﻿var TotalCnt;
var myArray;
var alertTimerId = 0;
$(document).ready(
				function() {
				    var FeaturedCompany = $(".cssFeaturedCompany")[0];
				    if (FeaturedCompany != null) {
				        FeaturedCompany.innerHTML = "<img src='" + JJHMainURL + "images/featured_employers.jpg' style='border: none;' title='Featured Healthcare Companies'  width='147px' height='28px' />";
				    }

				    var cssJJHMainLogo = $(".cssJJHMainLogo")[0];
				    if (cssJJHMainLogo != null) {
				        cssJJHMainLogo.innerHTML = "<img src='" + JJHMainURL + "images/logo.jpg' runat='server' id='imghome' alt='JobJobHealth.com' width='225' height='59' border='0' style='margin-left: 8px; margin-top: 24px;' />";
				    }


				    var CompleteFeatureList = $(".FeatureImageResult");
				    if (CompleteFeatureList.length > 0) {
				        myArray = new Array();
				        myArray = CompleteFeatureList[0].value.split("|");
				        TotalCnt = myArray.length - 1;
				        alertTimerId = setTimeout("RandomPicker()", 1);
				    }
				});


function RandomPicker() {
    var ran_unrounded = Math.random() * TotalCnt;
    var ran_number = Math.floor(ran_unrounded);
    var TempCnt = 0;
    var stringAppend = "";
    for (var i = 0; i < 3; i++) {
        var indexfetch = ran_number + i;
        if (indexfetch <= TotalCnt) {
            stringAppend = stringAppend + myArray[indexfetch];
        }
        else {
            stringAppend = stringAppend + myArray[TempCnt];
            TempCnt++;
        }
    }
    $("#featured_logos").fadeOut('false', function() {
        $("#featured_logos").empty();
        $("#featured_logos").append(stringAppend);
        $("#featured_logos").fadeIn("slow");
        alertTimerId = setTimeout("RandomPicker()", 6560);
    });
}

function CreateSearchURLAndRedirect() {

    var val_keyword = document.getElementById('ctl00_ContentPlaceHolder1_txtKeyword').value;
    var val_Loc = document.getElementById('ctl00_ContentPlaceHolder1_txtLocation').value;


    if ((val_Loc == "city, state or zip code") && (val_keyword == "job title, keywords or company name")) {
        alert('Please enter the search criteria');
        return false;
    }
    if ((val_Loc == '')) {
        alert('Please enter city, state or zip code');
        return false;
    }
    else {
        var stringURLForKeyword = "";
        if ((val_keyword != null) && (val_keyword != "") && (val_keyword != "job title, keywords or company name")) {
            val_keyword = val_keyword.replace(',', ' ');
            val_keyword = val_keyword.replace('  ', ' ');
			stringURLForKeyword = "k-" + val_keyword.replace(/ /g, '-');
        }
        var stringURLForLocation = "";
        if ((val_Loc != null) && (val_Loc != "") && (val_Loc != "city, state or zip code")) {
			 val_Loc = val_Loc.replace(',', ' ');
            val_Loc = val_Loc.replace('  ', ' ');
            stringURLForLocation = "l-" + val_Loc.replace(/ /g, '-');
        }
        var MainURL = "";
        if ((stringURLForKeyword != null) && (stringURLForKeyword != "")) {
            MainURL = stringURLForKeyword;
        }
        if ((stringURLForLocation != null) && (stringURLForLocation != "")) {
            if ((MainURL != null) && (MainURL != "")) {
                MainURL = MainURL + "-" + stringURLForLocation;
            }
            else {
                MainURL = stringURLForLocation;
            }
        }
       // __doPostBack('ctl00$ContentPlaceHolder1$btnSearchJobs', '');
        window.location.href = MainURL + "-jobs.html";
        return false;
    }
}

$('.cssEnterKeyPress').keyup(function(e) {
    if (e.keyCode == 13) {
        CreateSearchURLAndRedirect();
    }
});


function textBoxOnBlur(elementRef) {
    var checkValue = window.clipboardData.getData("Text");
    var newValue = '';
    var SpecialChars = "<> ? / ~ ` ! @ # % ^ & * () {} [] ' : ;_+ = \\|";
    var char1 = '" ';
    SpecialChars = SpecialChars + char1;
    for (var i = 0; i < checkValue.length; i++) {
        var currentChar = checkValue.charAt(i);
        if (SpecialChars.indexOf(currentChar) == -1) {
            newValue += currentChar;
        }
    }
    elementRef.value = newValue;
    return false;
}

function GetQueryString() {
    var keyWord = null;
    var Location = null;
    var Radius = null;
    var EmpJobs = null;
    var QryString = "";

    if (document.getElementById('ctl00_ContentPlaceHolder1_txtKeyword').value.length > 0 && document.getElementById('ctl00_ContentPlaceHolder1_txtKeyword').value != 'job title, keywords or company name') {
        keyWord = document.getElementById('ctl00_ContentPlaceHolder1_txtKeyword').value;
        QryString = QryString + "/k-" + keyWord + "-jobs.html";
    }

    if (document.getElementById('ctl00_ContentPlaceHolder1_txtLocation').value.length > 0 && document.getElementById('ctl00_ContentPlaceHolder1_txtLocation').value != 'city, state or zip code') {
        Location = document.getElementById('ctl00_ContentPlaceHolder1_txtLocation').value;
        QryString = QryString + "/l-" + Location + "-jobs.html";
    }
    return QryString;
}

var defaultText = "job title, keywords or company name";

function WaterMarkForTitle(txt, evt) {
    if (txt.value.length == 0 && evt.type == "blur") {
        txt.style.color = "#2e89ee";
        txt.value = defaultText;
    }
    if (txt.value == defaultText && evt.type == "focus") {
        txt.style.color = "#2e89ee";
        txt.value = "";
    }
}


function WaterMarkForFocus(txt, evt) {

    if (evt.type == "focus") {
        txt.style.color = "#2e89ee";
        txt.value = "";
    }
}

var defaultText1 = "city, state or zip code";
function WaterMarkForLocation(txt, evt) {
    if (txt.value.length == 0 && evt.type == "blur") {
        txt.style.color = "#2e89ee";
        txt.value = defaultText1;
    }
    if (txt.value == defaultText1 && evt.type == "focus") {
        txt.style.color = "#2e89ee";
        txt.value = "";
    }
}
// capitalize the first letter of string
function caplize(ctl) {
    var a = document.getElementById(ctl.id).value;
    s = '';
    if (a.length > 0) {
        for (i = 0; i < a.length; i++) {
            if (a.charAt(i) == " ") {
                s = s + a.charAt(i).toLowerCase();
                s = s + a.charAt(++i).toUpperCase();
            }
            else {
                s = s + a.charAt(i).toLowerCase();
            }
        }
        s = s.charAt(0).toUpperCase() + s.slice(1);
        document.getElementById(ctl.id).value = s;
    }
}

function ConvertToLowerCase(ctl) {
    var a = document.getElementById(ctl.id).value;
    if (a.length > 0) {
        document.getElementById(ctl.id).value = a.toLowerCase();
    }
}





       
       

