// hot jobs rotate
function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;
	$("div.job:eq(" + old_headline + ")").animate({top: -120},"slow", function() {$(this).css('top', '145px');	});
	$("div.job:eq(" + current_headline + ")").animate({top: 10},"slow");
	old_headline = current_headline;
}

// Maximum limit on entry fields alert

function checkCount(cur,total) {
	if(cur>=total) {
		alert("Sorry, the limit is "+total+" characters");
		return false;
	}
	return true;
}

// Dynamic job cateogry form

function updateCategory(theForm,want_all,idx) {
    var s = document.forms[theForm];
    var ci;
    var o;
    if( idx >= 0 ) {
        ci = s["Category_" + idx];
        o  = s["SubCategory_" + idx];
    } else {
        ci = s["Category"];
        o  = s["SubCategory"];
    }
    var cid = ci.options[ci.selectedIndex].value;
    var offset;
    if(want_all || cid == 0) {
        offset = 1;
    } else {
        offset = 0;
    }
    while (o.length != offset) { o.options[offset] = null; }
    if( ci.type == "select-multiple" ) {
        var num_selected = 0;
        for (var i = 0; i < ci.length; i++) {
            if( ci.options[i].selected ) {
                num_selected++;
                if( num_selected > 1 ) return;
            }
        }
    }
    if( cid > 0 ) {
        for (var i = 0; i < c[cid].length; i++) {
	    o.options[i+offset] = new Option(c[cid][i][0], c[cid][i][1]);
        }
    }
}

// Determine browser.

var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;

/*
open a new window, center it and set dimensions relative to the users screen
url: url of new document
name: document name
statbar: boolean yes or no for statusbar display
scroll: boolean yes or no for scrollbars
locate: boolean yes or no for locationbars
x: set the new window height with a percentage value relative to the users screen
y: set the new window width with a pecentage value relative to the users screen
usage: javascript:winOpen('index.htm','newwin','yes','yes','yes',.5,.5)
*/
function winOpen(url,name,statbar,scroll,locate,x,y)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = parseInt(screenheight)* y//set new window height properties
var winwidth = parseInt(screenwidth)* x//set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft)
}

function winOpenCenter(url,name,statbar,scroll,locate,resize,xWidth,yWidth)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = yWidth //set new window height properties
var winwidth = xWidth //set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',resizable='+resize+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft);
return win;
}

// Email Checker

function onFormSubmit(formObj) {
	if (!isEmailValid(formObj.Email.value))
		{
		formObj.Email.focus();
		return false;
		}
	return true;
}

function isEmailValid(str)
{
	var pos;
	var errorCount = 0;
	var email = str;
	
	var validStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.[]-_";

	if (email == "") {
		alert("Please enter your email address.");
		return false;
	}
	
	if (email.charAt(0) == "@" || email.charAt(0) == "." || email.charAt(0) == "[" || email.charAt(0) == "]" || email.charAt(0) == "-" || email.charAt(0) == "_") errorCount++;
	
	if (!validCharacters(email,validStr)) errorCount++;
		
	for (i = 1; i < email.length; i++) {
		if ((email.charAt(i-1) == "." && email.charAt(i) == ".") || (email.charAt(i-1) == "." && email.charAt(i) == "@") || (email.charAt(i-1) == "@" && email.charAt(i) == ".")) {
			errorCount++;
			break;
		}
	}

	if (!errorCount && email.indexOf("@") < 0 && email.length > 0) {
		alert("Your email address is missing the domain name. The format should be "+str+"@somedomain.\n\nFor example, "+str+"@aol.com, "+str+"@earthlink.net, or "+str+"@yahoo.com.");
		return false;
	}

	if (email.length < 6) errorCount++;
	
	pos = email.indexOf("@");
	email = email.substring(pos+1,email.length);
	
	if (email.indexOf("@") != -1) errorCount++;
	
	if ((email.charAt(0) == "[" && email.charAt(email.length-1) != "]") || (email.charAt(0) != "[" && email.charAt(email.length-1) == "]") || (email.charAt(0) == "]" || email.charAt(email.length-1) == "[")) errorCount++;
	
	if (email.indexOf(".") < 0) {
		errorCount++;
	}
	else {
		pos = email.lastIndexOf(".");
		email = email.substring(pos+1,email.length);

		if ((!isNaN(email) && email != "") || (email.charAt(email.length-1) == "]")) {

			pos = str.indexOf("@");
			
			if (email.charAt(email.length-1) == "]") {
			
				email = str.substring(pos+1,str.length-1);

				if (email.charAt(0) == "[") {
					email = email.substring(1,str.length);
				}				
			}
			else {
				email = str.substring(pos+1,str.length);
			}
			
			var ipAddress = "";
			var periods = 0;

			for (i = 0; i < email.length; i++) {
				if (email.charAt(i) == ".") {
					periods++;

					if ((isNaN(ipAddress)) || (ipAddress < 0 || ipAddress > 255)) {
						errorCount++
						break;
					}
					ipAddress = "";
				}
				else
					ipAddress += email.charAt(i).toString();
			}
			if ((isNaN(ipAddress)) || (ipAddress < 0 || ipAddress > 255)) errorCount++

			if (periods != 3) errorCount++;
		}
		else {
			if (email.length < 2 || email.length > 3) errorCount++;
		}
	}

	if (errorCount > 0) {
		alert(str+" is not a valid email address. Please check your typing.");
		return false; }
	return true;
}

function containsCharacter(str,testchar)
	{ for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == testchar) return true;	}
	return false;
}

function validCharacters(teststr,validstr)
	{ for (i = 0; i < teststr.length; i++) {
		if (validstr.indexOf(teststr.charAt(i)) < 0) return false;	}
	return true;
}

