﻿function serverQuery( url, blockid, data, method, callback_function, responseType )
	{
		var XMLHttpRequestObject = false;
		this.onCompletion = function(){  };
	if( window.XMLHttpRequest )
	    {
			XMLHttpRequestObject = new XMLHttpRequest();
		}
		else if( window.ActiveXObject )
		{
			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if( XMLHttpRequestObject )
	    {
			
			if(method == "post" &&  '' != data){
				
				loading(blockid,1);
				XMLHttpRequestObject.open('POST', url);
					XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
					XMLHttpRequestObject.send(data); 
					
				XMLHttpRequestObject.onreadystatechange = function() {
						 if(XMLHttpRequestObject.readyState == 4  && XMLHttpRequestObject.status == 200){
							 
							var answer = XMLHttpRequestObject.responseText;

								if ( '' != callback_function ){
											
									if(callback_function == "showAjaxBasketContent"){
										this.onCompletion = function(){ showAjaxBasketContent(answer); };
									}else if(callback_function == "ajaxValidateRemovedProduct"){
										this.onCompletion = function(){ ajaxValidateRemovedProduct(answer); };
									}
										this.onCompletion();

								}else{
							 
										getID(blockid).innerHTML = answer;
								 }
				loading(blockid,0);
						 }
					}
			}else{
					XMLHttpRequestObject.open( "GET", url );
					XMLHttpRequestObject.onreadystatechange = function()
					{
						if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 )
						{
							if ( '' != callback_function )
							{
								if ( 'xml' == responseType )
									answer = XMLHttpRequestObject.responseXML;
								else
									answer = XMLHttpRequestObject.responseText;
		
								callback_function(answer);
							}
		
							delete XMLHttpRequestObject;
							XMLHttpRequestObject = null;
						}
					}
					XMLHttpRequestObject.send( null );
				}
			}
		return true;
	}

function loading(blockid,stat){
	base = document.getElementsByTagName("html");
	
	if(blockid == "loading_basket"){

	note_loading = '<div align="center"><img src="/images/loading_1.gif" width="16" height="11" border="0" style="margin: 5px;"><br/>منتظر بمانید<div><br>';
	
	}else if(blockid == "rand_pic"){
		
	note_loading = '<div align="center"><img src="/images/loading_1.gif" width="16" height="11" border="0" style="margin: 5px;"><br/>منتظر بمانید<div><br>';
		
	}else{
	note_loading = '<br/><br/><br/><br/><br/><div align="center" style="width:500px"><img src="/images/loading.gif" width="22" height="22" border="0" style="margin: 5px;"><br/>منتظر بمانید<div><br>';
	
	}

	if(stat==1){
	    base[0].style.cursor = 'wait';
		
 	if(getID(blockid)){
		
    	getID(blockid).style.display ='';
 		getID(blockid).innerHTML=note_loading;
	}
	
	}else{
	    base[0].style.cursor = 'auto';
		
	if(blockid == "loading_basket"){
		 getID(blockid).style.display ='none';
	}

	}
}

function data_loader(url,blockid,post){
	
		serverQuery(url, blockid, post, 'post','','');		
		
		serverQuery("/random_pic.php", "rand_pic", 'ajax=yes', 'post','','');		
}

function getID(id)
{
	return document.getElementById(id);
}

function fadeup(elementId,red,green,blue) {

	if (red ==255 && green == 255 && blue==255) {
		getID(elementId).style.backgroundColor = "transparent";
		return true;
	}

	getID(elementId).style.backgroundColor = "rgb("+red+","+green+","+blue+")";

	red = red + Math.ceil((255 - red)/10);
	green = green + Math.ceil((255-green)/10);
	blue = blue + Math.ceil((255-blue)/10);

	setTimeout("fadeup('"+elementId+"',"+red+","+green+","+blue+")", 30);

}

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    return;
  }
}

var win= null;
function nWin(mypage,myname,w,h,scroll) {
 var winl = (screen.width-w)/2;
 var wint = (screen.height-h)/2;
 var settings ="height="+h+",";
 settings +="width="+w+",";
 settings +="top="+wint+",";
 settings +="left="+winl+",";
 settings +="scrollbars="+scroll+",";
 settings +="resizable=no,status=0,menubar=0,toolbar=0";
 win=window.open(mypage,myname,settings);
 if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
function ss(stat) {
		
				if(document.getElementById('payment').checked){
						  document.getElementById('acc').value= stat;
				}else{
						  document.getElementById('acc').value= stat;
				}
		}

/*
function main_ajax_do(url , thisid, post){
	
 	var xmlhttp=false;
        show_id(thisid)
        write_in_id(thisid ,'<font face="Tahoma" style="font-size: 8pt"><img src="/images/loading.gif" width="24" height="24" border="0" style="margin: 5px; filter: alpha(opacity=40);">&#1604;&#1591;&#1601;&#1575; &#1589;&#1576;&#1585; &#1705;&#1606;&#1610;&#1583; ...</span></font><br>') ;
       
		loading_effect(1);
    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(thisid).innerHTML =xmlhttp.responseText;
                loading_effect(0);
             }
        }
}


function show_page(page,block,post,option){
if(option=='yes'){
 document.title = "جامعترین سایت سینمای جهان به زبان فارسی - PersianMovieClub.com";
}else{
	
 document.title = option;
}
if(option=='yes')
	{		
	    hide_id('boxoffice')
		hide_id('product')
	}
block_loader('/random_pic','picrandom','ajax=yes&block=boxoffice')

main_ajax_do(page+'.php',block,post);		
}

function cat_show(ar_varible){
hide_id('rate')
hide_id('product')
block_loader('toppro','topproduct')
main_ajax_do('/index.php','main','id='+ar_varible+'');		
}
function shop_search(){
         
    ar_varible=get_value_for_ajax('search_box');	
	if (ar_varible == '')
		{
		write_in_id('search_error' ,'&nbsp;&nbsp;&nbsp;!!! فیلد جستجو خالی میباشد ')
		}
		else
		{	
		hide_id('search_error')
		hide_id('rate')
		main_ajax_do('search.php', 'main', 'search='+ar_varible+'')
		}
}

function AddToCart(Site){
 window.open(Site,"viewwin","toolbar=1,status=1,scrollbars=yes,width=590,height=530,resizable=0");
 } 

function new_movie_detail(block,id,title,post){
 document.title = title+" - PersianMovieClub.com";
main_ajax_do('/show_detail.php','main','id='+id+'&block='+block+'&ajax=yes&'+post);	
}

function show_detail(id){
hide_id('topproduct')
hide_id('rand')
main_ajax_do('show_detail.php','main','id='+id+'');	
block_loader('related_product','related_product','id='+id+'');
block_loader('tellfriend','tellfriend','id='+id+'');
block_loader('rating','rate','id='+id+'');
}



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_div_value_for_ajax ( id ){
	return encodeURIComponent(document.getElementById(id).innerHTML);
}

function loading_effect(k){
	ht = document.getElementsByTagName("html");
	if(k==1){
	    ht[0].style.cursor = 'wait';
	}else{
	    ht[0].style.cursor = 'auto';
	}
}







function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return true;		
} 

}

}

*/
