/*------------------------------------------------------------------------------
Purpose:
	Various JS functions/variables used across sites

History:
Ver			Inits	Date		Comments
1.00.00		WS		03/13/02	Added this comment block
1.00.01		WS		04/03/02	added "file" to the list of form field types checked	
1.00.02		WS		??-??-??	Added isNumeric to replace isThisANumber
1.00.03		BWJ		05-09-02	Changed isThisANumber to return the value
1.00.04		BWJ		07-11-02	Fixed typo in isWhole
1.00.05		BWJ		08-15-02	Changed equality determination in isWhole (NS bug)
1.00.06		BWJ		04-17-03	Added isPositive
1.00.07		WS		05/30/03	added scotts highlight functions
1.00.08		BWJ		07-16-03	Added showHide
1.00.09		BWJ		12-01-03	Changed "inline" to "" in showHide
1.01.00		DBS		03-03-06	added Yury's adjacent element stuff
------------------------------------------------------------------------------*/

var vNS4 = (document.layers)? true:false

if (vNS4) {
   layerRef="document.layers";
   styleRef="";
} else {
   layerRef="document.all";
   styleRef=".style";
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
 
function curUpdate(countryCode) {
var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());
var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
var expires_date = new Date(todays_date.getTime() + (52 * 7 * 86400000)); // 52 weeks

Set_Cookie("CPRICE",countryCode,expires_date,"/");
}

var editWin = null;

function openWin(theurl, winName, params) {
	if (winName=="") winName="Edit";
	if (params=="") params="status,scrollbars,menubar,location,width=500,height=400,left=10,top=10"
	if ((editWin == null) || (editWin.closed))
	  	editWin = window.open(theurl, winName, params);
	else {editWin.close();editWin = window.open(theurl, winName, params);}
	  if (!editWin.opener)
	        editWin.opener = self;
	  editWin.focus();
}

function formCheck(which) {
	var pass=true;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,1)=="r") {
				if (((tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="file")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
					pass=false;
					break;
				}
			}
		}//end of for loop
	}
	if (!pass) {
		alert("Please make sure ALL required fields are filled in.");
		return false;
	}
	else
		return true;
}

function isNumeric(where) {
	var x = where.value
	if (isNaN(x)) {
		alert('Please enter only a number into this text box')
		where.focus();
		return false;
	} else {
		return true;
	}
}

function isThisANumber(where) {
	return isNumeric(where);
}

function isWhole(where) {
	var x = where.value;
	var test;
	
	if (isNaN(x)) {
		test = false;
	} else if ((Math.round(x) - x != 0) || (x < 0)) {
		test = false;
	} else {
		test = true;
	}
	
	if (!test) {
		where.value = "";
		alert("Please enter only a whole number into this text box");
		where.focus();
		return false;
	}
}

function isPositive(where) {
	var x = where.value;
	var test = true;
	
	if (isNaN(x)) {
		test = false;
	} else if ((x != "") && (x <= 0)) {
		test = false;
	}
	
	if (!test) {
		alert("Please enter only a positive number into this text box");
		where.value = "";
		where.focus();
		return false;
	}
}

function fieldHighlight(OBJ,myColor) {
OBJ.style.background = '#' + myColor;
}

function fieldUnhighlight(OBJ,myColor) {
OBJ.style.background = '#' + myColor;
}

function showHide(thisBox) {
	var thisLink = event.srcElement;
	
	if (thisBox.style.display == "none") {
		thisBox.style.display = "";
		thisLink.innerHTML = "Hide" + thisLink.innerHTML.substring(4, thisLink.innerHTML.length);
	} else {
		thisBox.style.display = "none";
		thisLink.innerHTML = "Show" + thisLink.innerHTML.substring(4, thisLink.innerHTML.length);
	}
	
	return false;
}

// JavaScript Document
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm thor@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}