

﻿//Copyright "Ali Karimabadi" Email: Akarimabadi@gmail.com
//Dar sorat estefadeh az in Javascript Copyright Nevisande code ha ra Hazf nakonid.

//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="ltr" style="background-color:#FFFFFF;color:black;font-size:11px;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.ScrollDown('systemWorking',{queue:{scope:'myscope', position:'end'},duration:2});
		}
	},onComplete: function(){
			new Effect.BlindUp('systemWorking',{queue:{scope:'myscope', position:'end'},duration:2});
			//if(Ajax.activeRequestCount == 0){new Effect.BlindUp('systemWorking');}
	}
};
Ajax.Responders.register(myGlobalHandlers);

//window.onerror = function(){return true;} 

GetLoading=function (){
	return '<div align="center" dir="ltr"><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='url(./images/warning.gif) no-repeat  left';
	}else{
		id.border='#c0c0c0 1px solid';
		id.className='input';
		id.background='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='Appear';
	$(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);},onSuccess: function(t) {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='./news2.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='<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('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',
		    // Send this lovely data
		    postBody: 'AJAXED=1&'+poststr+'&rnd='+Math.round(100000*Math.random()),
		    // 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/progress1.gif" border="0"></div>';
		var myAjax = new Ajax.Updater('center', 'search.php',Proccess_Srch );
		return false;
}

//Frame Print by: Ali Karimabadi
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();
}
//Release Page
syswork.style.display='none';