function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function vlaunch(page,targetwin,x,y) {
 var doopt='toolbar=yes,menubar=no,status=no,scrollbars=no,resizable=no,directories=no,location=no,left=10,top=10,width='+ x + ',height=' + y;
 window.open(page,targetwin,doopt);
}

function vlaunchScroll(page,targetwin,x,y) {
 var doopt='toolbar=yes,menubar=no,status=no,scrollbars=yes,resizable=yes,directories=no,location=yes,left=10,top=10,width='+ x + ',height=' + y;
 window.open(page,targetwin,doopt);
}

function SendToAFriend(){
	window.location='mailto:?subject=Malvern Instruments page recommendation &body=I saw this page on the Malvern Instruments website and thought you should see it: ' + document.location 
}

function Search()
  {
    document.search.submit();
  }

//******************* QUICK LINKS **********************//
function htmlExpandWidth(){
	var targetWidth = 136;
	var id = 'rapidLinks';
	var i = document.getElementById(id).offsetWidth;
	var left = document.getElementById(id).offsetLeft;
	if(i<targetWidth){
		i = i + 8;
		left = left - 5;
		document.getElementById(id).style.borderWidth = '1px';
		document.getElementById(id).style.width = i + 'px';
		document.getElementById(id).style.height = 23 + 'px';
		document.getElementById(id).style.left = left + 'px';
		var time = setTimeout("htmlExpandWidth()",21);
	}
	else{
		htmlExpandHeight();
	}
}

function htmlExpandHeight(){
	var targetHeight = 318;
	var id = 'rapidLinks';
	var i = document.getElementById(id).offsetHeight;
	if(i<targetHeight){
		i = i + 8;
		document.getElementById(id).style.height = i + 'px';
		var time = setTimeout("htmlExpandHeight()",21);
	}
}

function htmlClose(){
	
	var targetWidth = 0;
	var id = 'rapidLinks';
	var i = document.getElementById(id).offsetWidth;
	var left = document.getElementById(id).offsetLeft;
	if(i>targetWidth){
		i = i - 8;
		if(i<0){i=0;}
		document.getElementById(id).style.borderWidth = '1px';
		document.getElementById(id).style.width = i + 'px';
		document.getElementById(id).style.height = i + 'px';
		var time = setTimeout("htmlClose()",21);
	}
	document.getElementById('rapidLinks').style.borderWidth = '0px';
}

function appendEmail(){
	var email = document.signUpFrm.signUpEmail.value;
	if(email == "输入您的电子邮件"){
		email = "";
	}
	vlaunchScroll('/malvern/malvernreg.nsf/Register?openform&email=' + email,'_blank','800','600');
}

function userLog(userObj){
	if (userObj.logged_in){
		 document.getElementById("loggedOut").style.visibility = 'hidden';
		 document.getElementById("loggedOut").style.height = '0';
		 document.getElementById("loggedIn").style.visibility = 'visible';
		 document.getElementById("loggedIn").style.height = '166px';
		 document.getElementById("userName").innerHTML = userObj.name;
	 }
	 else{
		 document.getElementById("loggedIn").style.visibility = 'hidden';
		 document.getElementById("loggedIn").style.height = '0';
		 document.getElementById("loggedOut").style.visibility = 'visible';
		 document.getElementById("loggedOut").style.height = '116px';
		 document.getElementById("userName").innerHTML = "";
	 }
}

	function showKin(id){
		document.getElementById('kin0').className  = "kinexus_content_notactive";
		if(id != 'kin1'){
			document.getElementById('kin1').className  = "kinexus_content_notactive";
			document.getElementById('list1').className  = "list_notactive";
		}
		document.getElementById('kin'+id).className  = "kinexus_content_active";
		document.getElementById('list'+id).className  = "list_active";
	}
	function hideKin(id){
		document.getElementById('kin'+id).className  = "kinexus_content_notactive";
		document.getElementById('list'+id).className  = "list_notactive";
		document.getElementById('kin0').className  = "kinexus_content_active";
	}
	
function checkmail(email){
var regex=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	email = document.__Submission.EmailAddress;
	var retVal=regex.test(email.value);
		if (retVal==false){
			alert("Please enter a valid email address. ");
			email.select();
		}
		else{
			retVal = document.__Submission.submit;
		}
	return retVal
}
	
function addsrc() {
	var _uacct="UA-8255137-1";
    switch (window.location.hostname) {
        case "www.malverninstruments.fr":
            _uacct="UA-8255489-1";	// set up the Urchin Account French
            break;
		case "www.malvern.de":
            _uacct="UA-8255161-1";	// set up the Urchin Account German
            break;
		case "www.malvern.com.cn":
            _uacct="UA-8255472-1";	// set up the Urchin Account Chinese
            break;
		case "www.malverninstruments.co.kr":
            _uacct="UA-8255445-1";	// set up the Urchin Account Korean
            break;
		case "www.malvern.co.kr":
            _uacct="UA-8255445-1";	// set up the Urchin Account Korean
            break;
		case "www.malvern.ru":
            _uacct="UA-8255506-1";	// set up the Urchin Account Korean
            break;
		case "www.malvern.jp":
            _uacct="UA-8255535-1";	// set up the Urchin Account Korean
            break;
        default:
            _uacct="UA-8255137-1";	// set up the Urchin Account English
            break;
    }
	return _uacct;
}	
function getElementsByClassName(classname, node)  {    
		if(!node) node = document.getElementsByTagName("body")[0];    
		var a = [];    
		var re = new RegExp('\\b' + classname + '\\b');    
		var els = node.getElementsByTagName("*");    
		for(var i=0,j=els.length; i<j; i++){
			if(re.test(els[i].className)){
				a.push(els[i]);    
			}
		}
		return a;
}

function changetab(id, tab){
	var arr =  getElementsByClassName("show", document.getElementsByTagName("body")[0]);
	for(i=0;i<arr.length;i++){
		document.getElementById(arr[i].id).className = "hide";
	}
	document.getElementById(id).className = "show";
				
	var arr =  getElementsByClassName("tabselected", document.getElementsByTagName("body")[0]);
	for(i=0;i<arr.length;i++){
		document.getElementById(arr[i].id).className = "tab boxtext_white12px";
	}
	document.getElementById(tab).className = "tabselected boxtext_white12px";
}
