//Window Formatting
//defaults: width-650px height-450px window name-win
function openWindow(path,winName,w,h)
{
	window.name="parentWindow";
	if (w == null) {w = 650} if (h == null) {h = 450} if (winName == null) {winName = 'win'}
	msgWindow=window.open(path,winName,"menubar=yes,width="+w+",height="+h+",resizable=yes,toolbar=no,scrollbars=yes,status=yes,screenX=50,screenY=50");
	msgWindow.focus();
}
//Image Window Formatting
function openImgWindow(path,winName,w,h)
{
	window.name="parentWindow";
	if (w == null) {w = 650} if (h == null) {h = 450} if (winName == null) {winName = 'win'}
	msgWindow=window.open(path,winName,"menubar=no,width="+w+",height="+h+",resizable=yes,toolbar=no,scrollbars=yes,status=yes,screenX=50,screenY=50");
	msgWindow.focus();
}
//CouponLink Window Formatting
function couponLink(path,winName,w,h)
{
	window.name="parentWindow";
	if (w == null) {w = 650} if (h == null) {h = 450} if (winName == null) {winName = 'win'}
	msgWindow=window.open(path,winName,"menubar=yes,width="+w+",height="+h+",resizable=yes,toolbar=yes,scrollbars=yes,status=yes,screenX=50,screenY=50");
	msgWindow.focus();
}
//Open link in parent window and close the child window
function updateParent(newURL) {
	opener.document.location=newURL;
	window.close();
}

//Target link with form select
function goSelect(formId) {
	form = document.getElementById(formId);
	list = form.selector;
	location = list.options[list.selectedIndex].value;
}

//Reset Form
function reset(formId) {
	document.getElementById(formId).reset();
	return;
}

/*
Randomizer. To create a random floating point number use: rnd();
to create a random integer, say between 0 and 25, use: rand(26)-1;
*/
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
}
function rand(number) {
	return Math.ceil(rnd()*number);
}

//DOM Verification
var isDHTML=0;
var isID=0;
var isAll=0;
var isLayers=0;

if (document.getElementById) {isID=1; isDHTML=1;}
else {
if (document.all) {isAll=1; isDHTML=1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape')!=-1) && (browserVersion==4)) {isLayers=1; isDHTML=1;}
}}
function findDOM(objectID,withStyle) {
	if (withStyle==1) {
		if (isID) {
			if (document.getElementById(objectID) == null) {return;}
			else {return (document.getElementById(objectID).style);}}
		else {
			if (isAll) {
				if (document.all[objectID] == null) {return;}
				else {return (document.all[objectID].style);}}
		else {
			if (isLayers) {
				if (document.layers[objectID] == null) {return;}
				else {return (document.layers[objectID]);
}}};}}
	else {
		if (isID) {
			if (document.getElementById(objectID) != null) {
				return (document.getElementById(objectID));}}
		else {
			if (isAll) {
				if (document.all[objectID] != null) {
					return (document.all[objectID]);}}
		else {
			if (isLayers) {
				if (document.layers[objectID] != null) { 
					return (document.layers[objectID]);
}}}}};}

//Visibility Controller
function setVisibility(objectID,state) {
	var dom = findDOM(objectID,1);
	if (dom == null) {return;}
	else {dom.visibility = state;}
}
//Display Controller
function setDisplay(objectID,state) {
	var dom = findDOM(objectID,1);
	if (dom == null) {return;}
	else {dom.display = state;}
}

//Textarea Limit Validation
function textCounter(field,countfield,maxlimit) {
	if (field.value.length > maxlimit)
	field.value = field.value.substring(0,maxlimit);
	else 
	countfield.value = maxlimit - field.value.length;
}

/* baseToggle - Description:
		Show/hide layers. Optionally select form element.
 */
var prevObj = "none";
function baseToggle(objectID,style,hilite) {
	if (document.getElementById) {
		var obj = document.getElementById(objectID).style;
		if (style == 'd') {
			if (obj.display == 'block') obj.display = 'none';
			else {
				obj.display = 'block';
				if (hilite == 'y') document.getElementById(objectID).select();
				if (prevObj != 'none')
					document.getElementById(prevObj).style.display = 'none';
					prevObj = objectID;
			}
		}
		if (style == 'v') {
			if (obj.visibility == 'visible') obj.visibility = 'hidden';
			else {
				obj.visibility = 'visible';
				if (hilite == 'y') document.getElementById(objectID).select();
				if (prevObj != 'none' && prevObj != objectID)
					document.getElementById(prevObj).style.visibility = 'hidden';
					prevObj = objectID;
			}
		}
	}
}

//Misc. functions
function emailTo(path) {
	document.location=path;
}
function noDaughter(path) {
	window.location=path
}
function trackSorting(url) {
	document["TRACKER"].src = url;
}

//Update parent window and close/refocus child window
function updateOpener(page) {
	if (window.opener && !window.opener.closed) {
		if (page) {
			if (page == "member") {
				opener.vp_showFullMemberReg();
			} else {
				opener.vp_showOverlayContent(page);
			}
			opener.focus();
		} else {
			window.close();
		}
	} else {
		window.location = "http://www.valpak.com";
	}
}