String.prototype.trim = function (){ return this.replace(/^\s+|\s+$/g,""); };

function HideHint()
{
	if (typeof(trVerify) == 'undefined' )
	{
		if (typeof(tdName) != 'undefined' )         tdName.title = '';
		if (typeof(tdEMail) != 'undefined' )        tdEMail.title = '';
		if (typeof(tdEMail) != 'undefined' )        tdEMail.title = '';
		if (typeof(tdVersion) != 'undefined' )      tdVersion.title = '';
		if (typeof(tdSerialNo) != 'undefined' )     tdSerialNo.title = '';
		if (typeof(tdPackageId) != 'undefined' )    tdPackageId.title = '';
		if (typeof(tdOrganization) != 'undefined' ) tdOrganization.title = '';
	}
}

//-----------------------------------------------------------------------------------------------------------------
var LangName = "FA";
var LangOrg  = "FA";
var BaseString = ' !"#$%،گ)(×+و-./۰۱۲۳۴۵۶۷۸۹:ک,=.؟@ِذ}ىُىلآ÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزیثبلاهتنمئدخحضقسفعرصطغظ<|>ّ';
function FarsiKey(e,Name_Org)
{
	var key;
	
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
 
	if (( key > 31 && key < 128) && (
		( LangName == "FA" && Name_Org == "Name" )||
		( LangOrg  == "FA" && Name_Org == "Org" ))
	   )
		if (window.event)
			window.event.keyCode = BaseString.charCodeAt(key-32);
		else if (e)
			e.which = BaseString.charCodeAt(key-32);
			
	return true;
}
//-----------------------------------------------------------------------------------------------------------------
function ChangeLang(e, Name_Org)
{
	e ? evt = e:evt = window.event;

	if ( evt.keyCode == 119 )  
	{
		if ( Name_Org == "Name" )
			LangName  = (LangName == "FA") ? "EN" : "FA"; 
		else
			LangOrg   = (LangOrg == "FA") ? "EN" : "FA"; 		
	}
	lblLangName.innerHTML = LangName ;
	lblLangOrg.innerHTML  = LangOrg ;
	return true;
}
//-----------------------------------------------------------------------------------------------------------------
function getAbsX(elt)
{
	return (elt.x) ? elt.x : getAbsPos(elt,"Left");
}
function getAbsY(elt)
{
	return (elt.y) ? elt.y : getAbsPos(elt,"Top");
}
function getAbsPos(elt,which)
{
	iPos = 0;
	while (elt != null)
	{
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}
//-----------------------------------------------------------------------------------------------------------------
function NumberKey(e)
{
	var key;
	layerHint.style.visibility = "hidden" ;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	if ( !(key >= 48 && key <= 57 || key == 32))   		
	{
	    if (window.event)
		    window.event.keyCode = 0 ;
	    else if (e)
		    e.which = 0 ;    
        var pos = GetCursorPosition() ;
        var Serial = document.all["txtSerialNo"] ;
		layerHint.style.left = getAbsX(Serial) + 2 + pos*8 + 'px';
		layerHint.style.top  = getAbsY(Serial) + 17 +'px';
		layerHint.style.visibility = "visible" ;
    }
	return true;
}
//-----------------------------------------------------------------------------------------------------------------
function CounterKey(e,x,n)
{
	var key;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	if ( key == 32 )
		return false;
		
	var pos = GetCursorPosition() ;
	if ( pos >= n )
	{
		document.getElementById(x).focus();
//		document.getElementById(x).select();
		if ( x == 'txtOrganization' )
		 	return false;
	}
 	return true;
}
//-----------------------------------------------------------------------------------------------------------------
function GetCursorPosition()
{
	var obj = document.activeElement ;
	var cur = document.selection.createRange() ;
	if (obj && cur)
	{
		var tr = obj.createTextRange() ;
		if (tr)
		{
			for ( var pos = 0 ; cur.compareEndPoints("StartToStart", tr) > 0 ; pos++ )
				tr.moveStart("character", 1) ;
			return pos ;
		}
	}
	return -1 ;
}
//-----------------------------------------------------------------------------------------------------------------
function CheckPage()
{
    window.event.returnValue = false ;     
    if ( document.all["txtSerialNo"].value != "" )
    if ( document.all["txtPackageId"].value != "" )
    if ( document.all["txtOrganization"].value != "" )
    if ( document.all["txtName"].value != "" )
    if ( document.all["txtEMail"].value != "" )
        window.event.returnValue = true ;
}
//-----------------------------------------------------------------------------------------------------------------
function CopyClipBoard()
{
    window.clipboardData.setData("Text",document.all["txtActivationKey"].value);
}
//-----------------------------------------------------------------------------------------------------------------
function CopyClipBoard3()
{
	str = document.all["txtActivationKey4"].value + document.all["txtActivationKey3"].value + document.all["txtActivationKey2"].value + document.all["txtActivationKey1"].value ;
    window.clipboardData.setData("Text",str);
}
//-----------------------------------------------------------------------------------------------------------------
function PasteClipBoard()
{
	var str = window.clipboardData.getData("Text");
	var reg = /[a-zA-Z_0-9%+@&*=]{4}/g;
	var matches = str.match(reg);

	if ( typeof (matches[0]) != "undefined" )	document.all["txtSerialNo1"].value = matches[0];
	if ( typeof (matches[1]) != "undefined" )	document.all["txtSerialNo2"].value = matches[1];
	if ( typeof (matches[2]) != "undefined" )	document.all["txtSerialNo3"].value = matches[2];
	if ( typeof (matches[3]) != "undefined" )	document.all["txtSerialNo4"].value = matches[3];
	event.returnValue = false;
}
//-----------------------------------------------------------------------------------------------------------------
function ChangeText(x,n)
{
	document.getElementById(x).value = document.getElementById(x).value.toUpperCase().replace(/\s*/g, "").substring(0,n);
}
