/*
	script take care of Input fields
	01/04/03 Shay Lapid
*/
function isNetScapeNavigator()
{
	return navigator.appName.toLowerCase()=='netscape' ;
}

function Input(oInput)
{
//onerror=function (sError,sURL,iLine){	return ClassException('Input',sError,sURL,iLine); }
var iMaxSize;
this.iMaxSize=iMaxSize;
oInput.iMaxSize=iMaxSize;
oInput.AddToPosition=AddToPosition;
this.AddToPosition=AddToPosition;

oInput.BlockHebChar=BlockHebChar;
this.BlockNonHebChar=BlockNonHebChar;
oInput.BlockNonHebChar=BlockNonHebChar;
this.BlockHebChar=BlockHebChar;
oInput.BlockNonEnglishChar=BlockNonEnglishChar;
this.BlockNonEnglishChar=BlockNonEnglishChar;
oInput.BlockNonNumericChar=BlockNonNumericChar;
this.BlockNonNumericChar=BlockNonNumericChar;
this.BlockNonFloatChar=BlockNonFloatChar;
oInput.BlockNonFloatChar=BlockNonFloatChar;	
oInput.BlockCR=BlockCR;
this.BlockCR=BlockCR;
oInput.BlockNonPriceChar=BlockNonPriceChar;
this.BlockNonPriceChar=BlockNonPriceChar;
this.BlockNonEnglishNumericChar=BlockNonEnglishNumericChar;
oInput.BlockNonEnglishNumericChar=BlockNonEnglishNumericChar;	

this.Sort = Sort;
oInput.Sort = Sort;
this.FixUrl=FixUrl;
oInput.FixUrl=FixUrl;	
this.CheckEmail=CheckEmail;
oInput.CheckEmail=CheckEmail;	
this.getContentSize=getContentSize;
oInput.getContentSize=getContentSize;	
this.MaxLength=MaxLength;
oInput.MaxLength=MaxLength;	
this.CheckLength=CheckLength;
oInput.CheckLength=CheckLength;	
this.getObjectIndex=getObjectIndex;
oInput.getObjectIndex=getObjectIndex;	
this.Rename=Rename;
oInput.Rename=Rename;	
this.getDoubleItem=getDoubleItem;
oInput.getDoubleItem=getDoubleItem;	
this.Replace=Replace;
oInput.Replace=Replace;	
this.isEmpty=isEmpty;
oInput.isEmpty=isEmpty;	
this.DisableIsValid=DisableIsValid;
oInput.DisableIsValid=DisableIsValid;	

	function DisableIsValid(oArrEnable,oArrDisable,sClassEnable,sClassDisable)
	{
		var bState = oInput.checked;

		for (var i=0;i<oArrEnable.length;i++)
		{
			oArrEnable[i].disabled=bState;
			oArrEnable[i].className=!bState?sClassEnable:sClassDisable;
		}

		for (var i=0;i<oArrDisable.length;i++)
		{
			oArrDisable[i].disabled=!bState;
			oArrDisable[i].className=bState?sClassEnable:sClassDisable;
		}						
	}


	function isEmpty()
	{
		for (var i=0;i<oInput.value.length;i++)
			if(oInput.value.charAt(i)!=' ')
				return false;
		return true;
	}
	function getDoubleItem()
	{
		var arrMyList = new Array() ;
		var counter ;
		for (counter = 0; counter < oInput.length-1 ; counter++)
			if (!arrMyList[oInput[counter].value])
				arrMyList[oInput[counter].value] = 1 ; 
			else
				return counter ;
		return null ;
	}

	function getObjectIndex(oArr)
	{
		var i=0;
		for (i=0;i<oArr.length;i++)
		{ 
			if (oInput==oArr[i])
				return i;
		}    
		return null;

	}

	function MaxLength(iMaxLength)
	{
		oInput.iMaxSize=iMaxLength-1;
		oInput.onkeypress=ConCat;
	}
	
	function ConCat()
	{
		if (oInput.iMaxSize<getContentSize())
		{
				oInput.innerText=oInput.innerText.substring(0,oInput.iMaxSize);
				//alert('less then' + (oInput.iMaxSize + 1) + ' chars')
		}
	}
	
	function CheckLength(iSize)
	{
		var arr=oInput.value.split(' ');
		
		for (i=0;i<arr.length;i++)
			if (arr[i].length>iSize)
				return false;
		return true;
	}	

	function Rename(sNewRadioName)
	{
		var oParent=oInput.parentNode;
		var oClone=document.createElement('<INPUT name="' + sNewRadioName + '">');
		oClone.type=oInput.type;
		oClone.onclick=oInput.onclick;
		oClone.value=oInput.value;
		var bChecked=oInput.checked;
		oParent.removeChild(oInput);
		oParent.appendChild(oClone);
		oClone.checked=bChecked;
	}

	function getContentSize()
	{
	return getContent().length;
	}
	
	function getContent()
	{
	if (!oInput.value)
		return oInput.innerText;
	else
		return oInput.value;
	}
	
	function CheckEmail()
	{
		return (oInput.value.indexOf("@")> 1 && oInput.value.lastIndexOf(".") > oInput.value.indexOf("@") + 2 );
	}

	function FixUrl()
	{
		if (oInput.value.indexOf("mailto:")!=-1 || oInput.value.indexOf("http://")!=-1) return ;
		if (oInput.value.indexOf("@")!=-1)
			oInput.value = "mailto:" + oInput.value
		else
			if (oInput.value.indexOf("www")!=-1)
				if (oInput.value.indexOf("http")==-1)
					oInput.value = "http://" + oInput.value
	}	
	
	function AddToPosition(sText)
	{
		oInput.focus();
		document.selection.createRange().text=sText;
	}
	
	function BlockCR(e) 
	{
		var PressedKey = getKeyCode(e);	
		
		if (PressedKey==13) 
			if (!isNetScapeNavigator()) window.event.returnValue = 0;
	}

	function BlockNonHebChar(e) 
	{
		var PressedKey = getKeyCode(e);			
		if (!((PressedKey>=1488) && (PressedKey<=1514)) || !PressedKey==39) 
			if (!isNetScapeNavigator()) window.event.returnValue = 0;
	}
	function BlockNonEnglishNumericChar(e) 
	{
		var PressedKey = getKeyCode(e);			
		if (!(
			(PressedKey>=97 && PressedKey<=122) || 
			(PressedKey>=48 && PressedKey<=57) || 
			(PressedKey==45 ) || 
			(PressedKey==95) || 
			(PressedKey>=65 && PressedKey<=90)) 
			)
			if (!isNetScapeNavigator()) window.event.returnValue = 0;
	}
	function BlockHebChar(e) 
	{
		var PressedKey = getKeyCode(e);		
		if ((PressedKey>=1488) && (PressedKey<=1514) ) 
			if (!isNetScapeNavigator()) window.event.returnValue = 0;

	}
	function getKeyCode(e)
	{
		return isNetScapeNavigator()?  e.which : window.event.keyCode;
	}
	function BlockNonNumericChar(e) 
	{
		var PressedKey = getKeyCode(e);		
		if (!(PressedKey>=48 && PressedKey<=57))
			if (!isNetScapeNavigator())  window.event.returnValue = 0;
	}
	function BlockNonFloatChar(e) 
	{
		var PressedKey = getKeyCode(e);		
		if (!(PressedKey>=46 && PressedKey<=57))
			if (!isNetScapeNavigator())  window.event.returnValue = 0;
	}
	function BlockNonPriceChar(e) 
	{
		var PressedKey = getKeyCode(e);		
		if (!(
			   (PressedKey>=48 && PressedKey<=57) || 
			    PressedKey==46)
			  )
			if (!isNetScapeNavigator())  window.event.returnValue = 0;
	}
	
	function BlockNonEnglishChar(e) 
	{
		var PressedKey = getKeyCode(e);						
		if (!(
			(PressedKey>=97 && PressedKey<=122) || 
			(PressedKey>=65 && PressedKey<=90)) 
			)
			if (!isNetScapeNavigator()) window.event.returnValue = 0;
	}
	
	function Replace(sBefore,sAfter)
	{
		var oRE			= new RegExp(sBefore,'g');
		oInput.value	= oInput.value.replace(oRE,sAfter);
	}
	
	function Sort(ArrInput, IsCaseSensitive)
	{
		var arrSort = new Array(ArrInput.length);
		var sInput
		for (i = 0; i < arrSort.length; ++i)
		{
			sInput = ArrInput[i].value
			if (IsCaseSensitive)
				arrSort[i] = sInput;
			else
				arrSort[i] = sInput.toLowerCase();

		}

		arrSort = arrSort.sort();

		var index = 0;
		for (i = 0; i < arrSort.length; ++i)
			for (j = 0; j < arrSort.length; ++j)
			{
				sInput = ArrInput[j].value;
				if (!IsCaseSensitive)
					sInput = sInput.toLowerCase();
				if (arrSort[i] == sInput)
					oInput[j].value = ++index;
			}
	}	
	
}

function ChangeSecurityQuestion(type)
				{
					switch(type)
					{
						case 'nanaList':						
							document.getElementById('containerNanaSecurityQuestion').style.display = '';
							document.getElementById('containerUserSecurityQuestion').style.display = 'none';
							document.getElementById('SecurityQuestionType').value = 1;
							break;
						case 'userQ':						
							document.getElementById('containerNanaSecurityQuestion').style.display = 'none';
							document.getElementById('containerUserSecurityQuestion').style.display = '';
							document.getElementById('SecurityQuestionType').value = 2;
							break;
					}
				}
				
				function CheckUserName(name)
				{		
				    					
					switch(name)
					{
						case 'UserName':
							if(document.getElementById('UserName').value=='')
							{
								alert('יש להזין שם משתמש')
								return;
							}
							document.getElementById('ifrAlternateUserNames').src='Form.asp?s=100&pid=48&UserName='+document.getElementById('UserName').value;	
							document.getElementById("takenNick").style.display="inline-block";
							break;
						case 'NickName':
							if(document.getElementById('NickName').value=='')
							{
								alert('יש להזין כינוי')
								return;
							}
							
							document.getElementById('ifrAlternateUserNames').src='Form.asp?s=101&pid=48&UserName='+document.getElementById('NickName').value;	
							break;
						case 'ChatName':
							if(document.getElementById('ChatName').value=='')
							{
								alert('יש להזין כינוי')
								return;
							}
							
							document.getElementById('ifrAlternateUserNames').src='Form.asp?s=101&pid=48&UserName='+document.getElementById('ChatName').value;	
							break;	
					}					
				}	
				

function RevealUserOptions()
{
	var nome = document.getElementById("userOptions");
	
	if (nome.style.display=="block")
	{	
		document.getElementById("userOptions").style.display="none";
	}
	else
	nome.style.display="block";
}	
				
				
				
	function fCheckFields()
		{																
			var sError = '';
			var oInput=new Input(document.S2.Email);												 
			if((document.S2.Password.value.length) < 6)
			{
				sError='*הסיסמה חייבת להיות בעלת 6 תווים לכל הפחות.<br/>'
			}
			
			if (oInput.CheckEmail()!=true && document.S2.Email.value!=''){sError= sError + '*דואר אלקטרוני לא תקין.<br/>'}
			if(document.S2.UserName.value==''){sError= sError + '*יש למלא שם משתמש.<br/>'}
			if(!document.S2.chbTermsOfUse.checked){sError= sError + '*יש לאשר את התנאים לחברות במועדון.<br/>'}						
			if(sError!='')
			{
				alert("אנא בדוק את הפרטים שוב")
				sError='<b>אנא תקן את הדברים הבאים:</b><br/>' + sError ;
				return false;
			}
			
		}
		
			function TwistNShow()
				{
					var takanon = document.getElementById('rulesOfUsage');
					var secBlock = document.getElementById('securityBlock');
					var isCheckBox = document.getElementById('chbTermsOfUse');
					
					if (takanon.style.display == 'block' && isCheckBox.checked==true)
					{
						takanon.style.display = 'none';
						secBlock.style.display = 'block';
					}

				}
				
			function ShowTakanon()
			{
				var takanon = document.getElementById('rulesOfUsage');
				var secBlock = document.getElementById('securityBlock');
				
				if (takanon.style.display == 'none')
				{
						takanon.style.display = 'block';
						secBlock.style.display = 'none';
				}
				else
					takanon.style.display = 'none';
			}
			
			function RevealPass()
			{
				var passBox = document.getElementById('newUserPass');
				passBox.setAttribute('type','text');
				
			}
				