﻿var UnicodeString = ' !"#$?،گ)(?+و-./۰۱۲۳۴۵۶۷۸۹:ك,=.؟@ِذ}ىُىلآ÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزيثبلاهتنمئدخحضقسفعرصطغظ<|>ّ';

function ResizeIFrame()
{
	try
	{
		if (window.parent) // has parent
		{
			ifobj = window.frameElement;
			if (ifobj) // iframe object exists
			{
				if (document.body.scrollHeight <= 5)
					ifobj.height=10;
				else	
					ifobj.height = document.body.scrollHeight;	
				if (document.body.scrollWidth <= 5)
					ifobj.width=200;
				else	
					ifobj.width = document.body.scrollWidth;
			}
		}
	}
	catch(err)
	{
		
	}
}


function CheckUnicode()
{
	var key = window.event.keyCode;
	if(key > 47 && key < 58) return true;
	if(key < 32)return true;
	if(key >= 128)
	{
		alert("تغيير دهيد ctrl+shift لطفا زبان صفحه کليد را با");
		return false;
	}
	editor.fireEvent("onfocus");
	if(editor.lang.toString()=="Fa")
	{
		window.event.keyCode = UnicodeString.charCodeAt(key-32);
		return true;
	}
	return true;
}

function KeyDown()
{
	if(window.event.shiftKey && window.event.ctrlKey)
	{
		editor = event.srcElement;
		if(editor.lang.toString() == "Fa")
			editor.lang = "En";
		else
			editor.lang = "Fa";
		editor.fireEvent("onfocus");
		return false;
	}
}

function KeyUp()
{ 
	if(window.event.keyCode == 13)
		return;
	editor = event.srcElement;
    str = editor.value;
    if(str.charAt(str.length-1)=="\n")
		if(editor.lang.toString()=="Fa") editor.dir = "rtl";
		else editor.dir = "ltr";
	else if(str == "")
		if(editor.lang.toString()=="Fa") editor.dir = "rtl";
		else editor.dir = "ltr";
}

function ShowLangStatus()
{
	editor = event.srcElement;
	str = "زبان جاري : "
	if(editor.lang.toString()=="Fa")
		str += "فارسي";
	else
		str += "انگليسي";
	window.status = str;
}

function ClearStatus()
{
	window.status='';
}

function Expand(ElementId)
{
  var elemSrc = document.getElementById(ElementId + "_i");
  var elemTR = document.getElementById(ElementId + "_tr");
  elemSrc.Expanded='false';
  elemSrc.src='../ImageGallery/SystemFiles/Images/Expand.gif';
  elemTR.style.display = 'none';
}

function Collaps(ElementId)
{
  var elemSrc = document.getElementById(ElementId + "_i");
  var elemTR = document.getElementById(ElementId + "_tr");
  elemSrc.Expanded='true';
  elemSrc.src='../ImageGallery/SystemFiles/Images/Collap.gif';
  elemTR.style.display = '';
}

function ExpandThisDiv(ElementId)
{
	var elemSrc = document.getElementById(ElementId + "_i");
	if (elemSrc == null) 
		return;
	if (elemSrc.Expanded=='true')
	{
		CookieSet(ElementId, "false");
		Expand(ElementId);
	}
	else
	{
		CookieSet(ElementId, "true");
		Collaps(ElementId);
	}
}

function ReadCookie(nameoftable)
{
	var expire = 8;
	if(GetCookie (nameoftable) == '')
	{
		var expDate = new Date();
		expDate.setTime( expDate.getTime() + (expire != 0 ? expire : 0 ) );
		document.cookie = nameoftable + "=" + escape( "false" ) + ( expire ? "; expires=" + expDate.toGMTString() + ";":	"") ;
	}
	if(GetCookie(nameoftable)!="true")
	{
		Expand(nameoftable);
	}
	else
	{
		Collaps(nameoftable);
	}
}

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  

	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) 
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	} 
	return '';
}

function CookieSet( name, value, expire)
{
      if( document.cookie.length > 4000 )
            window.alert( "Your cookie is getting close to 4k");
    var expDate = new Date();
    expDate.setTime( expDate.getTime() + (expire != 0 ? expire : 0 ) );
    document.cookie = name + "=" + escape( value ) + ( expire ? "; expires=" + expDate.toGMTString() + ";": "") ;
}

var popUpWin=0;
function popUpWindow(URLStr, Title, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed)
		popUpWin.close();
  }
  //popUpWin = open(URLStr, Title, 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin = open(URLStr, Title, 'toolbar=no,location=no,directories=no,status=no,menub ar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin = open(URLStr, Title, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin = open(URLStr, Title, 'scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function checkIt(evt)
{
	evt = (evt) ? evt : window.event;
	var ChCode = (evt.which) ? evt.which : evt.keyCode;
	if (editor.lang.toString()=="Fa")
	{
		if (ChCode == Key_A || ChCode == Key_S || ChCode == Key_D || ChCode == Key_Z || ChCode == Key_X || ChCode == Key_C)
		{
			window.event.keyCode = Key_Nothing;
			return true;
		}
		if (ChCode == Key_H || ChCode == Key_N || ChCode == Key_V)
			return true;
		if (ChCode > 64 && ChCode < 91 )
		{
			window.event.keyCode = Key_Nothing;
			alert("لطفا حروف بدون Shift و يا CapsLock وارد نمائيد");
			return false;
		}
		status = "";
	}
	return true;
}

function EditorCheckUnicode()
{
	var key = mce_editor_0.event.keyCode;
	if(key > 47 && key < 58) return true;
	if(key < 32)return true;
	if(key >= 128)
	{
		alert("تغيير دهيد EN لطفا زبان صفحه کليد را به");
		return false;
	}
	//editor.fireEvent("onfocus");
	//if(editor.lang.toString()=="Fa")
	//{
		mce_editor_0.event.keyCode = UnicodeString.charCodeAt(key-32);
		return true;
	//}
	return true;
}

function EditorKeyDown()
{
	if(window.event.shiftKey && window.event.ctrlKey)
	{
		editor = event.srcElement;
		if(editor.lang.toString() == "Fa")
			editor.lang = "En";
		else
			editor.lang = "Fa";
		editor.fireEvent("onfocus");
		return false;
	}
}

function EditorKeyUp()
{ 
	if(window.event.keyCode == 13)
		return;
	editor = event.srcElement;
    str = editor.value;
    if(str.charAt(str.length-1)=="\n")
		if(editor.lang.toString()=="Fa") editor.dir = "rtl";
		else editor.dir = "ltr";
	else if(str == "")
		if(editor.lang.toString()=="Fa") editor.dir = "rtl";
		else editor.dir = "ltr";
}

function EditorShowLangStatus()
{
	editor = event.srcElement;
	str = "زبان جاري : "
	if(editor.lang.toString()=="Fa")
		str += "فارسي";
	else
		str += "انگليسي";
	window.status = str;
}

function EditorClearStatus()
{
	window.status='';
}
