var color_red='#FF0000';
var color_white='#FFFFFF';
var xmlhttp=false;
try{
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
	 try {	 
		xmlhttp=new ActiveX0bject ("Microsoft.XMLHTTP");	
	} catch(E){	 
		xmlhttp = false;
	}
}
if(!xmlhttp && typeof XMLHttpRequest !='undefined'){
  xmlhttp= new XMLHttpRequest(); 
}

var xmlhttp2=false;
try{
	xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
	 try {	 
		xmlhttp2=new ActiveX0bject ("Microsoft.XMLHTTP");	
	} catch(E){	 
		xmlhttp2 = false;
	}
}
if(!xmlhttp2 && typeof XMLHttpRequest !='undefined'){
  xmlhttp2= new XMLHttpRequest(); 
}

function makerequest(serverPage,objID){

var obj = document.getElementById(objID) ;
//alert(objID);
xmlhttp.open("POST" , serverPage);
xmlhttp.onreadystatechange = function(){
 	if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
		obj.innerHTML = xmlhttp.responseText;
		
	}
	}
	xmlhttp.send(null);
}
function makerequest2(serverPage2,objID2){

var obj = document.getElementById(objID2) ;
xmlhttp2.open("POST" , serverPage2);
//alert(serverPage2);
xmlhttp2.onreadystatechange = function(){
 	if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200){
		obj.innerHTML = xmlhttp2.responseText;
	}
	}
	xmlhttp2.send(null);
}
function load2content(serverPage,serverPage2,objID,objID2)
{
makerequest(serverPage,objID)
makerequest2(serverPage2,objID2)
}

function goback(objID,url,img){
	document.getElementById(objID).innerHTML="<a href="+url+" onclick=\"makerequest('"+url+"','"+objID+"'); return false;\"><img src="+img+" alt=\"Features\" border=\"0\" /></a>"; 
}
function Popup(url,popupname,width,height){
	window.open(''+url,''+popupname,'scrollbars=no,width='+width+',height='+height+',resizable=no');
}
function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co.th|jp)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)");
		//document.getElementById("email").focus();
		document.seminar_form_my.email.style.backgroundColor = color_red;
		document.getElementById("email_exists").innerHTML="<strong><font color=red>Email address seems incorrect (check @ and .'s)</font></strong>";
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("Ths username contains invalid characters.");
			//document.getElementById("email").focus();
			document.seminar_form_my.email.style.backgroundColor = color_red;
			document.getElementById("email_exists").innerHTML="<strong><font color=red>Ths username contains invalid characters.</font></strong>";
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			//document.getElementById("email").focus();
			document.seminar_form_my.email.style.backgroundColor = color_red;
			document.getElementById("email_exists").innerHTML="<strong><font color=red>Ths domain name contains invalid characters.</font></strong>";
			return false;
   		}
	}
	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid.");
		//document.getElementById("email").focus();
		document.seminar_form_my.email.style.backgroundColor = color_red;
		document.getElementById("email_exists").innerHTML="<strong><font color=red>The username doesn't seem to be valid.</font></strong>";
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				//document.getElementById("email").focus();
				document.seminar_form_my.email.style.backgroundColor = color_red;
				document.getElementById("email_exists").innerHTML="<strong><font color=red>Destination IP address is invalid!</font></strong>";
				return false;
		   }
		}
		//return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			//document.getElementById("email").focus();
			document.seminar_form_my.email.style.backgroundColor = color_red;
			document.getElementById("email_exists").innerHTML="<strong><font color=red>The domain name does not seem to be valid.</font></strong>";
			return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		//document.getElementById("email").focus();
		document.seminar_form_my.email.style.backgroundColor = color_red;
		document.getElementById("email_exists").innerHTML="<strong><font color=red>The address must end in a well-known domain or two letter " + "country.</font></strong>";
		return false;
	}

	if (len<2) {
		//alert("This address is missing a hostname!");
		//document.getElementById("email").focus();
		document.seminar_form_my.email.style.backgroundColor = color_red;
		document.getElementById("email_exists").innerHTML="<strong><font color=red>This address is missing a hostname!</font></strong>";
		return false;
	}
	//return true;
	document.seminar_form_my.email.style.backgroundColor = color_white;
}
function CheckSubmit(){
	var check_enum = new Array();	
	var check_enum2=1;
	var i;
	document.getElementById("process_bar").innerHTML="<img src=\"images/uploader.gif\" width=\"220\" height=\"19\">";
	for(i=0;i<document.forms['seminar_form_my'].elements.length;i++){
		box=document.forms['seminar_form_my'].elements[i];	
		if(box != null && box.name != ""){
			if(box.name=="email"){
				if(emailCheck(box.value) == false){
					box.style.backgroundColor = color_red;
					check_enum[i]=0;
				} else {
					box.style.backgroundColor = color_white;
					document.getElementById("email_exists").innerHTML="";
					check_enum[i]=1;
				}
			}else{
				if(!box.value){
					box.style.backgroundColor = color_red;			
					check_enum[i]=0;
				}else{
					box.style.backgroundColor = color_white;	
					check_enum[i]=1;
				}
			}			
		}
	}
	for(i=0;i<check_enum.length;i++){
		if(check_enum[i] == 0) {
			check_enum2=0;
			document.getElementById("process_bar").innerHTML="";
		}
	}
	if(check_enum2 == 0) return false;
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
	   //( (expires) ? ";expires=" + expires : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
} 
