﻿//This is the true scripts by JB king of scripts
//INDEX SEARCH FORM
//=================
//Jack's on effect
function chkFormiIndexSearch() {
	var doSubmit = true;
	//Submit If Form is OK
	if(doSubmit) {
		document.getElementById('IndexSearchFormLoading').className = "divOpen"; 
		document.getElementById('IndexSearchFormButton').className = "divContent"; 
		setTimeout("formiIndexSearchGO()",1000);
	}
	else {
		//formiIndexSearchError.className = "divOpen error";
	}
}

//Prepers the syntax to send to the search results
function formiIndexSearchGO(){
	//Index Values
	var indexCatIDS = '0';
	var elms =
		$('.Catcolomn input:checked');
	var result = true;
	elms.each
	(
	   function () {
		   var elm = $(this);
		   indexCatIDS += ","+elm.val();
		   
	   }
	);
	
	//Zone Values
	var ZoneIDS = '0';
	var elms =
		$('.zoneContainer input:checked');
	var result = true;
	elms.each
	(
	   function () {
		   var elm = $(this);
		   ZoneIDS += ","+elm.val();
		   
	   }
	);
	
	//Free Query
	var indexQ = document.getElementById("IndexQ").value;
	//alert(indexQ);
	if (indexQ == 'טקסט חופשי...') {
		indexQ = '';
	}

	location.href='/cmsIndexResults.asp?indexQ='+indexQ+'&indexCatIDS='+indexCatIDS+'&ZoneIDS='+ZoneIDS;
}

//CONTACT JOB
//===========
//validates the contact biz form
function validateContactJobForm() {
    var isFormValid = true;

	$('#errorNote').addClass("notDisplayed");
    //Step # 1 : Determine the Fields by reverse order.

	//Validate File
    if (!(isCVValid("contactFile"))) {
        isFormValid = false;
    }
	
    //Validate Email
    if (!(isEmailValid("contactEmail"))) {
        isFormValid = false;
    }
	
	//Validate Phone
    if (!(isNameValid("contactPhone", 1))) {
        isFormValid = false;
    }

    //Validate Last Name
    if (!(isNameValid("contactName", 1))) {
        isFormValid = false;
    }

    //Step # 2 : Determine display of notification and errors.
    if (isFormValid) {
        $('#contactSubmit')
        .hide();
        $('#ContactLoader')
        .show();
        sleep(500);
        return true;
    }
    else {
		$('#errorNote').removeClass("notDisplayed");
        return false;
    }
}
//CONTACT BIZ
//===========
//validates the contact biz form
function validateContactBizForm() {
    var isFormValid = true;
	$('#errorNote').addClass("notDisplayed");
    //Step # 1 : Determine the Fields by reverse order.

    //Validate Email
    if (!(isEmailValid("contactEmail"))) {
        isFormValid = false;
    }
	
	//Validate Phone
    if (!(isNameValid("contactPhone", 1))) {
        isFormValid = false;
    }
	
	//Validate Job
    if (!(isNameValid("contactJob", 1))) {
        isFormValid = false;
    }

    //Validate Last Name
    if (!(isNameValid("contactName", 1))) {
        isFormValid = false;
    }
	
	//Validate Company Name
    if (!(isNameValid("contactCompanyName", 1))) {
        isFormValid = false;
    }

    //Step # 2 : Determine display of notification and errors.
    if (isFormValid) {
        $('#contactSubmit')
        .hide();
        $('#ContactLoader')
        .show();
        sleep(500);
        return true;
    }
    else {
		$('#errorNote').removeClass("notDisplayed");
        return false;
    }
}
//FORM FUNCTIONS
//==============
//validates textbox field by the char length as a minimum 
//required fields
function isNameValid(id, charLength) {
    var jqueryId = "#" + id;
    if (document.getElementById(id).value.length > charLength) {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
    else {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
}
//Validates the email field
function isEmailValid(id) {
    var jqueryId = "#" + id;
    var filter = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+){1,4}$/;
    if (filter.test(document.getElementById(id).value)) {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
    else {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
}


//Validates for docx,doc and pdf
function isCVValid(id)
{
	var docxregex = /doc/g;
	var pdfregex = /pdf/g;
	var jqueryId = "#" + id;
    if ((!(docxregex.test($(jqueryId).val()))&&(!pdfregex.test($(jqueryId).val())))) {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
    else {
        $(jqueryId).removeClass("fieldError");
        return true;
    }

}

//validates that the check box has a non default value
function isCheckBoxValid(id) {
    var jqueryId = "#" + id;
    if ($(jqueryId).val() == "0") {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
    else {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
}

