
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)
{         
	 if(d == '') return true;

	if (!(d.length == 9))
        return false;

            
    /*
        Formula Description:
        --------------------
        1. let's say for example that my number id is                      ==> | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
        2. we set Array like CheckTZIndex with values like                      ==> | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 |
        3. than we multiply every nums in id with nums in Array            ==> | 1 | 4 | 3 | 8 | 5 |12 | 7 |16 | 9 |
        4. If we have One of The Values in the Array big then 9 we plus them ->| 1 | 4 | 3 | 8 | 5 | 3 | 7 | 7 | 9 |
        5. then we sum all the value in the  Array                         ==> | 1 | 4 | 3 | 8 | 5 | 3 | 7 | 7 | 9 | == 47
        6. if the sum value is not sum % 10 = 0 then the id num is Rong 
    */
    var TZID = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
    //Extract Number From String to a Array
    for(var i=0; i<d.length; i++)
    {
        var n = d.substring(i,i+1);
        if(n=="1"||n=="2"||n=="3"||n=="4"||n=="5"||n=="6"||n=="7"||n=="8"||n=="9"||n=="0")
            TZID[i] = parseInt(n);
        else
            return false;
    }   
    var CheckTZIndex = new Array(1, 2, 1, 2, 1, 2, 1, 2, 1); //Set value to multiply
    var TzSum = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);  // Set Array To  plus Values in Array
    var Sum = 0; //Set parm For Sum them All
    for (var i = 0; i < 9; i++) 
    {
        //Step 3  multiply     
        //alert(d[i]);                       
        TzSum[i] = TZID[i] * parseInt(CheckTZIndex[i]);   
        // alert(parseInt(d[i])) ;                       
    }
    for (var i = 0; i < 9; i++) 
    {
        //Step 4  If big then 9 Plus 
        if (TzSum[i] > 9) 
        {
            var num = 0;
            var ones = 0;
            var tens = 0;
            num = parseInt(TzSum[i]);
            ones = parseInt(num % 10);                    
            num = num / 10;
            tens = parseInt(num);                    
            TzSum[i] = tens + ones;
        }                
        Sum = parseInt(Sum) + parseInt(TzSum[i]);//Sum The Result Array to one Parm               
    }                       
    //step  6. If SUm Modol(%) 10 is Not zero  
    if (Sum % 10 != 0) 
    {
        return false;
    }
    else
    {
        return true;
    }                                                  
}

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;
}
