// function to set focus to the what box on load
function setFocus(){
	document.frmZip.q.focus();
}


//function to check if the what textbox is blank
function checkWhatFld(what, where)
{
	what.value = what.value.replace(/^\s+/, '');
	what.value = what.value.replace(/\s+$/, '');

    if(what.value == "" || what.value == "Please enter the keyword.")
    {
    	what.focus();
    	what.value = "Please enter the keyword.";
    	select_all(what);
    	return false;
    }

    var iChars = "!@#$%^&*()+_=[]\\\';./{}|\":<>?";

    for (var i = 0; i < where.value.length; i++) {
      	if (iChars.indexOf(where.value.charAt(i)) != -1) {
      		where.focus();
      		alert ("Special characters are not allowed in Where.");
      		return false;
      	}
	}
}

function select_all(thisFld)
{
	var Fld_val=eval("thisFld");
	//Fld_val.focus();
	//Fld_val.select();
}

// function to open print pop up
function show_popup(link){
	open(link,'bids', 'width=750,height=620,menubar=yes,status=no,resizable=no,location=no,toolbar=no, personalbar=no,scrollbars=yes');
}

//function to display and hide a section for eg: nearby cities, national chains, tags etc.
function showHideSection(section, obj)
{
    var display;
    display = document.getElementById(section).style.display;
    document.getElementById(section).style.display = (display=="") ? "none" : "";
    var nodes = obj.childNodes;
    node = nodes[0];
    var ta=document.createElement("textarea");
    if(display)
        ta.innerHTML = "&#171;&nbsp;close";
    else
        ta.innerHTML = "more&nbsp;&#187;";
    node.data = ta.value;
    obj.blur();
}

function showMore(id,more_element)
{
    var display;
    hght = document.getElementById(id).style.height;
    document.getElementById(id).style.height = (hght!="auto") ? "auto" : "32px";
    if(hght!="auto")
        more_element.innerHTML = "&#171;&nbsp;close";
    else
        more_element.innerHTML = "more&nbsp;&#187;";
    more_element.blur();
}

function setHeight(cnt)
{
    for(i=0;i<cnt;i++)
    {
		if(document.getElementById("box"+i))
		{
			document.getElementById("box"+i).style.display = "";
			if(document.getElementById("box"+i).offsetHeight > 35)
			{
				document.getElementById("more"+i).style.display = "";
				document.getElementById("box"+i).style.height = "32px";
			}
		}
    }

}

function goThere(rdurl) {
    location.href=rdurl;
    return false;
}

var allowdTag = new Array("IMG");

function isAllowdTag(node)
{
   for (var i = 0; i < allowdTag.length; i++)
   {
     if (node.tagName == allowdTag[i])
     {
		return true;
     }
   }
   return false;
}

function scanNodeForImages(parent)
{
	var nodes = parent.childNodes;
    for (var i = 0; i < nodes.length; i++)
    {
    	var node = nodes[i];

    	if(!isAllowdTag(node))
    	{
    		continue;
    	}

		if(node.width > 110)
		{
			node.width = 110;
			node.height = ( 110 / node.width ) * node.height;
    	}
		if(node.height > 75)
		{
			node.height  = 75;
			node.width = ( 75 * node.width ) / node.height;
    	}
    }
}

function resizeImage()
{
	var paras = $A(document.getElementsByClassName('thumb-image'));
	paras.each(function show(s){
		scanNodeForImages(s);
	});
}

function setPopularCity(city, domain)
{
	document.cookie = "where="+escape(city)
                         + ";path=/;domain=.zipcodez."+domain+";";
}

function debug(str, color)
{
	var div = document.createElement("div");
	var br = document.createElement("br");
	var txt = document.createTextNode(str);
	div.appendChild(txt);
	div.appendChild(br);
	document.body.appendChild(div);
	if(typeof color!=undefined)
	{
	  div.style.color = color;
	}
}

function searchJobs(domain, location_path){
	strKeyword = document.form1.jobfield.value.toLowerCase();
	strKeyword = escape(escape(strKeyword));
	strKeyword = strKeyword.replace(new RegExp(/\+/g), '%252b');
	strKeyword = strKeyword.replace(new RegExp(/\//g), '%252f');

	url = 'http://jobs.zipcodez.' + domain + location_path + 'job/' + strKeyword + '.htm';

	open(url, 'bids', '');
}


//function to check if the what textbox is blank
function checkJobFld(what, domain, location_path)
{
	what.value = what.value.replace(/^\s+/, '');
	what.value = what.value.replace(/\s+$/, '');

    if(what.value == "" || what.value == "Please enter the keyword.")
    {
    	what.focus();
    	what.value = "Please enter the keyword.";
    	select_all(what);
    	return false;
    }

    searchJobs(domain, location_path);
    return false;
}

