function onGotoJob() {
	var theJobNumber = parseInt(document.forms[0].GotoJobNumber.value);
	var Loc = (arguments.length > 0) ? arguments[0] : '';
	
	if (document.forms[0].GotoJobNumber.value == 'Job ID') return false;
	
	if (isNaN(theJobNumber) || theJobNumber <= 0) {
		alert('You must input a valid job number');
	} else {
		var new_href = "JobDetailsOrder.asp?Job_ID=" + theJobNumber + '&Loc=' + Loc;
		location.href = new_href;
	}
	return false;
}

function onGotoJCItem(obj)
{
    var bCart = (obj.value.charAt(0).toUpperCase() == 'C') ? true : false;
    var itemID = (bCart) ? obj.value.substr(1) : obj.value;

    if (itemID == 'Item ID') return false;

    if (isNaN(itemID) || itemID <= 0) {
        alert('You must input a valid item ID');
    } else {
        location.href = ((bCart) ? '/Cart.asp?CartID=' : '/JobDetailsOrder.asp?Job_ID=') + itemID;
    }
    return false;
}

function onGotoItem(obj) {
    // [C]art | Cart [I]tem | Job (no prefix)
    switch (obj.value.charAt(0).toUpperCase()) {
        case 'C':
            location.href = '/Cart.asp?CartID=' + obj.value.substr(1);
            break;
        case 'I':
            location.href = '/Form.asp?CartItemID=' + obj.value.substr(1);
            break;
        default:
            location.href = '/JobDetailsOrder.asp?Job_ID=' + obj.value;
    }
    return false;
}

function launchit(newURL, newName, newFeatures, orgName) {
  var NewWindow = window.open(newURL, newName, newFeatures);
  try {
	if (NewWindow.opener == null) NewWindow.opener = self;
	NewWindow.opener.name = orgName;
	NewWindow.focus();
  }
  catch (e) {
	;
  }

  return NewWindow;
}

function popUp(mylink) { 
	if (!window.focus) return true; // Don't know what this does but .focus() does not return a value
	var href = (typeof(mylink) == 'string') ? mylink : mylink.href;
	var Width = (arguments.length > 1) ? arguments[1] : 750;
	var Height = (arguments.length > 2) ? arguments[2] : 500;
	var Name = (arguments.length > 3 && arguments[3].length > 0) ? arguments[3] : ((mylink.target) ? mylink.target : '_blank');
	var ExtraFeatures = (arguments.length > 4 && arguments[4].length > 0) ? arguments[4] : 'resizable=1,scrollbars=1,status=1,toolbar=0,menubar=0';
	var leftPos = 5, topPos = 5;
	
	if (screen) { // Center the popup
		leftPos = (screen.width / 2) - (Width / 2);
		topPos = (screen.height / 2) - (Height / 2);
	}
	var Features = (ExtraFeatures.length > 1) ? "screenX=" + leftPos + ",left=" + leftPos + ",screenY=" + topPos + ",top=" + topPos + ",width=" + Width + ",height=" + Height + "," + ExtraFeatures : "screenX=" + leftPos + ",left=" + leftPos + ",screenY=" + topPos + ",top=" + topPos + ",width=" + Width + ",height=" + Height;
	//alert('DEBUG Name: ' + Name + ', Features: ' + Features + ', href: ' + href + ', orgName: ' + (window.name==''?'main':window.name));
	launchit(href, Name, Features, (window.name==''?'main':window.name));
	return false;
}

function load_url(inURL) {
	var myRemote = launchit(inURL, "myRemote", "height=500,width=750,screenX=5,left=5,screenY=5,top=5,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=1", window.name);
}

function redirect(thisSelect){
	var v = thisSelect.options[thisSelect.selectedIndex].value;
	if (v!="") {
		if (v.indexOf('.lch') != -1 && v.indexOf('Mac.lch') == -1) 
			location.href = v;
		else
			load_url(v);
	}
	thisSelect.selectedIndex = 0;
	return false;
}

function listgoto(thisSelect){
	var v = thisSelect.options[thisSelect.selectedIndex].value;
	if (v!="") {
		location.href = v;
	}
	thisSelect.selectedIndex = 0;
	return false;
}

// According to the Netscape JavaScript Reference manual there isn't a form input type of image.
function HREFSubmit(inText, inAction) {
	if (inText != ''){
		if (confirm(inText)) {
			if (document.forms[0].hiddenaction) {
				document.forms[0].hiddenaction.value = inAction;
			}
			document.forms[0].submit();
		}
	}
	else {
		if (document.forms[0].hiddenaction) {
			document.forms[0].hiddenaction.value = inAction;
		}
		document.forms[0].submit();
	}
	return false;
}

function BrowserType()
{

	var AppString = navigator.appName;
	var isNS = (AppString == "Netscape" ); 
	if (isNS )
	{
		var NSVer = parseInt(navigator.appVersion);
		
		if (navigator.appVersion.indexOf('Safari') != -1)
			result = 'safari';
		else if (navigator.userAgent.indexOf('Firefox') != -1)
			result = 'firefox';
		else if (NSVer >= 6)
			result = 'n6';
		else if (NSVer >= 5)
			result = 'n5';
		else if (NSVer >= 4)
			result = 'n4';
		else
			result = 'n3';
	}
	else if (AppString.indexOf('Explorer') != -1) 
		result = 'ie';
	else if (navigator.userAgent.indexOf('Opera') != -1) 
	    result = 'opera';
		
	return result;
}

function IsOpera() {
	var AppString = navigator.appName
	
	if (AppString.indexOf('Opera') != -1)
		return true

	return false
}

function OSType()
{
	var AppString = navigator.platform;
	var result;
	
	if (AppString.indexOf('Win32') != -1) 
		result = 'win';
	if (AppString.indexOf('Linux') != -1) 
		result = 'linux';
	if (AppString.indexOf('Mac') != -1) 
		result = 'mac';

	return result;
}

function trim(str) {
	while (str.charAt(0) == ' ')
	  str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
	  str = str.substring(0, str.length - 1);
	return str;
}
function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
// Utility function that returns true if a string only contains whitespace
function isblank(s)
{
	for( var i = 0; i < s.length; i++ ) {
		var c = s.charAt(i);
		if( (c != ' ') && (c != '\n') && (c != '\t') ) return false;
	}
	return true;
}

function getOptionValue(e) {
var oValue;

	for( var j = 0; j < e.options.length; j++ ) {
		if( e.options[j].selected ) {
			oValue = e.options[j].value;
			return oValue; 
			break;
		}
	}
	return true;
}

function alertUser(inMessage) {
	var theMessage, theHRef;
	var pos, pos2;
	var bConfirm = false, rc = true;
			
	pos = inMessage.indexOf("|goHRef=");	pos2 = inMessage.indexOf("|goCHRef=");
	if (pos != -1) {
		theMessage = inMessage.substring(0, pos-1);
		theHRef = inMessage.substring(pos + 8); // 8 is the length of "|goHRef=";
	}
	else if (pos2 != -1) {
		theMessage = inMessage.substring(0, pos2-1);
		theHRef = inMessage.substring(pos2 + 9); // 9 is the length of "|goCHRef=";
		bConfirm = true;
	}
	else
		theMessage = inMessage;
	
	// Show the message			
	if( (theMessage == null) || (theMessage == "") || isblank(theMessage) ) { }
	else {
		if (bConfirm)
			rc = confirm(theMessage);
		else
			alert(theMessage);
	}
	
	if (rc) {
		// Redirect if necessary		
		if( (theHRef == null) || (theHRef == "") || isblank(theHRef) ) { }
		else
			window.location = theHRef;
	}		
	
	return true;
}

function myVoid () { ; } // do nothing

function onSearchJQ(e, query, list, searchStats) {

    jQuery.expr[':'].Contains = function (a, i, m) {
        return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
    };

    var key = (window.event) ? event.keyCode : e.which;
    var stats = $('#' + searchStats);
    var listAll = $('#' + list.id + ' option');
    var foundLength = 0;

    if (query.length > 0 && (listAll.size() <= 100 || key == 13)) {
        var found = $('#' + list.id + ' option:Contains("' + query + '")');
        //foundLength = found.attr('selected', 'selected').show().size();
        foundLength = found.prop('selected', true).show().size();
        //$('#' + list.id + ' option:not(:Contains("' + query + '"))').attr('selected', '').hide();
        $('#' + list.id + ' option:not(:Contains("' + query + '"))').prop('selected', false).hide();
        if (foundLength > 0) { stats.html('<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>' + foundLength + ' items found</strong>'); } else { stats.html('<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>No match found</strong>'); }
    } else {
        if (query.length > 0) {
            stats.html('<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>Hit <em>Enter</em> to begin search.</strong>');
        } else {
            listAll.attr('selected', '').show();
            stats.html('');
        }
    }
}

function onSearchNEW(e, query, list, searchStats) {
    var resultCount = 0;
    var oSearchStats = document.getElementById(searchStats);
    var arrOpt = list.options;
    var iLen = arrOpt.length;
    var key = (window.event) ? event.keyCode : e.which;

    if (query.length > 0 && (iLen <= 100 || key == 13)) { //select items that contain query text
        var oRegExp = new RegExp(query, 'i');
        for (var i = 0; i < iLen; i++) {
            if (oRegExp.test(arrOpt[i].text)) {
                arrOpt[i].selected = true;
                resultCount++;
                //arrOpt[i].style.display = 'block';
            } else {
                arrOpt[i].selected = false;
                //arrOpt[i].style.display = 'none';
            }
        }
        if (oSearchStats) {
            oSearchStats.innerHTML = (resultCount > 0) ? '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>' + resultCount + ' items found</strong>' : '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>No match found</strong>';
        }
    } else {
        if (oSearchStats && query.length > 0) {
            oSearchStats.innerHTML = '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>Hit <em>Enter</em> to begin search.</strong>';
        } else if (oSearchStats) {
            oSearchStats.innerHTML = '';
        }
    }
}

function onSearch(e, query, list, searchStats) {
	var resultCount = 0;
	var oSearchStats = document.getElementById(searchStats);
	var arrOpt = list.options;
	var iLen = arrOpt.length;
	var key = (window.event) ? event.keyCode : e.which;
	
  if (query.length > 0 && (iLen <= 100 || key == 13)) { //select items that contain query text
		//for (var i = iLen-1; i >= 0; i--) {
		for (var i = 0; i < iLen; i++) {
			if (arrOpt[i].text.toUpperCase().indexOf(query.toUpperCase()) >= 0) {
				arrOpt[i].selected = true;
				arrOpt[i].style.display = 'block';
				resultCount++;
			} else {
				arrOpt[i].selected = false;
				arrOpt[i].style.display = 'none';
			}
		}
		if (oSearchStats) {
			oSearchStats.innerHTML = (resultCount > 0) ? '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>' + resultCount + ' items found</strong>' : '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>No match found</strong>';
		}
  } else {
		if (oSearchStats && query.length > 0) { 
			oSearchStats.innerHTML = '<img src="images/StockImages/arrow3.gif" style="width:7px;height:11px;"/> <strong>Hit <em>Enter</em> to begin search.</strong>'; 
		} else if (oSearchStats) {
			oSearchStats.innerHTML = ''; 
		}
/*
		for (var i = 0; i < iLen; i++) {
			arrOpt[i].selected = false;
			arrOpt[i].style.display = 'block';
		}
*/
  }
}
function onSearchBlur(obj) {
	if (obj.value.length <= 0) {obj.value='Search'};
}
function onSearchFocus(obj) {
	if (obj.value == 'Search') {obj.value = ''};
}
function onListAutosize(obj, oSelectList, min) {
	oSelectList.size = (oSelectList.options.length+5 > oSelectList.size) ? oSelectList.options.length+5 : min;
	return false;
}

function DoAsciiHex(x,dir) {
var hex="0123456789ABCDEF";
var almostAscii=' !"#$%&'+"'"+'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ['+'\\'+']^_`abcdefghijklmnopqrstuvwxyz{|}';
var r="";
var i, let, let1, let2, pos, h1, h16, val;

	if (dir=="A2H") {
		for (i=0;i<x.length;i++){
			let=x.charAt(i);
			pos=almostAscii.indexOf(let)+32;
			h16=Math.floor(pos/16);
			h1=pos%16;r+=hex.charAt(h16)+hex.charAt(h1);
		}
	}
	else if (dir=="H2A") {
		for (i=0;i<x.length;i++) {
			let1=x.charAt(2*i);
			let2=x.charAt(2*i+1);
			val=hex.indexOf(let1)*16+hex.indexOf(let2);
			r+=almostAscii.charAt(val-32);
		}
	}

	return r;
}

// Hack for D1, D4, D5 skin... Who knows?...
function OnLoadSkinFix() {
var Dbg;
	try {
			if (window.outerWidth < screen.width)
				window.resizeBy(0,-1);
	}
	catch (e) {
		;
	}
}

// AJAX Call
function getHTTPObject() {
var xmlhttp;

	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E) {
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlhttp = false;
		}
	}

	return xmlhttp;
}

function addSupportHelpLink () {
    document.write('<div id="supportHelp"> <a href="/Help.asp">Need more help?</a></div>');
}
function addPrintButton() {
    document.write('<div id="printHelp"><a href="#" onclick="window.print()"><img src="/images/printer.png" alt="Printer Icon" border="0"> Print</a>');	  
    document.write('</div>');
}

function NetSolSiteSeal(img,type){
if(window.location.protocol.toLowerCase()=="https:"){var mode="https:";} else {var mode="http:";}
var host=location.host;
var baseURL=mode+"//seals.networksolutions.com/siteseal_seek/siteseal?v_shortname="+type+"&v_querytype=W&v_search="+host+"&x=5&y=5";
document.write('<a href="https://seals.networksolutions.com" onClick=\'window.open("'+baseURL+'","'+type+'","width=450,height=500,toolbar=no,location=no,directories=no,\
status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no");return false;\' onmouseover="window.status=\'Click to Verify\';return true" onmouseover="window.status=\'\';return true">\
<img src="'+img+'" style="border:none;" oncontextmenu="alert(\'This SiteSeal is protected\');return false;"></a>');}

function jqid(myid) {
    return '#' + myid.replace(/(:|\.)/g, '\\$1');
}

