//
// this depends on jQuery lib
//

function getQuerystring(key, default_)
{
      if (default_==null) default_=""; 
        key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
          var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
            var qs = regex.exec(window.location.href);
              if(qs == null)
                      return default_;
                else
                        return qs[1];
}

//
// the array waiting_page_message holds a list of messages that can be displayed
// it's a bit messy as we have no here docs in javascript
//

var waiting_page_message = new Array;
var i = 0;

waiting_page_message[i++] = 'Did you know that you can look at all locations on this site on our "By Location" tab?';
waiting_page_message[i++] = 'Did you know that the "What" search can be used for anything?</p> <p align="center">Try; Job Title, Company name, Job Description or Job category.';
waiting_page_message[i++] = 'Did you know that when you see this icon <img border="0" src="http://www.localhelpwanted.net/lasvegas/images/mag.png" width="40" height="55"> you can click on it for our video help buddy?';
waiting_page_message[i++] = 'Did you know that a video resume should showcase your work NOT you talking (unless that\'s how you make your living)?';
waiting_page_message[i++] = 'Did you know that you can use all of our job seeker features &nbsp; FREE after you register?';
waiting_page_message[i++] = 'Did you know that you can go back to your previous search by using the "Return to Search" at the  top of each job?';
waiting_page_message[i++] = 'Did you know that you that a job listing is not &quot;Too Old&quot; until it is filled??';
waiting_page_message[i++] = 'Did you know that after filling out just 8 fields of our online resume/profile you can upload and attach your own resume?';
waiting_page_message[i++] = 'Did you know that when you click on &quot;browse&quot; you are looking at ALL of the listings?';
waiting_page_message[i++] = 'Did you know that an employer may list the job in a different manner or category than you would???</p> <p align="center">So be sure and search using keywords.';
waiting_page_message[i++] = 'Did you know that you can upload your resume or cover letter to "My Portfolio"?';
waiting_page_message[i++] = 'Did you know that you can switch between BROWSE and GRID views at the top of the sarch page?';
waiting_page_message[i++] = 'Did you know that you can send your search by Instant Messenger, Twitter, Email or Text with our Active Alerts?';
waiting_page_message[i++] = 'Did you know that NO email is Required to search for jobs and we send NO junk Mail ?';

function open_waiting_page(msg)
{
    if (msg == null) msg = 'Searching for your listing...';

    //
    // get on with it now..
    //

    var index = Math.floor(Math.random() * waiting_page_message.length);

    message = 
        '<p align="center">'
        + '<img border="0" src="http://www.localhelpwanted.net/lasvegas/images/search/waiting.gif" width="42" height="42"></p>'
        + '<p align="center"><font color="#0000FF" style="font-family: Arial, Helvetica, sans-serif;"><b>' + msg +'</b></font></p>'
        + '<p>&nbsp;</p>'
        + '<p><font style="font-family: Arial, Helvetica, sans-serif;">'
        + waiting_page_message[index]
        + '</font></p>';

    jQuery.blockUI({ message: message });
}

function popdown()
{
    jQuery.unblockUI();
}

function close_waiting_page()
{
    jQuery.unblockUI();
}

function http_request(callback_fn, strURL, showWaitingPage) 
{
    if (showWaitingPage == null) showWaitingPage = 1;

	var xmlHttpReq = false;
	var self = this;

	try {
	    self.xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (err2) {
	    try {
            self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    catch (err3) {
            try {
                self.xmlHttpReq = new XMLHttpRequest();
            }
            catch (err1) 
            {
                self.xmlHttpReq = false;
            }
	    }
	}

    if (showWaitingPage == 1) open_waiting_page();

	self.xmlHttpReq.open('GET', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() 
	{
		if (self.xmlHttpReq.readyState == 4) 
		{
            callback_fn(self.xmlHttpReq.responseText);
            if (showWaitingPage == 1) close_waiting_page();
		}
	}
	self.xmlHttpReq.send(null);
}

function set_div_from_url(strDIV, strURL, showWaitingPage) 
{
    if (strDIV == null) return;
    if (showWaitingPage == null) showWaitingPage = 1;

	var xmlHttpReq = false;
	var self = this;

	try {
	    self.xmlHttpReq = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (err2) {
	    try {
            self.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    catch (err3) {
            try {
                self.xmlHttpReq = new XMLHttpRequest();
            }
            catch (err1) 
            {
                self.xmlHttpReq = false;
            }
	    }
	}

    if (showWaitingPage == 1) open_waiting_page();

	self.xmlHttpReq.open('GET', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() 
	{
		if (self.xmlHttpReq.readyState == 4) 
		{
			set_div_from_str(strDIV,self.xmlHttpReq.responseText);
            if (showWaitingPage == 1) close_waiting_page();
		}
	}
	self.xmlHttpReq.send(null);
}

function set_div_from_str(div,str)
{
	document.getElementById(div).innerHTML = str;
}

function hide(name)
{
	hide_show(name, 'none');
}

function show(name)
{
	hide_show(name, 'block');
}

function hide_show(name,state)
{
    if (name == null || name == 'undefined') return;

	//if(document.all)
	//{ //IS IE 4 or 5 (or 6 beta) 
	//	eval("document.all." +name+ ".style.display = state"); 
	//} 
	if (document.layers) 
	{ //IS NETSCAPE 4 or below 
		document.layers[name].display = state; 
	} 
	//if (document.getElementById &&!document.all) 
	if (document.getElementById)
	{ 
		hza = document.getElementById(name); 
        if (hza != null) hza.style.display = state; 
	}
}
 
function sleep(delay)
{
	var start = new Date().getTime();
	while (new Date().getTime() < start + delay);
}

function showPopUp(el) {
    var cvr = document.getElementById("cover")
        var dlg = document.getElementById(el)
        cvr.style.display = "block"
        dlg.style.display = "block"
        if (document.body.style.overflow = "hidden") {
            cvr.style.width = 1600;
            cvr.style.height = "100%"
        }
}
function closePopUp(el) {
    var cvr = document.getElementById("cover")
        var dlg = document.getElementById(el)
        cvr.style.display = "none"
        dlg.style.display = "none"
        document.body.style.overflowY = "scroll"
}

function getPageWidth()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
        imyWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );

    return myWidth;
}

function get_x_offset(id)
{
    var tLeft = 0, tTop = 0;
    var node = $(id);

    while ( node != null )
    {
        tTop  += node.offsetTop;
        tLeft += node.offsetLeft;
        node = node.offsetParent;
    }

    return tLeft;
}

function get_y_offset(id)
{
    var tLeft = 0, tTop = 0;
    var node = $(id);

    while ( node != null )
    {
        tTop  += node.offsetTop;
        tLeft += node.offsetLeft;
        node = node.offsetParent;
    }

    return tTop;
}

function add_x_offset(id, offset)
{
    var xpos = get_x_offset(id);
    $(id).style.left = xpos + "px";
}

function scroll_page(id) 
{   
    var offset = get_y_offset(id);
    window.scroll(0,offset); // horizontal and vertical scroll targets
}





