function doeval(js){
	if(js!=null){
	var sc = document.createElement('script');
	jsCode = js;
	sc.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(sc);
	sc.text = 'try{eval(jsCode);}catch(e){}jsCode="";';
	//sc.text = 'try{eval(jsCode);}catch(e){try{alert(e.fileName+" : "+e.lineNumber+"\\n"+e.name+" : "+e.message); alert(e.stack);}catch(e){}}jsCode="";';
	sc.text = "\/\/ :-)";
	}
}

function getscript(str){
let_out=str;
	jstr=let_out.split('<script>');
	if( jstr[1] !=null){
		newstr=jstr[1].split('</script>');
		if( newstr[1] !=null){
			setTimeout("doeval( newstr[0] )", 500);
		}
	}
return let_out;
}

function addtocart(Site){
 window.open(Site,"viewwin","toolbar=1,status=1,scrollbars=yes,resizable=1");
 } 

function show_detail(post){
hide_id('djbazar_net_place_block_topproduct')
hide_id('djbazar_net_place_block_rand')
main_ajax_do('show_detail.php','djbazar_net_place_block_main',''+post+'');	
block_loader('related_product','related_product',''+post+'');
block_loader('rating','rate',''+post+'');
}


function showwait(){
	document.getElementById("wait").style.visibility="visible";
}

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

function viewid(id){
    if(document.getElementById(id)){
    	document.getElementById(id).style.display ='';
	}
}

function dviewid(id,note){
 	if(document.getElementById(id)){
  		viewid(id);
 		document.getElementById(id).innerHTML=note;
	}
}

function hiddeen(id){
    if(document.getElementById(id)){
		document.getElementById(id).style.display ='none';
	}
}

function get_vajax(inid){
	if(! document.getElementById(inid) ){
		return '';
	}else if(document.getElementById(inid).type == 'checkbox'){
        return document.getElementById(inid).checked;	
	}else{
        return encodeURIComponent(rajax(document.getElementById(inid).value));
	}
}

function get_dvajax ( ainid ){
	return encodeURIComponent(document.getElementById(ainid).innerHTML);
}

function rajax(text){
	note= text.replace(/&/g,"**am**");
	note= text.replace(/=/g,"**mosavi**");
	note= text.replace(/\+/g,"**jam**");
	return text;
}

function mainload(url , inid, post){
     var xmlhttp=false;
        viewid(inid)
        dviewid(inid ,'<center><span style="color: #0092dd; line-height: 20px;">چند لحظه لطفا...</span><br/><img src="images/loader.gif" /></center>') ;
       
        /*@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){
                my_respons=xmlhttp.responseText;
                my_respons = my_respons.replace('\n', '');
                my_respons = my_respons.replace('\r', '');
                my_respons = getscript(my_respons);
                document.getElementById(inid).innerHTML =my_respons;
             }
        }
}

function pay_proc_js(block,id,ads,idlink){
page = document.getElementById('pay_proc_'+id+'').value;
if(page=='cart')
{
//addtocart('gopage.php?id'+id+'');
addtocart(''+idlink+'');
}
else{
     if(page=='pid')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=post','main_div','&show=1');		
     }
     else if(page=='pida')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=iranmc','main_div','&show=1');		
     }
     else if(page=='pidb')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=p24','main_div','&show=1');		
     }
     else if(page=='pidc')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=fer','main_div','&show=1');		
     }
     else if(page=='pidd')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=dpay','main_div','&show=1');		
     }
     else if(page=='pidw')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=naghd','main_div','&show=1');		
     }
     else if(page=='pidx')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=online','main_div','&show=1');		
     }
     else if(page=='pidy')
     {
     mainload('peyk_state.php?'+page+'='+id+'&ads='+ads+'&noe=peyk','main_div','&show=1');		
     }
     else if(page=='pidz')
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=tel','main_div','&show=1');		
     }
     else
     {
     mainload('cart.php?'+page+'='+id+'&ads='+ads+'&noe=post','main_div','&show=1');		
     }
		setTimeout("mainload('viewproduce.php','userbasket','')",2000)
		scroll(0,0)
}
}

function CAjax()
{
	var st=document.orderform.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/loader.gif" width="16" border="0"><font face="Tahoma" style="font-size: 8pt">چند لحظه لطفا ...</font><BR>';//Wait For Loading
	}
}

function Post()
{
	var ct = document.orderform.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 CHEmail(DRT)
{
	var CHECK = /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/
	return CHECK.test(DRT)
}

function send_friend(){
    zname=get_vajax('zname');	
    email=get_vajax('email');	
    fname=get_vajax('fname');	
    femail=get_vajax('femail');	
    zid=get_vajax('zid');	
    ads=get_vajax('ads');	
    var EEmail = document.getElementById("email");  	
    var FEmail = document.getElementById("femail");  	

	if (zname == '' || email == '' || fname == '' || femail == '')
		{
		hiddeen('sendmail')
		dviewid('error_sendmail' ,'<font color="red">لطفا تمامی موارد را تکمیل نمایید</font>')
		}
		else
		{	
			if(!CHEmail(EEmail.value))
			{
		                hiddeen('sendmail')
				dviewid('error_sendmail' ,'<font color="red">ایمیل شما معتبر نمیباشد</font>')
			}
			else if(!CHEmail(FEmail.value))
			{
		                hiddeen('sendmail')
				dviewid('error_sendmail' ,'<font color="red">ایمیل دوست شما معتبر نمیباشد</font>')
			}
			else
			{	
		                hiddeen('error_sendmail')
				mainload( 'motor.php?sub=send', 'sendmail', '&id='+zid+'&ads='+ads+'&name='+zname+'&email='+email+'&fname='+fname+'&femail='+femail)
			}
		}
}

function replace_chat(name){
	hiddeen('A'+name)
	viewid('B'+name)
}

function delete_chat(name){
	hiddeen('B'+name)
	viewid('A'+name)
}

function edit_chat(name,idd){
    text=get_vajax('text'+idd);	

	        if (text == '')
		{
		dviewid('error_editchat' ,'<font color="red">کادر پیام نمی تواند خالی باشد</font>')
		}
		else
		{		
	            mainload( name, 'editchat', '&sub=send&text='+text)
		}
}

function del_chat(name){
if (confirm("آیا مایل به حذف این پیام هستید ؟")) {
	            mainload( name, 'editchat', '&sub=delete')
}
}

function loadPage(page) {
		mainload( page, 'main_div' ,'')
		scroll(0,0)
}

function loadPagea(page) {
		mainload( page, 'main_div' ,'')
		setTimeout("mainload('viewproduce.php','userbasket','')",2000)
		scroll(0,0)
}

function loadbasket() {
		mainload('viewproduce.php','userbasket','')
}
