
function clickIE() {
if (document.all) {
return false;
}
} 
function clickNS(e) {
if (document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {
return false;
}
}
} 
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
} 
else{
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
} 
document.oncontextmenu=new Function("return false") 



function encodeHtml(str) {
     encodedHtml = str;
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
   }
   
 function getStrOption(str){
	ArrayList = str.split(","); 
	num = ArrayList.length;
	StrOption = "";
	for(i=0;i<num;i++){
		if(i>0){
			StrOption += "&";
		}
		StrOption += ArrayList[i]+"=";
		StrOption += encodeHtml(document.getElementById(ArrayList[i]).value);
	}
	
	return StrOption;
 }


function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}


function CallModuleID(id,strOption) {
		
	createXMLHttpRequest();
	url = "main.php?m="+id;
	if(strOption!=""){
	url += "&"+getStrOption(strOption);
	}
	
    xmlHttp.onreadystatechange = CreateInfoToDiv;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function CallModuleIDAlert(id,strOption) {
	createXMLHttpRequest();
	url = "main.php?m="+id;
	if(strOption!=""){
	url += "&"+getStrOption(strOption);
	}
	
    xmlHttp.onreadystatechange = CreateInfoToDivAlert;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}


function CreateInfoToDiv(){
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			document.getElementById("DisplayInfo").innerHTML = xmlHttp.responseText;
        }
    }
}


function CreateInfoToDivAlert(){
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			alert(xmlHttp.responseText);
        }
    }
}


function chLanguage(lang){
	createXMLHttpRequest();
	url = "main.php?m=chlang&lang="+lang;
    xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					//alert(xmlHttp.responseText);
					this.location.href = xmlHttp.responseText;
				}
			}
	};
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}



function showRegisterForm(lang){
	username = encodeHtml(document.getElementById("username").value);
	password = encodeHtml(document.getElementById("password").value);
	salutation = encodeHtml(document.getElementById("salutation").value);
	fullname = encodeHtml(document.getElementById("fullname").value);
	company = encodeHtml(document.getElementById("company").value);
	address = encodeHtml(document.getElementById("address").value);
	zipcode = encodeHtml(document.getElementById("zipcode").value);
	telephone = encodeHtml(document.getElementById("telephone").value);
	mobile = encodeHtml(document.getElementById("mobile").value);
	email = encodeHtml(document.getElementById("email").value);
	
	if(
			username == "" || 
			password  == "" || 
			salutation  == "" || 
			fullname  == "" || 
			company  == "" || 
			address  == "" || 
			zipcode  == "" || 
			telephone  == "" || 
			mobile  == "" || 
			email  == "" 
	   ){
			if(lang=="en")
				alert("Sorry! Please fill information into blank form.");
			else
				alert("กรุณากรอกข้อมูลให้ครบครับ");		
	}else{
		
			createXMLHttpRequest();
			
			url = 'main.php?m=regdb&lang='+lang+'&username='+username+'&password='+password+'&salutation='+salutation+'&fullname='+fullname+'&company='+company+'&address='+address+'&zipcode='+zipcode+'&telephone='+telephone+'&mobile='+mobile+'&email='+email;
			xmlHttp.onreadystatechange = function(){
					if(xmlHttp.readyState == 4) {
						if(xmlHttp.status == 200) {
							alert(xmlHttp.responseText);
							//this.location.href = xmlHttp.responseText;
						}
					}
			};
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);
		
	}
}



function EditRegisterForm(lang){
	username = encodeHtml(document.getElementById("username").value);
	password = encodeHtml(document.getElementById("password").value);
	salutation = encodeHtml(document.getElementById("salutation").value);
	fullname = encodeHtml(document.getElementById("fullname").value);
	company = encodeHtml(document.getElementById("company").value);
	address = encodeHtml(document.getElementById("address").value);
	zipcode = encodeHtml(document.getElementById("zipcode").value);
	telephone = encodeHtml(document.getElementById("telephone").value);
	mobile = encodeHtml(document.getElementById("mobile").value);
	email = encodeHtml(document.getElementById("email").value);
	
	if(
			username == "" || 
			password  == "" || 
			salutation  == "" || 
			fullname  == "" || 
			company  == "" || 
			address  == "" || 
			zipcode  == "" || 
			telephone  == "" || 
			mobile  == "" || 
			email  == "" 
	   ){
			if(lang=="en")
				alert("Sorry! Please fill information into blank form.");
			else
				alert("กรุณากรอกข้อมูลให้ครบครับ");		
	}else{
		
			createXMLHttpRequest();
			
			url = 'main.php?m=eduserprofiledb&lang='+lang+'&username='+username+'&password='+password+'&salutation='+salutation+'&fullname='+fullname+'&company='+company+'&address='+address+'&zipcode='+zipcode+'&telephone='+telephone+'&mobile='+mobile+'&email='+email;
			xmlHttp.onreadystatechange = function(){
					if(xmlHttp.readyState == 4) {
						if(xmlHttp.status == 200) {
							alert(xmlHttp.responseText);
							//this.location.href = xmlHttp.responseText;
						}
					}
			};
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);
		
	}
}

// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function PicViewer(pic){
	
	
	createXMLHttpRequest();
	url = "main.php?m=picview&pic="+pic;

	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) {
				document.getElementById("viewpic").innerHTML = xmlHttp.responseText;
			}
		}
	};
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}


function checkNumber(str){
	len = str.length;
	for(i=0; i<len; i++){
		if(!(str.charCodeAt(i) >=48 && str.charCodeAt(i) <=57))
			return false;
	}
	return true;
}
function PageView(page){
	
	createXMLHttpRequest();
	url = page;

    xmlHttp.onreadystatechange =  function(){
			if(xmlHttp.readyState == 4) {
				if(xmlHttp.status == 200) {
					document.getElementById("DisplayInfo").innerHTML = xmlHttp.responseText;
				}
			}
	};
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	
}

