var help_active=true;var posted=0;var fd=0;errstr="";var mode;

var nav=navigator.appName;
var ie=(nav.indexOf("Microsoft")!=-1);
var ns=(nav.indexOf("Netscape")!=-1);
function nrcIE(){return false;}
if(ie){document.oncontextmenu=nrcIE;}
//document.onselectstart=new Function("return false;");
//document.ondragstart=new Function("return false;");
document.onmousemove=new Function("window.status='Secured by PersianForm';");

function forminit(){
	document.onkeyup = show_help;document.onclick= show_help;
}

function NumberCheck(){
	var key;
	if (window.event){
		key = window.event.keyCode;
	}
	if (key ==13){
		return true;
	}
	if (key >57){
		return false;
	}
	if ((key <48)&&(key != 46)){
		return false;
	}else{
		return true;
	}
}

function DateCheck(){
	var key;
	if (window.event){
		key = window.event.keyCode;
	}
	if (key ==13){
		return true;
	}
	if (key >57){
		return false;
	}
	if (key <47){
		return false;
	}else{
		return true;
	}
}


function AlphabetCheck(){
	var key;
	if (window.event){
		key = window.event.keyCode;
	}
	if (key >128){
		window.event.keyCode='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.charCodeAt(key-256);
		return false;
	}
}

function show_help(){
	if(event.srcElement.id=='chb'){
		help_active=false;
		help.style.display='none'
	}
	if(help_active==true){
		yh=0;
		xh=0;
		var obj = event.srcElement;
		help_text.innerHTML=obj.help;
		if(obj.help>''){
			help.style.display ='';
		}else{
			help.style.display ='none';
		}
		xw=obj.offsetWidth;
		yw=obj.offsetHeight;
		while(obj!= null){
			yh=yh+obj.offsetTop;
			xh=xh+obj.offsetLeft;
			obj = obj.offsetParent;
		}
		xh=xh+xw ;
		if(xh+150>document.body.clientWidth){
			xh=xh-2*xw-5;
		}
		if(yh+yw+help.offsetHeight>document.body.clientHeight){
			yh=yh+yw-help.offsetHeight;
		}else{
			yh=yh+yw
		}
		help.style.left=xh;
		help.style.top=yh;
	}
}

function helpact(obj){
	if(help_active==true){
		help_active=false;
		help.style.display='none';
		obj.value='&#1583;&#1587;&#1578;&#1610;&#1575;&#1585; &#1601;&#1593;&#1575;&#1604;'
	}else{
		help_active=true;
		obj.value='&#1583;&#1587;&#1578;&#1610;&#1575;&#1585; &#1594;&#1610;&#1585;&#1601;&#1593;&#1575;&#1604;'
	}
}


function CheckForm(){
	errstr="";
	errors.innerHTML='';
	errsit=true
	var str="";
	//************** TEXT BOX
	els=document.form.elements.tags("INPUT").length
	for(i=0;i<els;i++){
		elstype=document.form.elements.tags("INPUT")[i].type

		if((elstype=="text")||(elstype=='password')){
			id=document.form.elements.tags("INPUT")[i].name
			if(id!="secode"){
				eval('check_textbox(form.'+id+')');
			}else{
				if(form.secode.value.length!=7){
					AddError(form.secode,"&#1583;&#1585;&#1587;&#1578; &#1608;&#1575;&#1585;&#1583; &#1606;&#1588;&#1583;&#1607; &#1575;&#1587;&#1578;","&#1705;&#1583; &#1575;&#1605;&#1606;&#1610;&#1578;&#1610;")
				}				
			}
		}

		if(elstype=="hidden"){
			id=document.form.elements.tags("INPUT")[i].name
			if(id.indexOf("sys_",0)==-1){
				check_combo(id)
			}
		}
		
		if(elstype=="file"){
			id=document.form.elements.tags("INPUT")[i].name
			eval('check_file(form.'+id+')');
		}

	}
	//	 ************* TEXT AREA
	els=document.form.elements.tags("TEXTAREA").length
	for(i=0;i<els;i++){
		id=document.form.elements.tags("TEXTAREA")[i].name
		eval('check_textbox(form.'+id+')');
	}

	if (errsit==true){
		if(mode=='preview'){alert('Demo !');return false;}else{
			start();
		}
	}else{
		errors.innerHTML=errstr
		window.location='#error'
	}
	return errsit
}

function check_combo(id){
			mid=id.replace('_list','');
			//form_n=Math.round(Math.random()*9999)+1
			eval('obj=form.'+mid);
			eval('obj_list=form.'+id);
			typ=obj_list.typ
			cnt1=obj_list.cnt
			title=obj_list.title
			valid=obj_list.valid
			valid2=obj_list.valid2
			nmin=obj_list.nmin
			nmax=obj_list.nmax
			if((typ==1)||(typ==3)){
				ok=0
				for(k=0;k<obj.length;k++){
					if(obj[k].checked==true){ok++}
				}
				if(obj.checked==true){ok=1;}
				if(valid==1){
					if(ok==0){	
						m5="&#1607;&#1610;&#1670; &#1711;&#1586;&#1610;&#1606;&#1607; &#1575;&#1610; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1606;&#1588;&#1583;&#1607; &#1575;&#1587;&#1578;";
						if(obj.checked==false){m5="&#1576;&#1575;&#1610;&#1583; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1588;&#1608;&#1583;";}
						AddError(obj,m5,title)
					}
				}
				if((valid2==1)&&(typ==3)){
					if(nmin==nmax){
						if ((nmin>0)&&(ok>nmin)){
							m8="&#1576;&#1575;&#1610;&#1587;&#1578;&#1610; &#1601;&#1602;&#1591; "+nmin+" &#1711;&#1586;&#1610;&#1606;&#1607; &#1585;&#1575; &#1578;&#1610;&#1705; &#1576;&#1586;&#1606;&#1610;&#1583;";
							AddError(obj,m8,title)
						}
					}else{
						if((ok<nmin)&&(nmin>0)){	
								m6="&#1581;&#1583;&#1575;&#1602;&#1604; &#1576;&#1575;&#1610;&#1583; "+nmin+" &#1711;&#1586;&#1610;&#1606;&#1607; &#1585;&#1575; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1705;&#1606;&#1610;&#1583;";
								AddError(obj,m6,title)
						}
						if((ok>nmax)&&(nmax>0)){	
								m7="&#1581;&#1583;&#1575;&#1705;&#1579;&#1585; &#1576;&#1575;&#1610;&#1583; "+nmax+" &#1711;&#1586;&#1610;&#1606;&#1607; &#1585;&#1575; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1705;&#1606;&#1610;&#1583;";
								AddError(obj,m7,title)
						}
					}
				}
		}else{
			if(valid==1){
				if((obj.selectedIndex ==0)&&(typ==2)){
					m5="&#1576;&#1575;&#1610;&#1587;&#1578;&#1610; &#1610;&#1705; &#1711;&#1586;&#1610;&#1606;&#1607; &#1585;&#1575; &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1606;&#1605;&#1575;&#1610;&#1610;&#1583;";
					AddError(obj,m5,title)
				}
			}
		}

}

function SecCheck(){
	var key;
	if (window.event){key = window.event.keyCode;} 
	if (key ==13){return true}
	if ((key >=65)&&(key <=90)){return true}
	if ((key >=97)&&(key <=122)){window.event.keyCode=key-32; return true}
	if ((key >=48)&&(key <=57)){return true}
	return false;
}


function check_textbox(obj){


	val=obj.value
	objid=obj.name
	title=obj.title
	valid1=obj.valid1
	valid2=obj.valid2
	valid3=obj.valid3
	valid4=obj.valid4
	eq1=obj.eq1
	eqt1=obj.eqt1
	eq2=obj.eq2
	eqt2=obj.eqt2
	nmax=obj.nmax
	nmin=obj.nmin
	words=obj.words
	vtype=obj.vtype

	if(valid1=='1'){
		if(eq1==">"){alamat="&#1576;&#1586;&#1585;&#1711;&#1578;&#1585;"}
		if(eq1==">="){alamat="&#1576;&#1586;&#1585;&#1711;&#1578;&#1585; &#1605;&#1587;&#1575;&#1608;&#1610;"}
		if(eq1=="<"){alamat="&#1705;&#1608;&#1670;&#1705;&#1578;&#1585;"}
		if(eq1=="<="){alamat="&#1705;&#1608;&#1670;&#1705;&#1578;&#1585; &#1605;&#1587;&#1575;&#1608;&#1610;"}
		if(eq1=="=="){alamat="&#1576;&#1585;&#1575;&#1576;&#1585;"}
		if(eq1=="!="){alamat="&#1606;&#1575;&#1576;&#1585;&#1575;&#1576;&#1585;"}

		m1=" &#1576;&#1575;&#1610;&#1583; &#1575;&#1586; ' "+eqt1+" ' "+alamat+" &#1576;&#1575;&#1588;&#1583; "
		if((vtype!=1)&&(eqt1=='')){m1="&#1606;&#1576;&#1575;&#1610;&#1583; &#1582;&#1575;&#1604;&#1610; &#1576;&#1575;&#1588;&#1583;"}
		if(vtype!=1){eqt1="'"+eqt1+"'"}
		if(!eqt1){eqt1="''"}
		if(eq1){
			eval("if(!(val"+eq1+""+eqt1+")){AddError(obj,m1,title)}");
		}
	}

	if(valid2=='1'){
		if(eq2==">"){alamat="&#1576;&#1586;&#1585;&#1711;&#1578;&#1585;"}
		if(eq2==">="){alamat="&#1576;&#1586;&#1585;&#1711;&#1578;&#1585; &#1605;&#1587;&#1575;&#1608;&#1610;"}
		if(eq2=="<"){alamat="&#1705;&#1608;&#1670;&#1705;&#1578;&#1585;"}
		if(eq2=="<="){alamat="&#1705;&#1608;&#1670;&#1705;&#1578;&#1585; &#1605;&#1587;&#1575;&#1608;&#1610;"}
		if(eq2=="=="){alamat="&#1576;&#1585;&#1575;&#1576;&#1585;"}
		if(eq2=="!="){alamat="&#1606;&#1575;&#1576;&#1585;&#1575;&#1576;&#1585;"}
		m2=" &#1576;&#1575;&#1610;&#1583; &#1575;&#1586; ' "+eqt2+" ' "+alamat+" &#1576;&#1575;&#1588;&#1583; "
		if((vtype!=1)&&(eqt2=='')){m2="&#1606;&#1576;&#1575;&#1610;&#1583; &#1582;&#1575;&#1604;&#1610; &#1576;&#1575;&#1588;&#1583;"}
		if(vtype!=1){eqt2="'"+eqt2+"'"}
		if(!eqt2){eqt2="''"}
		if(eq2){
			eval("if(!(val"+eq2+""+eqt2+")){AddError(obj,m2,title)}");
		}
	}

	if(valid3=='1'){
		if(vtype==1){ch="&#1585;&#1602;&#1605;"}else{ch="&#1581;&#1585;&#1601;"}
		m3="&#1581;&#1583;&#1575;&#1602;&#1604; &#1576;&#1575;&#1610;&#1583; "+ nmin +" "+ch+"  &#1608; &#1581;&#1583;&#1575;&#1705;&#1579;&#1585; " + nmax + " "+ch+" &#1576;&#1575;&#1588;&#1583;";
		if(nmin==nmax){
			m3="&#1576;&#1575;&#1610;&#1583; "+nmin+" " + ch + "&#1610; &#1576;&#1575;&#1588;&#1583;";
		}
		if((val.length<nmin)||(val.length>nmax)){AddError(obj,m3,title)}
	}

	if(valid4=='1'){
		dohave=0;
		sk=words.split(" ")
		if(sk.length>1){
			for(v=0;v<sk.length;v++){
				if (val.indexOf(sk[v],0) == -1){
					dohave=1;break;
				}
			}
		}else{
			if (val.indexOf(words,0) == -1){
				dohave=1;
			}
		}
		m4="&#1593;&#1576;&#1575;&#1585;&#1578; &#1608;&#1575;&#1585;&#1583; &#1588;&#1583;&#1607; &#1605;&#1593;&#1578;&#1576;&#1585; &#1606;&#1610;&#1587;&#1578;"
		if(dohave==1){AddError(obj,m4,title)}

	}

}

function check_file(obj){

	if((obj.value=='')&&(obj.valid1==1)){
		AddError(obj,"&#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1606;&#1588;&#1583;&#1607; &#1575;&#1587;&#1578;",obj.title)
	}
	if(obj.valid3==1){
		if(obj.value.substr(0,1).toUpperCase()!=obj.drive)
		AddError(obj,"&#1576;&#1575;&#1610;&#1583; &#1575;&#1586; &#1585;&#1608;&#1610; &#1583;&#1585;&#1575;&#1610;&#1608; "+obj.drive+" &#1575;&#1606;&#1578;&#1582;&#1575;&#1576; &#1588;&#1608;&#1583;",obj.title)
	}
	if(obj.valid4==1){
		extension=obj.value.substr(obj.value.length-4,4)
		extension=extension.toLowerCase()
		mojaz=obj.mojaz.toLowerCase()
		if(mojaz.indexOf(extension.replace('.',''),0)==-1){
			AddError(obj,"&#1662;&#1587;&#1608;&#1606;&#1583; "+ extension.replace('.','') +" &#1605;&#1580;&#1575;&#1586; &#1606;&#1610;&#1587;&#1578;",obj.title)
		}
	}

}

function AddError(id,message,name){

	errstr+="<br>"+name+" : "+message
	errsit=false;
}

function finish(){
	if (posted>0){
		send.style.display='none'
		fc=(document.body.clientWidth-350)/2;if(fc<0){fc=0;}
		fh=(document.body.clientHeight-70)/2;if(fh<0){fh=0};
		message.style.left=fc
		message.style.top=fh
		message.style.display=''
		fcmw.focus();
		fd=0;
	}
}

function start(){
	form.sys_speed.value=sp;
	form.sys_screen.value=screen.width+"x"+screen.height+" "+screen.colorDepth+"bit"+" "+document.body.clientWidth+"x"+document.body.clientHeight;
	dte=new Date()
	mm=dte.getMinutes();
	hh=dte.getHours();
	if(mm<9){mm='0'+mm;}
	if(hh<9){hh='0'+hh;}
	form.sys_localtime.value=hh+":"+mm
	fc=(document.body.clientWidth-343)/2;if(fc<0){fc=0;}
	fh=(document.body.clientHeight-66)/2;if(fh<0){fh=0};
	send.style.left=fc
	send.style.top=fh
	xpbk.style.height=allh.offsetHeight
	hide_select();
	xpbk.style.display=""
	send.style.display="";
	tofocus.focus()
	posted++;
}

function hide_select(){

	els=document.form.elements.tags("SELECT").length
	for(i=0;i<els;i++){
		document.form.elements.tags("SELECT")[i].style.display="none"
	}

}

function show_select(){
	els=document.form.elements.tags("SELECT").length
	for(i=0;i<els;i++){
		document.form.elements.tags("SELECT")[i].style.display=""
	}
}


function close_message(){
	message.style.display='none';
	xpbk.style.display='none';
	show_select()
}

function print_message(){
	ipost.document.execCommand('Print')
}
 
function message_key(){
	key = window.event.keyCode
	if((key==27)||(key==13)){close_message()}
}

function cancel_send(){
		send.style.display='none';
		xpbk.style.display='none';
		fd=0;
		posted=0;
		ipost.window.stop();
		window.stop();
}

function send_key(){
	key = window.event.keyCode
	if(key==27){
		cancel_send()
	}
}

 var keyboard="Farsi";
function FKeyPress(){
	key = window.event.keyCode;
	if((key==39)&&(keyboard!="Farsi")){window.event.keyCode=34;return true;}
	if ((key>127)||(key<32)){return true;}
	if ( keyboard == "Farsi"){
		//basestring=' !"#$%،گ)(×+و-./0123456789:ك,=.؟@ِذ}ىُىلآ÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزيثبلاهتنمئدخحضقسفعرصطغظ<|>ّ';
		window.event.keyCode=basestring.charCodeAt(key-32);
	}
	return true;
}
function FKeyDown(){
	key=window.event.keyCode;
	if (key==145){  
		if (keyboard == "Farsi"){
			keyboard = "English" ;
		}else{
			keyboard = "Farsi"; 
		}
	}
	return true;
}

function window.onscroll(){
	fc=(document.body.clientWidth-343)/2;if(fc<0){fc=0;}
	fh=(document.body.clientHeight-66)/2;if(fh<0){fh=0};
	send.style.left=fc
	send.style.top=fh
	fc=(document.body.clientWidth-350)/2;if(fc<0){fc=0;}
	fh=(document.body.clientHeight-70)/2;if(fh<0){fh=0};
	message.style.left=fc
	message.style.top=fh
}

function window.onresize(){
	fc=(document.body.clientWidth-343)/2;if(fc<0){fc=0;}
	fh=(document.body.clientHeight-66)/2;if(fh<0){fh=0};
	send.style.left=fc
	send.style.top=fh
	fc=(document.body.clientWidth-350)/2;if(fc<0){fc=0;}
	fh=(document.body.clientHeight-70)/2;if(fh<0){fh=0};
	message.style.left=fc
	message.style.top=fh
}



function show_help_window(){
	if(mode=='preview'){alert('Demo!');return false;}
	els=document.form.elements.tags("INPUT").length
	str="<meta http-equiv='Content-Language' content='fa'><meta http-equiv='Content-Language' content='windows-1256'><title>راهنما</title><body dir=rtl style='font-family: Tahoma; font-size: 10pt'>"
	str+="<b>چاپ</b> :<br>براي چاپ اين صفحه کليد CTRL+P را فشار دهيد<p></p></body>"
	str+="<b>تغيير صفحه کليد</b> :<br>براي تغيير صفحه کليد به انگليسي و فارسي و يا بالعکس مي توانيد از کليد Scroll استفاده کنيد<p></p></body>"
	for(i=0;i<els;i++){
		hlp=document.form.elements.tags("INPUT")[i].help
		title=document.form.elements.tags("INPUT")[i].title
		if((hlp)&&(title)){str+="<b>"+title+"</b> :<br>"+hlp+"<p></p>"}
	}
	str+="</body>"
	var helpWindow = window.open('', 'helpwindow' , 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=750,height=550');
	helpWindow.document.open();
	helpWindow.document.write(str);
}
