﻿function contact()
{  
   namec  = getid('namecontact');emailc = getid('myemail');titlec = getid('title');txtc   = getid('txtq');
   var pmail = document.getElementById("myemail").value;
   if(namec == '' )
   {
   alert('لطفا تمامی موارد را تکمیل کنید');
   }else{	
			
			if(!IsEmail(pmail)){
			alert(pmail);
			alert('آدرس ایمیل وارد شده صحیح نمی باشد');}else{
			document.getElementById('sendBTN').disabled = true;
			Ajax_SEND( 'Contacst' , 'contactresult' ,'name='+namec+'&email='+emailc+'&title='+title+'&txt='+txtc+'','<img src=images/loading.gif width="10" height="10">','cload' );}	}

}

function Show(id)
{    
if(document.getElementById(id))
{    	
document.getElementById(id).style.display ='';	}}

function write_in_id(id,note,loading){ 	
if(document.getElementById(id)){  		
Show(id);

document.getElementById(loading).innerHTML=note;

}}

function Hide(id){    
if(document.getElementById(id)){		
document.getElementById(id).style.display ='none';	}}


function write(id){ 	
if(document.getElementById(id)){  	
	Show(id); 		
	document.getElementById(id).innerHTML=' ';	}}
	
	
	
	
function getid(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(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 Ajax_SEND(url , thisid, post,imgsrc,loading){
 	var xmlhttp=false;
        Show(thisid)
        write_in_id(thisid ,imgsrc,loading) ;
       
		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(loading).innerHTML='';
                //alert(xmlhttp.responseText);
                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 news(url)
       {
         n_email=getid('email');
         var Email = document.getElementById("email");
        if (n_email == ''  )
		{
		write_in_id('news_sub' ,'<font color=red>لطفا آدرس ایمیل را وارد کنید</font>','news_sub');
		}
		else
		{	
			
			if(!IsEmail(Email.value))
			{
				
				write_in_id('news_sub' ,'<font color=red>آدرس ایمیل وارد شده صحیح نمی باشد</font>','news_sub');
			}
			else
			{
			Ajax_SEND( url+'letter_m.php' , 'news_sub' ,'mail='+n_email+'','<img src='+url+'images/loading.gif>','mload' );
			
			}			
		}

}





  
