﻿function show_id(id){    if(document.getElementById(id)){    	document.getElementById(id).style.display ='';	}}function write_in_id(id,note){ 	if(document.getElementById(id)){  		show_id(id); 		document.getElementById(id).innerHTML=note;	}}function hide_id(id){    if(document.getElementById(id)){		document.getElementById(id).style.display ='none';	}}function page_loader(this_page){	main_ajax_do(this_page, 'main_page', '');}function write_in_blank_id(id){ 	if(document.getElementById(id)){  		show_id(id); 		document.getElementById(id).innerHTML=' ';	}}function get_value_for_ajax(this_id){	if(! document.getElementById(this_id) ){		return '';	}else if(document.getElementById(this_id).type == 'checkbox'){        return document.getElementById(this_id).checked;	}else{        return encodeURIComponent(replace_for_ajax(document.getElementById(this_id).value));	}}function replace_for_ajax(note){	note= note.replace(/&/g,"**am**");	note= note.replace(/=/g,"**mosavi**");	note= note.replace(/\+/g,"**jam**");	return note;}function loading_effect(k){	ht = document.getElementsByTagName("html");	if(k==1){	    ht[0].style.cursor = 'wait';	}else{	    ht[0].style.cursor = 'auto';	}}function main_ajax_do(url , thisid, post){ 	var xmlhttp=false;        show_id(thisid); write_in_id(thisid ,'<center>Processing...</center>') ;       		loading_effect(1);        /*@cc_on @*/        /*@if (@_jscript_version >= 5)        	try {                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');                }                 catch (e) {            try {xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');} 				catch (E) {                 xmlhttp = false;                 }    		}    	@end @*/    if(!xmlhttp) { xmlhttp=new XMLHttpRequest();}	xmlhttp.open('POST', url, true);        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); post=post+'&my_time='+escape(new Date().getTime());        xmlhttp.send(post);         xmlhttp.onreadystatechange = function() {             if(xmlhttp.readyState == 4  && xmlhttp.status == 200){                document.getElementById(thisid).innerHTML =xmlhttp.responseText;                loading_effect(0);             }        }}
function IsEmail(Str)
{
	var Reg = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/;
	return Reg.test(Str);
}
function clearcform(){
document.getElementById('box4').value = '';
}
function sendmsg(){     var box1=get_value_for_ajax('box1');	 	var box2=get_value_for_ajax('box2');	 	var box3=get_value_for_ajax('box3');	 	var box4=get_value_for_ajax('box4');	 	var box5=get_value_for_ajax('box5');	 	var Email = document.getElementById("box2"); 	if (box1 == '' || box2 == ''  || box4 == '' ) { write_in_id('errormsg' ,'Please enter required information!'); } else if (!IsEmail(Email.value)) 	{ write_in_id('errormsg' ,'Your email address is not valid !'); 	} 	else if (box4.length>'250') 	{ write_in_id('errormsg' ,'Comment should be less than 250 character!'); 	} 	else 	{ 	main_ajax_do( 'motor.php' , 'errormsg' ,'name='+box1+'&email='+box2+'&message='+box4+'&website='+box3+'&postid='+box5+'' ); clearcform();	}  }