var xmlHttp;
var theDiv;

function createXMLHttpRequest() {
	 if (window.ActiveXObject) 
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
			 xmlHttp = new XMLHttpRequest();

}function startRequest(div, url) {
	theDiv = div;
	createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", url, true);
   xmlHttp.send(null);

   
}function handleStateChange() {
    if(xmlHttp.readyState == 4) 
		if(xmlHttp.status == 200)
			document.getElementById(theDiv).innerHTML = xmlHttp.responseText;


} function getRequestBody(pForm) {
            var nParams = new Array();
            
            for (var i=0 ; i < pForm.elements.length; i++) {
                var pParam = encodeURIComponent(pForm.elements[i].name);
                pParam += "=";
                pParam += encodeURIComponent(pForm.elements[i].value);
                nParams.push(pParam);
            } 
            
            return nParams.join("&"); 


}function startLogin() {
	   createXMLHttpRequest();
		var pForm = document.formDivLogin;
		var pBody = getRequestBody(pForm);   
		xmlHttp.open("post", pForm.action, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4)
				if (xmlHttp.status == 200){
					if(xmlHttp.responseText != "1")
						document.getElementById('LoginResult').innerHTML = '¡ÃØ³ÒµÃÇ¨ÊÍºª×èÍ¼Ùéãªé áÅÐ ÃËÑÊ¼èÒ¹´éÇÂ¹Ð¤Ð';
					else{
						document.getElementById('LoginResult').innerHTML = '¢éÍÁÙÅ¶Ù¡µéÍ§ ¡ÃØ³ÒÃÍÊÑ¡¤ÃÙè¹Ð¤Ð';
						setTimeout("window.location.reload();", 3000);
					}
				}
		};
		xmlHttp.send(pBody); 
		
}function startRegister() {
	   createXMLHttpRequest();
	   
		var pForm = document.formDivLogin;
		var pBody = getRequestBody(pForm);   
		xmlHttp.open("post", pForm.action, true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4)
				if (xmlHttp.status == 200){
					
					if(xmlHttp.responseText != "1")
						document.getElementById('LoginResult').innerHTML = 'à¡Ô´¢éÍ¼Ô´¾ÅÒ´ ¡ÃØ³ÒµÃÇ¨ÊÍº¢éÍÁÙÅ áÅÐºÑ¹·Ö¡ãËÁè¹Ð¤Ð';
					else{
						document.getElementById('LoginResult').innerHTML = '¢éÍÁÙÅ¶Ù¡µéÍ§ ¡ÃØ³ÒÃÍÊÑ¡¤ÃÙè¹Ð¤Ð';
						setTimeout("window.location.reload();", 3000);
					}
				}
		};
		xmlHttp.send(pBody); 
		
		
}function MM_swapImgRestore() { 
  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() {
  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) {
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;


}function MM_swapImage() {
  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 postArked(URL,HEIGTH){
  var Left = (screen.availWidth-490)/2;
  var Top = (screen.availHeight-HEIGTH)/2;
  window.open(URL,"VRUHelpDesk",
			  "toolbar=no,resizable=0,scrollbars=0,width=490,height="+HEIGTH+",left="+Left+",top="+Top+"");


}function jumpMenu(address,varieable,object){ 
  parent.location=address+varieable+object.options[object.selectedIndex].value
 
}function swapRegister(){
 	document.getElementById('DivLight').innerHTML = "<img src=\"../images/loading.gif\">";
	startRequest('DivLight', '../libraries/faceRegister.php');
	document.getElementById('DivLight').className = 'white_content_regis';
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var windowLoginSize = Array(400, 360);
	windowLoginSize[0] /= 2;
	windowLoginSize[1] /= 2;

	document.getElementById('DivLight').style.top = (arrayPageSize[3]/2) - windowLoginSize[1] + arrayPageScroll[1];
    document.getElementById('DivLight').style.left = (arrayPageSize[0]/2) - windowLoginSize[0];

}function swapLogin(){
	document.getElementById('DivLight').innerHTML = "<img src=\"../images/loading.gif\">";
	startRequest('DivLight', '../libraries/faceLogin.php');
	document.getElementById('DivLight').className = 'white_content';
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var windowLoginSize = Array(400, 200);
	windowLoginSize[0] /= 2;
	windowLoginSize[1] /= 2;

	document.getElementById('DivLight').style.top = (arrayPageSize[3]/2) - windowLoginSize[1] + arrayPageScroll[1];
    document.getElementById('DivLight').style.left = (arrayPageSize[0]/2) - windowLoginSize[0];
	
}function showLogin(){
	document.getElementById('DivLight').className = 'white_content';
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var windowLoginSize = Array(400, 180);
	windowLoginSize[0] /= 2;
	windowLoginSize[1] /= 2;

	document.getElementById('DivLight').style.top = (arrayPageSize[3]/2) - windowLoginSize[1] + arrayPageScroll[1];
    document.getElementById('DivLight').style.left = (arrayPageSize[0]/2) - windowLoginSize[0];
	document.getElementById('DivLight').style.display='block';
	document.getElementById('DivFade').style.height = arrayPageSize[1] + 'px';
	document.getElementById('DivFade').style.display='block';
	
	document.getElementById('DivLight').innerHTML = "<img src=\"../images/loading.gif\">";
	startRequest('DivLight', "../libraries/faceLogin.php");
	
}function showRegister(){
	
	document.getElementById('DivLight').className = 'white_content_regis';
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var windowLoginSize = Array(400, 390);
	windowLoginSize[0] /= 2;
	windowLoginSize[1] /= 2;

	document.getElementById('DivLight').style.top = (arrayPageSize[3]/2) - windowLoginSize[1] + arrayPageScroll[1];
    document.getElementById('DivLight').style.left = (arrayPageSize[0]/2) - windowLoginSize[0];
	document.getElementById('DivLight').style.display='block';
	document.getElementById('DivFade').style.height = arrayPageSize[1] + 'px';
	document.getElementById('DivFade').style.display='block';
	
	document.getElementById('DivLight').innerHTML = "<img src=\"../images/loading.gif\">";
	startRequest('DivLight', '../libraries/faceRegister.php?cancel=1');
	
}function closeLogin(){
	document.getElementById('DivLight').style.display='none';
	document.getElementById('DivFade').style.display='none';

}function isEmail(email){
	return email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

}function isUsername(username){
	if(username.langth < 2)
		return false;
	else
		return username.match(/\b(^(\S).+$)\b/gi);

}function isImage(image){
	type = (image.substr(image.lastIndexOf('.')+1)).toLowerCase();
	return (type=="jpeg" || type=="jpg" || type=="gif");
	
}function getPageScroll(){
	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;

	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;

	} else if (document.body) {
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;

}function getPageSize(){

	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		if(document.documentElement.clientWidth)
			windowWidth = document.documentElement.clientWidth; 
		 else 
			windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){ 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight)
		pageHeight = windowHeight;
	else 
		pageHeight = yScroll;
	if(xScroll < windowWidth)
		pageWidth = xScroll;		

	else 
		pageWidth = windowWidth;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;

}function hideListShowText(objectList, textId, condition){
	
		if(objectList.options[objectList.selectedIndex].value==condition){
			document.getElementById(textId).disabled = false;
			document.getElementById(textId).style.display = '';
			objectList.style.display = 'none';
			objectList.disabled = true;
			document.getElementById(textId).focus();
		}
		
}function hideTextShowList(objectText, listId, condition){
		if(objectText.value==condition){
			document.getElementById(listId).disabled = false;
			document.getElementById(listId).style.display = '';
			objectText.style.display = 'none';
			objectText.disabled = true;
			document.getElementById(listId).focus();
		}

}function isCheck(temp){
	counter = 0;
	for (i=0; i < document.form1.elements.length; i++) {
		if(document.form1.elements[i].type=="radio" 
								   && document.form1.elements[i].className == "choise"
								   && document.form1.elements[i].checked == true ){
			counter++;
		}

    }
	return (counter != temp);

}

