﻿var state = true;

function object_disable(layer_ref1,layer_ref2) {
	if (state == true) {
		state = '';
	}
	else {
		state = true;
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref1 + ".disabled = state");
		eval( "document.all." + layer_ref2 + ".disabled = state");

	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref1].disabled=state;
		document.layers[layer_ref2].disabled=state;
	}

	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref1);
		maxwell_smart.disabled = state;
		maxwell_smart1 = document.getElementById(layer_ref2);
		maxwell_smart1.disabled = state;
	}
}
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 main_ajax_do_get(url , thisid){
    show_id(thisid)
    write_in_id(thisid ,'<div class="loading"><img src="images/loading.gif" border="0">&nbsp;&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</div>') ;
	var xmlhttp=false;
	var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
	for (var i = 0; i < msxmlhttp.length; i++) {
	try {xmlhttp = new ActiveXObject(msxmlhttp[i]);} catch (e) {xmlhttp = false;}
	}
	if(!xmlhttp && typeof XMLHttpRequest != "undefined")xmlhttp = new XMLHttpRequest();
	if(xmlhttp) {
		   // if(!xmlhttp) { xmlhttp=new XMLHttpRequest();}
			//else if (window.ActiveXObject) { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			xmlhttp.open('GET', url, true);
		    //xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
			//post=post+'&my_time='+escape(new Date().getTime());
		    xmlhttp.send(null); 
		    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(thisid).innerHTML =my_respons;
				}
		    }
	}else alert("مرورگر شما توانایی کار با اجکس را ندارد");
} 
 
function main_ajax_do(url , thisid, post){
    show_id(thisid)
    write_in_id(thisid ,'<div class="loading"><img src="images/loading.gif" border="0">&nbsp;&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</div>') ;
	var xmlhttp=false;
	/*if (window.XMLHttpRequest)     { 
			xmlhttp = new XMLHttpRequest();
         if(xmlhttp.overrideMimeType)
            xmlhttp.overrideMimeType('text/xml');
	}
    else if (window.ActiveXObject) {   
		try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch(e) {
            try{
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {}
         }  
	}*/
	var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
	for (var i = 0; i < msxmlhttp.length; i++) {
	try {xmlhttp = new ActiveXObject(msxmlhttp[i]);} catch (e) {xmlhttp = false;}
	}
	if(!xmlhttp && typeof XMLHttpRequest != "undefined")xmlhttp = new XMLHttpRequest();
	if(xmlhttp) {
		   // if(!xmlhttp) { xmlhttp=new XMLHttpRequest();}
			//else if (window.ActiveXObject) { 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', '');
					my_respons = getscript(my_respons);
					document.getElementById(thisid).innerHTML =my_respons;
				}
		    }
	}else alert("مرورگر شما توانایی کار با اجکس را ندارد");
}

function block_loader_get(page,this_block){
main_ajax_do_get('inc/'+page+'.php','jhost_place_block_'+this_block+'');		
}

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

function show_page(page,block,post,option){
if(option=='yes')
	{
		hide_id('jhost_place_block_rate')
		hide_id('jhost_place_block_related_product')
		block_loader('toppro','topproduct')
	}

main_ajax_do(page+'.php','jhost_place_block_'+block+'',post);		
}

function show_detail(post){
hide_id('jhost_place_block_topproduct')
hide_id('jhost_place_block_rand')
main_ajax_do('show_detail.php','jhost_place_block_main',''+post+'');	
block_loader('related_product','related_product',''+post+'');
block_loader('rating','rate',''+post+'');
}

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, div_id, post){
	main_ajax_do(this_page+'.php', div_id, post);
}

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(document.getElementById(this_id).value);
	}
}

function get_div_value_for_ajax ( id ){
	return encodeURIComponent(document.getElementById(id).innerHTML);
}

function replace_for_ajax(note){
	return note;
}

function set_value(id,word,this_page, div_id, post){
		document.getElementById(id).innerHTML = word;
		main_ajax_do(this_page+'.php','jhost_place_block_'+div_id+'', post);
}

