﻿//System Work indicator
var myGlobalHandlers = {
	onCreate: function(){
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		if ($('systemWorking')) {
			//$('systemWorking').style.top = '0 px';
			//$('systemWorking').style.left = '0 px';
//			$('systemWorking').style.height = (yScroll + 'px');
//			$('systemWorking').style.width = (xScroll + 'px');
//			$('systemWorking').innerHTML='<br><div align="center" dir="rtl" style="background-color:#FFFFFF;color:black;font-size:12px;font-family:verdana;border:1px solid #333333;padding-top:5px;padding-bottom:5px;"><b>درحال دریافت اطلاعات  لطفا منتظر بمائید...</b><br><img src="./images/progress1.gif" border="0"></div>';
//			Element.show('systemWorking');
			//new Effect.Appear('systemWorking',{duration:3});
		}
	},onComplete: function(request, transport){
			//Element.hide('systemWorking');
			new Effect.BlindUp('systemWorking',{duration:1});
			//if(Ajax.activeRequestCount == 0){new Effect.BlindUp('systemWorking');}
			if(transport.responseText=='OFFLINE'){
				LoadPage('./members/loginform.php?AJAXED=1','center');
				LoadPage('./box/members_box.php?AJAXED=1','members_lay');
				return false;
			}
	}
};
Ajax.Responders.register(myGlobalHandlers);

//window.onerror = function(){return true;} 

GetLoading=function (){
	return '<div align="center" dir="rtl" style="font-size:11px"><b>لطفا منتظر بمائید...</b><br><img src="./images/progress.gif" border="0"></div>';
}
changeStyle=function(id,status){
	if(status==1){
		id.border='solid 1pt red';
		id.background='#ffffff url(./images/warning.gif) no-repeat  left';
	}else{
		id.border='#c0c0c0 1px solid';
		id.className='input';
		id.background='#ffffff url(./images/ok.gif) no-repeat left';
	}
}

changeBorder=function(place,color,focos,msg,to){
	if(color && color.length>0){
		place.style.border='solid 1px '+color;
	}else{
		place.style.border='solid 0px';
	}
	if(focos){focos.focus();}
	if(msg && to){to.innerHTML=msg}
}
LoadPage=function(url,idl,effect){
	var pars = '';
	//if(!effect)effect='Highlight';
	$(idl).innerHTML=GetLoading();
	var myAjax = new Ajax.Updater(idl, url, {method: 'get', parameters: pars,evalScripts:true, onFailure: function(t) {alert('Error in internet Connection: ' + t.status + ' -- ' + t.statusText);},onComplete: function(t) {if(document.getElementById('navig') && document.getElementById('navig').innerHTML.length>0 && idl=='center'){$('nav-title').innerHTML=$('navig').innerHTML;$('navig').innerHTML='';$('navig').remove();}if(effect){var effects='new Effect.'+effect+'(\''+idl+'\')';eval(effects);}}});
}

sub_com=function(){
			var poststr='';
			for(var k=0;k<CF.elements.length;k++){
				poststr+='&'+CF.elements[k].name+'='+encodeURI(CF.elements[k].value);
			}

		var Proccess_comnt = {
		    // Use POST
		    method: 'post',
		    // Send this lovely data
		    postBody: 'AJAXED=1'+poststr,
		    // Handle successful response
		    onSuccess: function(t) {
		    },
		    // Handle 404
		    on404: function(t) {
		        alert('Error 404: location "' + t.statusText + '" was not found.');
		    },
		    // Handle other errors
		    onFailure: function(t) {
		        alert('Error ' + t.status + ' -- ' + t.statusText);
		    }
		}
		comnt_win.setDestroyOnClose();
		comnt_win.getContent().innerHTML='<center>Please Wait Loading...</center>';
		comnt_win.setAjaxContent('./acomment.php', Proccess_comnt, true, true);
		return false;
}


show_com=function(url){
		var Proccess_comnt = {
		    // Use POST
		    method: 'get',
		    // Send this lovely data
		    parameters: 'AJAXED=1',
			evalScripts:true,
		    // Handle successful response
		    onSuccess: function(t) {
		    },
		    // Handle 404
		    on404: function(t) {
		        alert('Error 404: location "' + t.statusText + '" was not found.');
		    },
		    // Handle other errors
		    onFailure: function(t) {
		        alert('Error ' + t.status + ' -- ' + t.statusText);
		    }
		}
		if (!$('comnt_win')) {
			comnt_win = new Window('comnt'+Math.round(100000*Math.random()), {className: "alphacube", title: "Comments", 
		                                              top:70, left:100, width:450, height:350,
		                                              resizable: true,showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, showEffectOptions: {duration:1}});
		}
		comnt_win.setDestroyOnClose();
		comnt_win.getContent().innerHTML='<center>Please Wait Loading...</center>';
		comnt_win.setAjaxContent(url, Proccess_comnt, true, true);
		return false;
}

Load_img=function(url){
	if (!$('gallery_im_win')) {
		gallery_im_win = new Window('gallery'+Math.round(100000*Math.random()), {className: "alphacube", title: "View image", 
	                                              top:70, left:100, width:500, height:500,
	                                              resizable: true,showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, showEffectOptions: {duration:1}});
	}
	gallery_im_win.setDestroyOnClose();
	gallery_im_win.getContent().innerHTML='<center><img src="'+url+'" border="0"></center>';
	gallery_im_win.showCenter(true);
}

sub_com2=function(){
			var poststr='';
			for(var k=0;k<CF.elements.length;k++){
				poststr+='&'+CF.elements[k].name+'='+encodeURI(CF.elements[k].value);
			}
			var url='';
			url='./product.php?op=listcomment&AJAXED=1&id='+CF.fid.value;
		var Proccess_comnt = {
		    // Use POST
		    method: 'post',
		    // Send this lovely data
		    postBody: 'AJAXED=1'+poststr,
		    // Handle successful response
		    onSuccess: function(t) {
			LoadPage(url,'Commlist');
		    },
		    // Handle 404
		    on404: function(t) {
		        alert('Error 404: location "' + t.statusText + '" was not found.');
		    },
		    // Handle other errors
		    onFailure: function(t) {
		        alert('Error ' + t.status + ' -- ' + t.statusText);
		    }
		}
		Comm.innerHTML=GetLoading();
		var myAjax = new Ajax.Updater('Comm', 'acomment.php',Proccess_comnt );
		return false;
}

sub_qa=function(){
			var poststr='';
			for(var k=0;k<CF.elements.length;k++){
				poststr+='&'+CF.elements[k].name+'='+encodeURI(CF.elements[k].value);
			}

		var Proccess_comnt = {
		    // Use POST
		    method: 'post',
		    // Send this lovely data
		    postBody: 'AJAXED=1'+poststr,
		    // Handle successful response
		    onSuccess: function(t) {
		    },
		    // Handle 404
		    on404: function(t) {
		        alert('Error 404: location "' + t.statusText + '" was not found.');
		    },
		    // Handle other errors
		    onFailure: function(t) {
		        alert('Error ' + t.status + ' -- ' + t.statusText);
		    }
		}
		center.innerHTML='<div align="center" dir="ltr" style="font-size:11px"><b>Please Wait Loading... </b><br><img src="./images/progress.gif" border="0"></div>';
		var myAjax = new Ajax.Updater('center', 'qa.php',Proccess_comnt );
		return false;
}

Search_sit=function(key){
			var poststr='';
			poststr='key='+encodeURI(key);
		var Proccess_Srch = {
		    // Use POST
		    method: 'post',
		    			evalScripts:true,
		    // Send this lovely data
		    postBody: 'AJAXED=1&'+poststr+'&rnd='+Math.round(100000*Math.random()),
		    // Handle successful response
		    onComplete: function(t) {
			    if(document.getElementById('navig') && document.getElementById('navig').innerHTML.length>0){$('nav-title').innerHTML=$('navig').innerHTML;$('navig').innerHTML='';$('navig').remove();}
		    },
		    // Handle 404
		    on404: function(t) {
		        alert('Error 404: location "' + t.statusText + '" was not found.');
		    },
		    // Handle other errors
		    onFailure: function(t) {
		        alert('Error ' + t.status + ' -- ' + t.statusText);
		    }
		}
		$('center').innerHTML='<div align="center" dir="ltr" style="font-size:11px"><b>Please Wait Loading... </b><br><img src="./images/progress1.gif" border="0"></div>';
		var myAjax = new Ajax.Updater('center', 'search.php',Proccess_Srch );
		return false;
}

//Frame Print 
framePrint=function framePrint(whichFrame,id){
	parent[whichFrame].designMode='on';
	parent[whichFrame].document.body.style.direction='rtl';
	parent[whichFrame].document.body.style.fontSize='11px';
	parent[whichFrame].document.body.style.fontFamily='tahoma';
	parent[whichFrame].document.body.innerHTML=document.getElementById(id).innerHTML;
	parent[whichFrame].focus();
	parent[whichFrame].print();
}

detectBrowser=function (){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if ((browser=="Microsoft Internet Explorer") && (version>=4)){//browser=="Netscape"||
		return 1;
	}else{
		return 0;
	}
}

if(detectBrowser()==0){
//	alert('Dear visitor this site work properly on IE 6,IE 7+ and you need change your browser or upgrade to see correct design of site \n بازدیدکننده گرامی بهترین نمایش این سایت در مرورگر اینترنت اکسپلورر نسخه 6 و 7 و نسخه های بعدی می باشد و با مرورگر فعلی شما سازگاری کامل ندارد.');
}
//Release Page
syswork.style.display='none';
