
function CheckMailFaxPhone(source,argument)
{
	if(document.getElementById("txtFax").value=="" 
	   && document.getElementById("txtPhone").value==""
	   && document.getElementById("EmailTB").value=="")
		argument.IsValid=false;
	else	
		argument.IsValid=true;
}

function CheckPhonesFax(source,argument)
{
	if(document.getElementById("txtFax").value=="" 
	   && document.getElementById("txtPhone2").value=="" 
	   && document.getElementById("txtPhone").value=="")
		argument.IsValid=false;
	else	
		argument.IsValid=true
}

function CheckCompanyName(source,argument)
{
	if(document.getElementById("NameHebrew").value=="" 
	   && document.getElementById("NameEnglish").value=="")
		argument.IsValid=false;
	else	
		argument.IsValid=true
}

function CheckAgreement(source,argument)
{
	if(document.getElementById("chkAgreement").checked)
		argument.IsValid=true;
	else	
		argument.IsValid=false;
}

function CheckConnection(source,argument)
{
	if(document.getElementById("txtFax").value=="" && document.getElementById("txtMobile").value=="" && document.getElementById("txtPhone").value=="")
		argument.IsValid=false;
	else	
		argument.IsValid=true;
}

function CheckMinAmount(source,argument)
{
	if(document.getElementById("txtAmountToDeposit").value=="")
		args.IsValid = false;
	else
	{
		var str = new String();
		var isN = true;
		var i;
		
		str = document.getElementById("txtAmountToDeposit").value;
		for(i=0;i<str.length;i++)
		{
			if(str.charAt(i)<'0' || str.charAt(i)>'9')
			{
				isN = false;
			}
		}
		if(isN == false)
			args.IsValid = false;
		else
			if(parseFloat(document.getElementById("txtAmountToDeposit").value)<300)	
				args.IsValid = false;	
	}
}

function CheckRadioExclusive (source,args)
{
	var rb0 = document.getElementById('RbExclusive_0');
	var rb1 = document.getElementById('RbExclusive_1');
	
	if (rb0.checked == false && rb1.checked == false)
		args.IsValid=false;
	else
		args.IsValid=true;
}

function checkNumber(n)
{
	var NumberExp=/^0\d{1,2}-\d{7}$/ ;
				
	if(n == '') return true;
		
	var isGoogNumber=NumberExp.test(n);
	return isGoogNumber;
}

function checkDigits(d)
{
	var DigitsExp=/^\d{8,16}$/;	// 8-16		
	///var DigitsExp=/^(\d{8}|\d{16})$/; //8 or 16
	if(d == '') return true;
		
	var isGoogDigits=DigitsExp.test(d);
	return isGoogDigits;
}

function checkCVV(d)
{
 
	var DigitsExp=/^\d{3}$/;	// 3		
	///var DigitsExp=/^(\d{8}|\d{16})$/; //8 or 16
	if(d == '') return true;
		
	var isGoogDigits=DigitsExp.test(d);
	return isGoogDigits;
}

function checkTZ(d)
{

	var DigitsExp=/^\d{8,9}$/;	// 9		
	if(d == '') return true;
		
	var isGoogDigits=DigitsExp.test(d);
	return isGoogDigits;
}

function checkEmail(e)
{
	var MailExp=/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ ;
	var isGoogMail=MailExp.test(e) ;
	return isGoogMail;
}

function checkUrl(u)
{
	var UrlExp= /^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?$/;
	var isGoogUrl=UrlExp.test(u) ;
	return isGoogUrl;
}


// Use onkeydown Event
function MaxLength(value,maxValue)
{
	// Exp' : <textArea onkeydown="return MaxLength(this.value,310)" />
	return(value.length<=maxValue);
}

// Use onpaste Event
function MaxLengthPaste(value,maxValue)
{
	// Exp' : <textArea onpaste="return MaxLength(this.value,310)" />
	var TotalLength = (value.length+window.clipboardData.getData("Text").length);
	var isOk = (TotalLength<=maxValue);
	if(!isOk)
		alert('לא ניתן לכתוב מעל ל '+maxValue+' תווים! כרגע יש '+TotalLength+' תווים ');
	return isOk
}

// remark: set the property 'ControlToValidate' value to be the combo name
function CmbRequired(source,argument)
{
	var combo = document.getElementById(source.controltovalidate);
	argument.IsValid = (!(combo.options[combo.selectedIndex].value.toString() == "-1"));
}

// remark: add property 'GroupName' and set his value to be the radio Group name
function RadioGroupRequired(source,argument)
{
	/* Exp' : <asp:CustomValidator ID="vCJobExpirationDate" Runat="server" Display="Dynamic" 
												CssClass="T12 B Red"
												ClientValidationFunction="RadioGroupRequired"
												ErrorMessage="בחר אחד מהאפשרויות"
												GroupName="rJobExpirationDate">
												בחר אחד מהאפשרויות
			  </asp:CustomValidator>
	*/
	
	var rArr = document.getElementsByName(source.GroupName);
	var i;
	
	argument.IsValid = false;
	for(i=0;i<rArr.length;i++)
		if(rArr[i].checked)
		{
			argument.IsValid = true;
			break;
		}
}

// remark: add property 'GroupName' and set his value to be the name of all the inputs text you want to check splitted by ','
function TextGroupRequired(source,argument)
{
	/* Exp' : <asp:CustomValidator ID="vCTextGroup" Runat="server" Display="Dynamic" 
												CssClass="T12 B Red"
												ClientValidationFunction="TextGroupRequired"
												ErrorMessage="בחר אחד מהאפשרויות - טלפון,פקס או אימייל"
												GroupName="txtPhone,txtFax,txtEmail">
												בחר אחד מהאפשרויות - טלפון,פקס או אימייל
			  </asp:CustomValidator>
							
	*/
	var ArrNames = source.GroupName.toString().split(',');
	var i,Counter=0; // counter all the inputs in the group that has some value(not empty) 
	
	argument.IsValid = false;
	
	for(i=0;i<ArrNames.length;i++)
		if(document.getElementById(ArrNames[i]).value != "")
			Counter++;
	argument.IsValid = (Counter > 0);	
}

// check the search engine values - all requiered - category,type,region
function RequireEngineValues(source,argument)
{
	if(
			($('input:hidden[@id="hdnCategoriesIDs"]').val()) == ""
		||
			($('input:hidden[@id="hdnCitiesIDs"]').val()) == ""
		||
			($('input:hidden[@id="hdnTypesIDs"]').val()) == ""
	)
	argument.IsValid=false;
}

function CheckExistsEmail(email)
{
	/// Res :  -1 = email not valid
	///			0 = email Not Exists
	///			1 = email Exists	
	var QRST = "/Employer/EmployerActions.aspx?action=CheckMail&e="+email;			
	var Res = parseInt($.ajax({url:QRST,async: false}).responseText);
	return (Res == 1 || Res == 2); // return true only if the email Exists (private user or company user)
}

function CheckExistsEmailOwner(email)
{
	/// Res :  -1 = email not valid
	///			0 = email Not Exists
	///			1 = email Exists - private user
	///			2 = email Exists - company user
	var QRST = "/Employer/EmployerActions.aspx?action=CheckExistsEmailOwner&e="+email;			
	var Res = parseInt($.ajax({url:QRST,async: false}).responseText);
	return Res;
}