﻿//coded by HAMED SAATI <www.HAM3D.net> <hamed.saati@gmail.com>
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 block_loader(page,this_block,post){
main_ajax_do(page+'.php','ham3d_net_place_block_'+this_block+'',post);		
}

function show_page(page,block,post,option){
if(option=='yes')
	{
		hide_id('ham3d_net_place_block_rate')
		hide_id('ham3d_net_place_block_related_product')
		hide_id('ham3d_net_place_block_topproduct')
	}

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

function HAM3D_NET_cat_show(ham3d){
hide_id('ham3d_net_place_block_rate')
hide_id('ham3d_net_place_block_related_product')
hide_id('ham3d_net_place_block_topproduct')
hide_id('ham3d_net_place_block_rand');
main_ajax_do('cat.php','ham3d_net_place_block_main','id='+ham3d+'');		
}

function ham3d_shop_search(){
         
    ham3d=get_value_for_ajax('ham3d_search_box');	
	if (ham3d == '')
		{
		write_in_id('ham3d_net_place_block_search_error' ,'&nbsp;&nbsp;&nbsp;!!! فیلد جستجو خالی میباشد ')
		}
		else
		{	
		hide_id('ham3d_net_place_block_search_error')
		hide_id('ham3d_net_place_block_rate')
		hide_id('ham3d_net_place_block_topproduct')
		main_ajax_do('search.php', 'ham3d_net_place_block_main', 'ham3dsearch='+ham3d+'')
		}
}

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

function show_detail(post){
hide_id('ham3d_net_place_block_topproduct')
hide_id('ham3d_net_place_block_rand')
main_ajax_do('show_detail.php','ham3d_net_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(replace_for_ajax(document.getElementById(this_id).value));
	}
}

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

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

function main_ajax_do(url , thisid, post){
 	var xmlhttp=false;
        show_id(thisid)
        write_in_id(thisid ,'<img src="theme/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>') ;
       
        /*@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(thisid).innerHTML =my_respons;
             }
        }
}

function num2fa( number){
	my_num='';
	for ( var i = 0; i < number.length; i++){
		my_num += newd_num2fa( number.substr(i , 1 ));
	}	
	return my_num;
}

function newd_num2fa( newnumber ){
	if ( newnumber  == 0 ){
		return newnumber.replace(0, '&#1776;');
	}
	if ( newnumber  == 1 ){
		return  newnumber.replace(1, '&#1777;');	
	}	
	if ( newnumber  == 2 ){
		return  newnumber.replace(2, '&#1778;');	
	}	
	if ( newnumber  == 3 ){
		return  newnumber.replace(3, '&#1779;');	
	}	
	if ( newnumber  == 4 ){
		return  newnumber.replace(4, '&#1780;');	
	}	
	if ( newnumber  == 5 ){
		return  newnumber.replace(5, '&#1781;');	
	}	
	if ( newnumber  == 6 ){
		return  newnumber.replace(6, '&#1782;');	
	}	
	if ( newnumber  == 7 ){
		return  newnumber.replace(7, '&#1783;');	
	}	
	if ( newnumber  == 8 ){
		return  newnumber.replace(8, '&#1784;');
	}	
	if ( newnumber  == 9 ){
		return newnumber.replace(9, '&#1785;');
	}	
}

function do_change_new(){
my_city = document.getElementById('get_city').value;
my_deliver_price =my_city.split(':');
document.getElementById('get_city_price').innerHTML=my_deliver_price[0];
document.getElementById('get_city_ID').innerHTML=my_deliver_price[1];
//document.getElementById('deliver_price').innerHTML=num2fa( ''+my_deliver_price[0]+'' );

my_zone = document.getElementById('get_zone').value;
my_zone_price =my_zone.split(':');
document.getElementById('get_zone_price').innerHTML=my_zone_price[0];
document.getElementById('get_zone_ID').innerHTML=my_zone_price[1];
//document.getElementById('deliver_price').innerHTML=num2fa( ''+my_deliver_price[0]+'' );

my_dval_1d =parseInt(  document.getElementById('get_zone_price').innerHTML , 10 );
my_dval_2d =parseInt(  document.getElementById('get_city_price').innerHTML , 10 );
deliverp=(my_dval_1d + my_dval_2d);
document.getElementById('get_deliver_price').innerHTML=deliverp;
document.getElementById('total_deliver_price').innerHTML=num2fa( ''+deliverp+'' );

my_val_1d =parseInt(  document.getElementById('get_zone_price').innerHTML , 10 );
my_val_2d =parseInt(  document.getElementById('get_city_price').innerHTML , 10 );
my_val_3d =parseInt(  document.getElementById('get_price').innerHTML , 10 )
my_val_4d =(my_val_1d + my_val_2d + my_val_3d);
document.getElementById('get_total_price').innerHTML=my_val_4d;
document.getElementById('deliver_total_price').innerHTML=num2fa( ''+my_val_4d+'' );
}

function get_zone(){
my_city = document.getElementById('get_city').value;
my_deliver_price =my_city.split(':');
main_ajax_do('city_zone.php','ham3d_net_place_block_get_zone','id='+my_deliver_price[1]+'');		
}

function pay_proc_js(block,ID,IDlink){
page = document.getElementById('pay_proc_'+ID+'').value;
if(page=='cart')
{
//AddToCart('gopage.php?ID'+ID+'');
AddToCart(''+IDlink+'');
}
else{
main_ajax_do(page+'.php','ham3d_net_place_block_main','id='+ID+'&show=1');		
}
}

function check_js_compatible(){
if(!document.getElementById('ham3d_net_place_block_support'))
	{
        newdiv = document.createElement("div");
        newdiv.innerHTML = '<center><a target="_blank" href="http://www.ham3d.net/shop.php"><img src="http://www.HAM3D.net/shop.gif" border="0"></a></center>'
        document.body.appendChild(newdiv);
	}
}

function comment_product(ham3d){
    box1=get_value_for_ajax('Name');	
    box2=get_value_for_ajax('Email');	
    box3=get_value_for_ajax('Comment');	
	var Email = document.getElementById("Email");  	

	if (box1 == '' || box2 == '' || box3 == '')
		{
		write_in_id('ham3d_net_place_block_comment_error' ,'لطفا همه موارد را تکميل نماييد')
		}
		else
		{	
			if(!IsEmail(Email.value))
			{
				write_in_id('ham3d_net_place_block_comment_error' ,'ايميل وارد شده معتبر نمي باشد')
			}
			else
			{	
				main_ajax_do( 'send_comment.php'  , 'comment_div', 'id='+ham3d+'&id1='+box1+'&id2='+box2+'&id3='+box3+'')
			}
		}
}
//--------------------------------------------------------------------
//coded by HAMED SAATI <www.HAM3D.net> <hamed.saati@gmail.com>
