// SAMAN CODE - basket fade
function show_wait(){
	document.getElementById("wait").style.visibility="visible";
}

function hide_wait(){
	document.getElementById("wait").style.visibility="hidden";
}

var timerRunning = true;

function showtime(i) 
{
   a = 204 + i;
   b = 255;
   c = 51 + i;
	document.getElementById("basket").style.backgroundColor = 'rgb(' + a + ',' + b + ',' + c + ')';
	i = i + 10;

	if (timerRunning == true) {
	timeo = setTimeout("showtime(" + i + ")",50);
	}
	timerRunning = true;

	if (i >= 255) {
	 timerRunning = false;
	 document.getElementById("basket").style.backgroundColor = "white";
	}
}

function fade() 
{
  timerRunning = true;
  showtime(1);
}

//-------------------------------------------------------

var timerRunning = true;

function del(i) 
{
   a = 255;
   b = 51 + i;
   c = 0 + i;
	document.getElementById("inbasket").style.backgroundColor = 'rgb(' + a + ',' + b + ',' + c + ')';
	
	i = i + 10;

	if (timerRunning == true) {
	timeo = setTimeout("del(" + i + ")",50);
	}
	timerRunning = true;
    if (i >= 255) {
	 timerRunning = false;
	 document.getElementById("inbasket").style.backgroundColor = "white";
	}
}

function dele() 
{
  timerRunning = true;
  del(1);
}

//----------------------------------------------------
function cheshmak( id , mode , number) {
if ( mode =='red'  ){
my_mode ='white'
}else{
my_mode ='red'
}
document.getElementById(id).className  ='chesmak_'+mode;
new_number =(parseInt(number) + 1);
if ( new_number <= 120 ){
setTimeout('cheshmak( "'+id+'" , "'+my_mode+'" , "'+new_number+'")',100 )
}
}



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 main_ajax_do(url , thisid, post){
 	var xmlhttp=false;
 	var my_respons = '';
        show_id(thisid);
        write_in_id(thisid ,'<img src="images/loading.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</font><BR>') ;
    if(!xmlhttp) { 
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlhttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
	 }
    }
    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){
				my_respons=xmlhttp.responseText;
				my_respons = my_respons.replace('\n', '');
				my_respons = my_respons.replace('\r', '');
				document.getElementById(thisid).innerHTML =my_respons;
             }
        }
}

function CAjax()
{
	var st=document.f1.state.value;
	var url="shahr.php?st=" + st + "&ctselect=" + 1 ;
	http.open("GET",url,true);
	http.onreadystatechange=RAjax;
	http.send(null);
}


function RAjax()
{
	if(http.readyState==4)
	{
		if(http.status==200)
		{
			var txt=http.responseText;
			document.getElementById("ct").innerHTML=txt;
		}
		else
		{
			//ERROR
		}
	}
	else
	{
		document.getElementById("ct").innerHTML='<img src="images/loading.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</font><BR>';//Wait For Loading
	}
}


function Post()
{
	var ct = document.f1.city.value;
	main_ajax_do('postpish.php?ct=' + ct,'postpish','1');
}

function CheckB()
{
	var R=false;
	try
	{
		R=new XMLHttpRequest();//Firfox
	}
	catch(err1)
	{
		try
		{
			R=new ActiveXObject("Msxml2.XMLHTTP");//IE 
		}
		catch(err2)
		{
			try
			{
				R= new ActiveXObject("Microsoft.XMLHTTP");//IE
			}
			catch(err3)
			{
				R=false;
			}
		}
	}
	return R;
}

var http = CheckB();


function main_ajax_do1(url , thisid, post){
 	var xmlhttp=false;
 	var my_respons = '';
    show_id(thisid);
    show_wait();

//        write_in_id(thisid ,'<img src="images/loading.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</font><BR>') ;


    if(!xmlhttp) { 
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlhttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
	 }
    }
     	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){
				my_respons=xmlhttp.responseText;
				my_respons = my_respons.replace('\n', '');
				my_respons = my_respons.replace('\r', '');
				document.getElementById(thisid).innerHTML =my_respons;
				if(document.getElementById('showbasket') ){
				main_ajax_do('showbasket.php','showbasket','1');
				}
				hide_wait();
				cheshmak('cheshmak_area','white',100);
//				fade();
             }
        }
}
//-----------------------------------------------------------del ---------------------
function main_ajax_do2(url , thisid, post){

 	var xmlhttp=false;
 	var my_respons = '';
    show_id(thisid);
    show_wait();

//        write_in_id(thisid ,'<img src="images/loading.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</font><BR>') ;


    if(!xmlhttp) { 
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlhttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
	 }
    }
     	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){
				my_respons=xmlhttp.responseText;
				my_respons = my_respons.replace('\n', '');
				my_respons = my_respons.replace('\r', '');
				document.getElementById(thisid).innerHTML =my_respons;
				if(document.getElementById('showbasket') ){
				main_ajax_do('showbasket.php','showbasket','1');
				}
				hide_wait();
				dele();
             }
        }
}
//=-----------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function IsEmail(Str)
{
	var Reg = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/
	return Reg.test(Str)
}

function send_form(nam,email,matn){

	if (nam == '' || email == '' || matn== '' )
		{
			write_in_id('mess' ,'همه موارد را تکمیل نمایید')
		}
		else
		{	
			if(!IsEmail(email))
			{
				write_in_id('mess' ,'ایمیل معتبر وارد نمایید')
			}
			else
			{
				main_ajax_do( 'contact.php?action=send' , 'main' ,'?nam=' + nam + '&email=' + email + '&matn=' + matn)
			}
		}
}
//------------------------- nagd -----------------------------
function resetID(){
	write_in_id('err1' ,'')
	write_in_id('err2' ,'')
	write_in_id('err3' ,'')
	write_in_id('err4' ,'')
	write_in_id('err5' ,'')
	write_in_id('err6' ,'')
	write_in_id('err7' ,'')
	write_in_id('err8' ,'')
	write_in_id('err9' ,'')

}
//-------------------------------------------------------------
function send_form_nagd(){
	nam = document.f1.nam.value
	email = document.f1.email.value
	tel = document.f1.tel.value
	postalcode = document.f1.postalcode.value
	address = document.f1.address.value
	type = document.f1.type.value
	rlskol = document.f1.rlskol.value
	fishno = document.f1.fishno.value
	dat = document.f1.dat.value
	shobename = document.f1.shobename.value
	shobecode = 0;
	addressshobe = "";
	disc = document.f1.disc.value
	rls = document.f1.rls.value
	takhfif = document.f1.takhfif.value
	allrls = document.f1.allrls.value
	PID = document.f1.PID.value

if (nam == '') 
	{
		resetID();
		write_in_id('err1' ,'نام و نام خانوادگي وارد نشده است')
		document.f1.nam.focus();
		err = 1;
		return false;
	} else if (email == '') {
		resetID();
		write_in_id('err2' ,'آدرس ايميل صحيح نيست')
		document.f1.email.focus();
		err = 1;
		return false;
	} else if (tel == '') {
		resetID();
		write_in_id('err3' ,'تلفن وارد نشده است')
		document.f1.tel.focus();
		err = 1;
		return false;
	} else if (postalcode == '') {
		resetID();
		write_in_id('err4' ,'كد پستي وارد نشده است')
		document.f1.postalcode.focus();
		err = 1;
		return false;
	} else if (address == '') {
		resetID();
		write_in_id('err5' ,'آدرس وارد نشده است')
		err = 1;
		document.f1.address.focus();
		return false;
	} else if (type == '0') {
		resetID();
		write_in_id('err6' ,'نحوه پرداخت وجه وارد نشده است')
		document.f1.type.focus();
		err = 1;
		return false;
	} else if (rlskol == '') {
		resetID();
		write_in_id('err7' ,'مبلغ واريزي وارد نشده است')
		document.f1.rlskol.focus();
		err = 1;
		return false;
	} else if (fishno == '') {
		resetID();
		write_in_id('err8' ,'شماره فيش بانكي وارد نشده است')
		document.f1.fishno.focus();
		err = 1;
		return false;
	} else if (dat == '') {
		resetID();
		write_in_id('err9' ,'تاريخ واريز وجه وارد نشده است')
		document.f1.dat.focus();
		err = 1;
		return false;
	} else	{	
		main_ajax_do( 'sabtnagd.php' , 'pardakht' ,'nam=' + nam + '&email=' + email + '&tel=' + tel  + '&postalcode=' + postalcode + '&address=' + address + '&type=' + type + '&rlskol=' + rlskol + '&fishno=' + fishno + '&dat=' + dat + '&shobename=' + shobename + '&shobecode=' + shobecode + '&addressshobe=' + addressshobe + '&disc=' + disc+ '&rls=' + rls + '&takhfif=' + takhfif + '&allrls=' + allrls + '&PID=' + PID);
//		main_ajax_do1('basket.php','basket',1);
		return true;			
			}
}



function send_motor_request() {
	
	city = document.getElementById('pbox1').value
	area = document.getElementById('pbox2').value
	nam = document.getElementById('pbox3').value
	email = document.getElementById('pbox4').value
	tel = document.getElementById('pbox5').value
	postalcode = document.getElementById('pbox6').value
	address = document.getElementById('pbox7').value
    rls = document.getElementById('pbox8').value
	dat = document.getElementById('pbox9').value
	PID = document.getElementById('pbox10').value
	prls = document.getElementById('pbox11').value
	
	if (city == 'zero' || area == 'zero' || nam == '' || email == '' || tel == '' || postalcode == '' || address == '')
	{
		write_in_id('message' ,'&#1607;&#1605;&#1607; &#1605;&#1608;&#1585;&#1575;&#1583; &#1585;&#1575; &#1578;&#1603;&#1605;&#1610;&#1604; &#1606;&#1605;&#1575;&#1610;&#1610;&#1583;')
		}
		else
		{	
			if(!IsEmail(email))
			{
				write_in_id('message' ,'&#1575;&#1610;&#1605;&#1610;&#1604; &#1605;&#1593;&#1578;&#1576;&#1585; &#1608;&#1575;&#1585;&#1583; &#1606;&#1605;&#1575;&#1610;&#1610;&#1583;')
			}
			else
			{
				main_ajax_do( 'sabtmotor.php' , 'pardakht' ,'nam=' + nam + '&email=' + email + '&city=' + city + '&area=' + area + '&tel=' + tel  + '&postalcode=' + postalcode + '&address=' + address + '&rls=' + rls + '&dat=' + dat + '&PID=' + PID + '&prls=' + prls);
			}  
		}
}


function block_loader(page,this_block,post){
main_ajax_do(page+'.php',this_block,post);		
}

function remove_from_basket(id,subid) {
if (confirm("آیا مایل به حذف این محصول از سبد خرید هستید ؟")) {
	main_ajax_do2('basket.php?action=delete&id='+id+'&subid='+subid,'basket','1');
}
}
