// ActionScript Document

   var http_request = false;
   var name_div_load = '';
   //Initiate the AJAX GET request
   function makeRequest(url, parameters) {
       http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {	
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

	function makeRequest_2(url, parameters,fun) 
	{
		   http_request = false;
		  if (window.XMLHttpRequest) { // Mozilla, Safari,...
			 http_request = new XMLHttpRequest();
			 if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/html');
			 }
		  } else if (window.ActiveXObject) { // IE
			 try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
				try {	
				   http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			 }
		  }
		  if (!http_request) {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
		  http_request.onreadystatechange =  fun;
		  http_request.open('GET', url + parameters, true);
		  http_request.send(null);
	}
	 
	//Initiate the AJAX POST request
	function makePostRequest(url, param, func) {
	  http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {	
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = func;
	  
      http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  http_request.setRequestHeader("Content-length", param.length);
	  http_request.setRequestHeader("Connection", "close");
	
	  //Make the request
	  http_request.send(param); 
	}


   function alertContents() {
	   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//document.getElementById(name_div_load).className = 'test';
			//alert(result);
			document.getElementById(name_div_load).innerHTML = result;
         } else {

            show_notice_box('There was a problem with the request.');
         }
      }
   }
   
   
   
	function insertEmail(emailID)
	{
		makeRequest_2("insertEmail.php",'?Email='+emailID,alertContentsEmail);	
		//name_div_load=namediv;
	}
	function alertContentsEmail() {
	   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//document.getElementById(name_div_load).className = 'test';
			//alert(result);
			alert(result);
         } else {

            alert('There was a problem with the request.');
         }
      }
    }
		
	
	function onchangeSendContact() {
	   
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//document.getElementById(name_div_load).className = 'test';
			//alert(result);
			alert(result);
         } else {
            alert('Có vấn đề khi thực hiện, vui lòng liên hệ với nhà điều hành.');
         }
      }
   }
   
   function trim(s){
		s = trimLeft(s);
		s = trimRight(s);
		return(s);
	}
	function trimLeft(s){
		var i;
		i=0;
		var n;
		n = s.length;
		while((i<n)&&(s.charAt(i)==' ')) i++;
			s = s.substring(i);
		return(s);
	} 

   function trimRight(s){
		var n;
		n = s.length;
		var i;
		i = s.length-1;
		while((i>=0)&&(s.charAt(i)==' ')) i--;
			s = s.substring(0,i+1);
		return(s);
	}
	function isDigit(c)
	{
	if((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9'))
		return true;
	else
		return false;
	}
   
   function isEmail(strEmail)
	{
	 var intlen;
	 var ctmp;
	 strEmail = trim(strEmail);
	 if(strEmail=='') return false;
	 intlen=strEmail.length;
	 if(intlen<5) return false;
	 if(strEmail.indexOf('@')==-1) return false;
	 if(strEmail.indexOf('.')==-1) return false;
	 if(intlen - strEmail.lastIndexOf('.') -1 > 4) return false; 
	 if((strEmail.indexOf("_")!=-1) && (strEmail.lastIndexOf("_") > strEmail.lastIndexOf("@"))) return false;
	 if(strEmail.lastIndexOf(".") <= strEmail.lastIndexOf("@")+1)  return false;
	 if(strEmail.indexOf("@")!=strEmail.lastIndexOf("@")) return false;
	 if(intlen -1 == strEmail.lastIndexOf('.')) return false;
	 if(strEmail.charAt(strEmail.indexOf('@')+1)=='.') return false;
	 if(strEmail.indexOf(" ")!=-1) return false;
	 if(strEmail.indexOf("..")!=-1) return false;
	 
	 strEmail=strEmail.toLowerCase();
	 for(intcnt=0;intcnt<intlen;intcnt++)
		{
		 ctmp = strEmail.charAt(intcnt)
		 if((!isDigit(ctmp))&& ((ctmp>'z')||(ctmp<'a')) && (ctmp!='-') && (ctmp!='.') && (ctmp!='@') && (ctmp!='_')) return false;
		}
	
	return true	;
	}
	
	function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	
	function send_email_pghone()
	{
		$('#error_mail').html('');
		var theForm=document.frm_email_pghone;
		if(theForm.Email.value=='')
		{
			alert("Vui lòng nhập Email!");
			theForm.Email.focus();
			return false;
		}
		if(!isEmail(theForm.Email.value))
		{			
			alert('Email không họp lệ!');
			theForm.Email.value = '';
			theForm.Email.focus();
			return false;
		}	
		theForm.submit();
	}
