window.onerror = null;
function AutoMaximize()
{
	/*
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth,screen.availHeight);	
	*/
}
function GetUnicodeFromAsci(inter, rettype)
{
	var ln = new Array ("i","a","b","t","c","H","x","d","r","z","s","S","I","f","q","k","l","m","n","h","u","w","y","G","g","C","R","v","j","p","o","Y","e","L","D","P",",");
	var ku = new Array ("\u0626","\u0627","\u0628","\u062A","\u062C","\u062D","\u062E","\u062F","\u0631","\u0632","\u0633","\u0634","\u0639","\u0641","\u0642","\u0643","\u0644","\u0645","\u0646","\u06BE","\u0648","\u0648","\u06CC","\u063A","\u06AF","\u0686","\u0695","\u06A4","\u0698","\u067E","\u06C6","\u06CE","\u0647\u200C","\u06B5","<br>","\u061F","\u066C");
	var result='';	
	for (i=0;i<=ln.length-1;i++)
	{
		var newreg = new RegExp(ln[i], 'g');
		result = inter.replace(newreg, ku[i]);
		inter = result;
	}
	if(rettype==0)
	{
		return result;
	}
	else
	{
		document.write(result);
	}
}
function GetAsciFromUnicode(inter, rettype)
{
	var ku = new Array ("i","a","b","t","c","H","x","d","r","z","s","S","I","f","q","k","l","m","n","u","w","y","G","g","C","R","v","j","p","o","Y","e","L","D","P","h");
	var ln = new Array ("\u0626","\u0627","\u0628","\u062A","\u062C","\u062D","\u062E","\u062F","\u0631","\u0632","\u0633","\u0634","\u0639","\u0641","\u0642","\u0643","\u0644","\u0645","\u0646","\u0648","\u0648","\u06CC","\u063A","\u06AF","\u0686","\u0695","\u06A4","\u0698","\u067E","\u06C6","\u06CE","\u0647\u200C","\u06B5","<br>","\u061F","\u0647");
	var result='';	
	for (i=0;i<=ln.length-1;i++)
	{
		var newreg = new RegExp(ln[i], 'g');
		result = inter.replace(newreg, ku[i]);
		inter = result;
	}
	if(rettype==0)
	{
		return result;
	}
	else
	{
		document.write(result);
	}
}
function WordsReport(chr,ifront)
{
	if(document.all.lstZman01.value != document.all.lstZman02.value)
	{
		openWindow('eFerheng_Words.asp?type=1&chr='+chr+'&lid1='+document.all.lstZman01.value+'&lid2='+document.all.lstZman02.value+'&uid=0&ifront='+ifront+'',"words",document.body.clientWidth,document.body.clientHeight+100,"yes","center");
	}
	else
	{
		alert(GetUnicodeFromAsci('tkaye duu zmany cyawaz heLbjYre.',0));
		document.all.lstZman02.focus();
	}
}
function GetFlag(id, img)
{
	document.all[img].src="images/"+id+".gif";
}
function FormatString()
{
	document.all.hidUshe.value = GetAsciFromUnicode(document.all.txtUshe.value,0);
}
function CopyChr(chr)
{
	document.all.txtUshe.value += chr;
	document.all.txtUshe.focus();
}
function CopyChr2(chr)
{
	if(document.all.hidTextbox.value != "")
	{
		document.all[document.all.hidTextbox.value].value +=chr;
		document.all[document.all.hidTextbox.value].focus();
	}
}
function CopyLanguage()
{
	var lang = document.all.lstLanguage;
	document.all.txtLanguage.value=lang.options[lang.selectedIndex].t;
	document.all.txtLanguageFront.value=lang.options[lang.selectedIndex].tf;
	document.all.lstFront.value=lang.options[lang.selectedIndex].f;
	document.all.lstActive.options.selectedIndex=lang.options[lang.selectedIndex].a;
	document.all.lstDir.options.selectedIndex=lang.options[lang.selectedIndex].d;
	document.all.spnID.innerText=lang.options[lang.selectedIndex].value;	
	document.all.imgID.src='images/'+lang.options[lang.selectedIndex].value+'.gif';
}
function CopyLbl()
{
	var lang = document.all.lstLables;
	document.all.txtLbl.value=lang.options[lang.selectedIndex].lbl;	
	document.all.txtID.value=lang.options[lang.selectedIndex].value;	
	document.all.spnEdit.style.display='block';
}
function CopyUser()
{
	var u = document.all.lstUsers;
	document.all.txtUserName.value=u.options[u.selectedIndex].n;
	document.all.txtUserNameLatin.value=u.options[u.selectedIndex].ul;
	document.all.txtLoginName.value=u.options[u.selectedIndex].l;
	document.all.txtPassword.value='';
	document.all.lstActiveUser.options.selectedIndex=u.options[u.selectedIndex].a;
	document.all.lstRols.options.selectedIndex=u.options[u.selectedIndex].r;
	document.all.txtUEmail.value=u.options[u.selectedIndex].e;
	document.all.txtTel.value=u.options[u.selectedIndex].t;
	document.all.txtMobile.value=u.options[u.selectedIndex].mobile;
	document.all.txtMessenger.value=u.options[u.selectedIndex].messenger;
	document.all.txtPaltalk.value=u.options[u.selectedIndex].paltalk;
	document.all.spnID.innerText=u.options[u.selectedIndex].value;
}
function ShowSecondTabe()
{
	var lang = document.all.lstShowLU;
	if(document.all.tabLU !=null)
	{
		if(lang.options[lang.selectedIndex].value=="0")
		{
			document.all.tabLU.style.display='none';
		}
		else
		{
			document.all.tabLU.style.display='block';
		}
	}
}
function DeleteRecord(type, oid, lid)
{
	var deleteword = '';
	if(type==0)
	{
		deleteword= window.confirm(GetUnicodeFromAsci("iaya detewYt iem uSeye le ferhengekeda bkujYnyteweP",0)+"\nAre you sure you want to delete this word?");
	}
	if(type==1)
	{
		deleteword= window.confirm(GetUnicodeFromAsci("iaya detewYt iem uSe kurdyye u iew uSaneSy ke be zmanekany tr peywendn pYyewe le ferhengekeda bkujYnyteweP",0));
	}
	if(type==2)
	{
		deleteword= window.confirm(GetUnicodeFromAsci("iaya detewYt iem peyame bkujYnyteweP",0)+"\nWould you like to delete this message?");
	}
	if(deleteword)
	{
		if(oid!="")
		{
			document.all.ifrmDelete.src='eFerheng_Delete.asp?type='+type+'&wid='+oid+'&lid='+lid+'';
			frmFerheng.submit();
		}
	}
}
function DeleteRecordNoConfirm(type, oid, lid)
{	
	if(oid!="")
	{
		document.all.ifrmDelete.src='eFerheng_Delete.asp?type='+type+'&wid='+oid+'&lid='+lid+'';
		frmFerheng.submit();
	}	
}
function FindWord(word, lng)
{		
	var list = document.all.lstWords;
	var words = list.options.length;
	var lword = word.length;		
	var sword=GetAsciFromUnicode(word,0);
	for(i=0;i<=words-1;i++)
	{
		if(lng==1)
		{	
			if(sword==list.options[i].f.substring(0, lword))
			{
				list.options[i].selected=true;
				return false;
			}
		}
		else
		{
			if(word==list.options[i].f.substring(0, lword))
			{
				list.options[i].selected=true;
				return false;
			}
		}
		
	}
}
function TranslateWord(words, lng, lng2, ifront)
{	
	if(words.options.length > 0)
	{
		if(lng==1)
		{
			document.all.txtFind.value=GetUnicodeFromAsci(words.options[words.options.selectedIndex].f,0);		
		}
		else
		{
			document.all.txtFind.value=words.options[words.options.selectedIndex].f;
		}
		var trres = document.all.tdResult;
		var shtml = '';
		var oid = words.options[words.options.selectedIndex].otherid;
		var kid = words.options[words.options.selectedIndex].value;	
		if(lng2==1)
		{
			oid = words.options[words.options.selectedIndex].value;
			kid = words.options[words.options.selectedIndex].otherid;	
		}
		shtml +='<table style="color:red; font-weight : bold;" width="100%" cellpadding="0" cellspacing="0" border="0">';
		shtml +='<tr>';	
		if(parseInt(oid) > 0 )
		{
			shtml +='<td width="18" valign="top">';			
			shtml +='<a href="#" onclick=openModal("eFerheng_Words_Description.asp?Table=2&Mode=0&iFront='+ifront+'&KID='+kid+'&OID='+oid+'",document.body.clientHeight,document.body.clientWidth);><img border="0" src="images/xor.gif" alt="'+GetUnicodeFromAsci("zanyaryy zortr derbarey uSe wergYRdraweke",0)+'&#010;More information about translated word"></a>';
			shtml +='</td>';
			shtml +='<td width="18" valign="top">';
			shtml +='<a href="#" onclick=openModal("msg.asp?type=6&OID='+oid+'&iFront='+ifront+'&toall=0&sid=0&tid=1",300,500);>';
			shtml +='<img src="images/edit.gif" alt="'+GetUnicodeFromAsci("Rastkrdnewey iem uSeye",0)+'&#010;Edit this word" border="0">';
			shtml +='</a>';
			shtml +='</td>';			
		}	
		else
		{
			shtml +='<td width="18" valign="top">';			
			shtml +='<a href="#" onclick=openModal("eFerheng_Words_Description.asp?Table=2&Mode=0&iFront='+ifront+'&WID='+kid+'&OID='+kid+'",document.body.clientHeight,document.body.clientWidth);><img border="0" src="images/xor.gif" alt="'+GetUnicodeFromAsci("zanyaryy zortr derbarey uSe wergYRdraweke",0)+'&#010;More information about translated word"></a>';
			shtml +='</td>';			
		}
		shtml +='<td style="padding-left:1;padding-right:1;"><textarea name="tdRedult" ';
		shtml +='style="font-weight:bold;color:red;background-color:#fefff6;border:none;padding:2;" readonly rows="2" cols="30">';
		if(lng2==1)
		{
			shtml +=GetUnicodeFromAsci(words.options[words.options.selectedIndex].otherword,0);
		}
		else
		{
			shtml +=words.options[words.options.selectedIndex].otherword;
		}
		shtml +='</textarea></td>';
		shtml +='<td width="18" align="center" valign="top">';			
		shtml +='<img name="cmdCopy" onclick="CopyResult();" src="images/copy.gif" style="cursor:hand;" alt="'+GetUnicodeFromAsci("kopykrdny iencameke",0)+'&#010;Copy Result" border="0">';
		shtml +='</td>';
		shtml +='</tr>';
		shtml +='</table>';	
		trres.innerHTML=shtml;	
	}
} 
function CopyResult()
{
	document.all.tdRedult.focus();
	document.all.tdRedult.select();
	document.execCommand('Copy');
	document.all.tdRedult.focus();
	document.all.tdRedult.select();
	document.execCommand('Copy');
}
function KopyWordToFind(words)
{
	document.all.hidKurdishID.value = words.options[words.options.selectedIndex].value;
	if(document.all.lstLanguageOption==null)
	{
		document.all.txtFind.value=GetUnicodeFromAsci(words.options[words.options.selectedIndex].f,0);
	}
	else
	{
		if(document.all.lstLanguageOption.value==1)
		{
			document.all.txtFind.value=GetUnicodeFromAsci(words.options[words.options.selectedIndex].f,0);
		}
		else
		{
			document.all.txtFind.value=words.options[words.options.selectedIndex].f;
		}
	}
}
function DerbareyEme(ifront)
{
	openModal('eFerheng_About_As.asp?iFront='+ifront,450,600);	
}
function SelectFindbox()
{
	if(document.all.hidSelect.value==0)
	{
		document.onselectstart=new Function ("return false");
	}
	else
	{
		document.onselectstart=new Function ("return true");
	}	
}
function CopyUserLanguage(ch)
{
	if(document.all[ch].checked==true)
	{
		document.all['hid'+ch].value=1;
	}
	else
	{
		document.all['hid'+ch].value=0;
	}
}
function ShowStat()
{
	if(document.all.checkSwitch.checked ==true)
	{
		document.all.txtSwitch.value=1;
	}
	else
	{
		document.all.txtSwitch.value=0;
	}
	SubmitForm();
}
function IsChecked(check, hidden)
{
	if(check.checked ==true)
	{
		hidden.value=1;
	}
	else
	{
		hidden.value=0;
	}
	PleaseWait();
	frmFerheng.submit();
}
function IsChecked2(check, hidden)
{
	if(check.checked ==true)
	{
		hidden.value=1;
	}
	else
	{
		hidden.value=0;
	}	
}
function ShowAllLanguagesInAdminPage()
{
	if(document.all.checkShowAllLanguages.checked ==true)
	{
		document.all.txtShowAllLanguages.value=1;
	}
	else
	{
		document.all.txtShowAllLanguages.value=0;
	}
	frmFerheng.submit();
}
var seconds1 ="";
function RefreshPage()
{
	var Digital=new Date();
	var hours=Digital.getHours();
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();
	var dn=GetUnicodeFromAsci("pYS nyweRo",0);
	if(seconds1 == "" || seconds1==0)
	{
		seconds1 = seconds-1;
	}
		
	else
	{
		seconds1 = seconds1;
	}				
	if (hours>12){
	dn=GetUnicodeFromAsci("paS nyweRo",0);
	hours=hours-12;
	}
	if (hours==0)
	hours=12;
	if (minutes<=9)
	minutes="0"+minutes;
	if (seconds<=9)
	seconds="0"+seconds		;
	myclock=hours+":"+minutes+":"+seconds+" "+dn;
	document.all.spnClock.innerText = myclock;
	setTimeout("RefreshPage()",1000);
	if(seconds1 == seconds)
	{
		frmFerheng.submit();
	}
}
function SwitchBothLanguages(l1,l2)
{
	var lng1 = document.all.lstZman01;		
	var lng2 = document.all.lstZman02;
	lng1.options[lng1.options.length] = new Option('',l2);
	lng2.options[lng2.options.length] = new Option('',l1);
	for(i=0;i<=lng1.options.length-1;i++)
	{
		if(lng1.options[i].value ==l2)
		{
			lng1.options[i].selected=true;
		}
		else
		{
			lng1.options[i].selected=false;
		}
	}		
	for(j=0;j<=lng2.options.length-1;j++)
	{
		if(lng2.options[j].value ==l1)
		{
			lng2.options[j].selected=true;
		}
		else
		{
			lng2.options[j].selected=false;
		}
	}	
}
function SwitchLanguage()
{
	var iz01 = document.all.lstZman01.value;
	switch (parseInt(iz01))
	{
		case 1: //Sorani
		{
			if(document.all.hidChar.value !="i")
			{
				document.all.lstArabic.selectedIndex=0;
				document.all.lstSlavic.selectedIndex=0;
				document.all.hidChar.value="i";
				document.all.hidArChar.value=0;
			}				
			break;
		}
		case 3: //Erebi
		{
			if(document.all.lstArabic.value=="ii")
			{
				document.all.lstArabic.selectedIndex=2;
				document.all.hidChar.value=document.all.lstArabic.value;
				document.all.hidArChar.value=1575;
			}				
			break;
		}
		case 4: //Farsi
		{
			if(document.all.lstArabic.value=="ii")
			{
				document.all.lstArabic.selectedIndex=2;
				document.all.hidChar.value=document.all.lstArabic.value;
				document.all.hidArChar.value=1575;
			}				
			break;
		}
		case 24: //Badini
		{
			if(document.all.lstArabic.value=="ii")
			{
				document.all.lstArabic.selectedIndex=1;
				document.all.hidChar.value=document.all.lstArabic.value;
				document.all.hidArChar.value=1574;
			}				
			break;
		}
		case 14: //Hewrami
		{
			if(document.all.lstArabic.value=="ii")
			{
				document.all.lstArabic.selectedIndex=1;
				document.all.hidChar.value=document.all.lstArabic.value;
				document.all.hidArChar.value=1574;
			}				
			break;
		}
		case 15: //Rusi
		{
			if(document.all.lstSlavic.value=="ii")
			{
				document.all.lstSlavic.selectedIndex=1;
				document.all.hidChar.value=document.all.lstSlavic.value;
				document.all.hidArChar.value=1040;
			}				
			break;
		}
		default:
		{
			if(document.all.hidChar.value !="a")
			{
				document.all.lstArabic.selectedIndex=0;
				document.all.lstSlavic.selectedIndex=0;
				document.all.hidChar.value="a";
				document.all.hidArChar.value=0;
			}
		}
	}
	SubmitForm();
}
function SubmitForm()
{
	if(document.all.divFerheng !=null)
	{
		document.all.divFerheng.scrollTop = 0;
	}
	PleaseWait();
	frmFerheng.submit();	
}
function PleaseWait()
{
	document.all.pleasewait2.style.display='block';
	var objDiv = document.all.divpleasewait;
	if(objDiv!=null)	
	{
		//DisableControls(1);
		/*var sh = document.body.clientHeight - objDiv.style.height.replace('px','');;
		sh = sh /2;
		objDiv.style.width = 400;
		objDiv.style.height = 55;		
		objDiv.runtimeStyle.left = sh;
		objDiv.runtimeStyle.top = 5;						
		*/
		objDiv.runtimeStyle.visibility='visible';
		//DisableControls(0);
	}
}
function DisableControls(iflag)
{
	var i=0;
	if(iflag==1)
	{
		for(i=0;i<document.all.length;i++)
		{
			document.all[i].disabled = true;
		}
	}
	else
	{
		for(i=0;i<document.all.length;i++)
		{
			document.all[i].disabled = false;
		}
	}
}
function openModal(lnk,h,w)
{
	window.showModalDialog(lnk,"objModal","dialogHeight: "+h+"px; dialogWidth: "+w+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
}
function ShowKeyboard()
{
	var objDiv = document.all.divKeyboard;
	if(objDiv!=null)	
	{		
		objDiv.style.width = 300;
		objDiv.style.height = 100;		
		objDiv.runtimeStyle.left = 1;
		objDiv.runtimeStyle.top = 1;		
		objDiv.runtimeStyle.visibility='visible';							
		document.all.txtKeyboard.value = '1';
	}
}
function CloseKeyboard()
{
	var objDiv = document.all.divKeyboard;
	if(objDiv!=null)	
	{	
		objDiv.runtimeStyle.visibility='';	
		document.all.txtKeyboard.value = '0';		
		if(document.all[document.all.hidTextbox.value]!=null)
		{
			document.all[document.all.hidTextbox.value].focus();
		}
	}
}
function KeyboardClicked()
{
	if(document.all.txtKeyboard.value == '1')
	{
		ShowKeyboard();
	}
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
function LoadCookie(obj,img)
{
	var list = document.all['lst'+obj];
	if (parseInt(getCookie(obj)) > 0) 
	{		
		for(i=0;i<=list.length-1;i++)
		{
			if(list.options[i].value==parseInt(getCookie(obj)))
			{
				list.options[i].selected=true;
				if(document.all['img'+obj]!=null)
				{
					document.all['img'+obj].src='images/'+list.options[i].value+'.gif';
				}
			}
		}
	}
	else
	{
		for(i=0;i<=list.length-1;i++)
		{
			if(list.options[i].value==1)
			{
				list.options[i].selected=true;
				if(document.all['img'+obj]!=null)
				{
					document.all['img'+obj].src='images/'+img+'.gif';
				}
			}
		}
	}		
}
function openWindow(mypage,myname,w,h,scroll,pos)
{

	var win=null;
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
var iFlags = new Array (1,2,3,6,7,8,10,11,12,15,37,16,17,18,23,27,28,29,30,1,31,32,33,34,35,36);
function LoadFlags()
{
	var flagPath = "images\\";		
	var sFlags = "";
	for(i=0;i<iFlags.length;i++)
	{			
		sFlags+= "<img width='20' height='14' name='Flag_"+i+"' src='"+flagPath+""+iFlags[i]+".gif' style='filter:alpha(opacity=15);border:1 outset;'>&nbsp;";			
	}
	document.all.divFlags.innerHTML = sFlags;
}
function playFlags()
{
	var iSecond;
	var iDate = new Date();		
	iSecond = iDate.getSeconds();
	for(s=0;s<iFlags.length;s++)
	{
		if(iSecond==s || (iSecond / 2) == s || (iSecond / 3) == s)
		{
			document.all['Flag_'+s].style.filter='alpha(opacity=100)';
			document.all['Flag_'+s].style.borderColor='#dee3e7';
		}		
		else
		{
			document.all['Flag_'+s].style.filter='alpha(opacity=15)';
			document.all['Flag_'+s].style.borderColor='';
		}
	}
	window.setTimeout('playFlags()',1000);
}
function GetAutoUfA(check, txt)
{
	if(check.checked==true)
	{
		txt.style.direction='rtl';
		txt.focus();
		txt.value=GetUnicodeFromAsci(txt.value,0);
	}
}
function GetAutoUfA2(input, output)
{	
	output.value=GetUnicodeFromAsci(input.value,0);	
}

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e)
{
	var ch = true;
	var returnval=emailfilter.test(e.value)
	if (returnval==false)
	{
		alert(GetUnicodeFromAsci('tkaye iy-mYLeket Rastbkerewe.',0)+"\nPlease enter a valid email address.")
		e.select()
		ch = false;
	}
	return ch;
}
function CapitalizeAll(obj) {
	if(obj!=null)
	{
        val = obj.value.toLowerCase();
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
        	newVal += val[c].substring(0,1).toUpperCase() +
			val[c].substring(1,val[c].length) + ' ';
        }
        obj.value = newVal;
	}
}
function Capitalize(obj) {
	if(obj!=null)
	{
        val = obj.value.toLowerCase();
        newVal = '';
       	newVal = val.replace(val.substring(0,1), val.substring(0,1).toUpperCase());        
        obj.value = newVal;
	}
}
function UpperCase(obj)
{
	if(obj!=null)
	{
		val = obj.value;
		obj.value = val.toUpperCase();
	}
}
function LowerCase(obj)
{
	if(obj!=null)
	{
		val = obj.value;
		obj.value = val.toLowerCase();
	}
}
