
function hov(loc,cls) {
	if(loc.className) {
		loc.className=cls;
	} else {
		return false;
	}
}

function setClass(thisForm,thisField,thisClass) {
	var thisField = document.forms[thisForm][thisField];
	if (thisField) {
		thisField.className = thisClass;
	} else {
		return false;
	}
}

 

function hov2(thisDiv,thisColor) {

	thisDiv = getStyleObject(thisDiv);
	
	if(thisDiv) {
		thisDiv.color = thisColor;
	} else {
		return false;
	}
}

function hov3(thisDiv,thisColor,thisDecoration) {
	if(thisDiv) {
		thisDiv.style.color = thisColor;
		thisDiv.style.textDecoration = thisDecoration;
	} else {
		return false;
	}
}





function relocateUser(thisAction,thisForm) {
	if (arguments.length != 1) {
		var thisForm = document.forms[thisForm];
	
		if (arguments.length == 3) {
			thisForm.thisAnchor.value = arguments[2];
		} 
		
		if (thisForm.thisAction && thisForm.thisAction.disabled == false) {
			thisForm.thisAction.value = thisAction;
		} else if (thisForm.thisBody) {
			thisForm.thisBody.value = thisAction;
		} 
		thisForm.submit();
	} else {
		window.location.href = thisAction;
	}
}

function goAnchor(thisAnchor) {
	location.hash = thisAnchor;
}



function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {		// cross-browser function to get an object's style object given its id
	
	return document.getElementById(objectId).style;							// W3C DOM
	} else if (document.all && document.all(objectId)) {
	
	return document.all(objectId).style;									// MSIE 4 DOM
	} else if (document.layers && document.layers[objectId]) {
	
	return document.layers[objectId];										// NN 4 DOM.. note: this won't find nested layers
	} else {
	return false;
	}
} 

function hideThis(objectID) {
	var styleObject = getStyleObject(objectID);
	if(styleObject) {
		styleObject.display = "none";
		return true;
	} else {
		return false;
	}
}


function goLaunch(template,id, local) {
	thisEnd = template+"?id="+id;
	thisWindow = "stats_"+id;
	thisRoot = (local == 0) ? "http://www.ecostamps.org/writers/"+thisEnd : "http://localhost:8500/ecostamps/writers/"+thisEnd;
	window.open(thisRoot,thisWindow);
}


function goMarket(id) {
	var thisURL;
	var thisWindow;
	var thisID;
	var thisRoot;
	
	if(arguments.length==2) {
		thisID = id;
		thisRoot = (arguments[1] == 0) ? "https://www.ecostamps.org/ecostamps.cfm?id=" : "http://localhost:8500/ecostamps/ecostamps.cfm?id=";
	} else {
		var thisForm = arguments[0];
		var thisField = arguments[1];
		thisRoot = (arguments[2] == 0) ? "https://www.ecostamps.org/ecostamps.cfm?id=" : "http://localhost:8500/ecostamps/ecostamps.cfm?id=";
		
		a = document.forms[thisForm][thisField];
		
		if (a.length) {
			for (i=0; i<a.length; i++) {
				if (a[i].checked) {
					thisID = a[i].value;
				}
			}
		} else if (a.checked) {
			thisID = a.value;
		}
	}
	
	thisURL = thisRoot+thisID;
	thisWindow = "market_"+thisID;

	window.open(thisURL,thisWindow);
}

function goProfile(id,url,a) {
	var thisURL = url+id;
	window.open(thisURL,a);
}


function setHidden(id,thisForm,thisField) {
	var thisForm = document.forms[thisForm];
	var thisField = thisForm[thisField];
	thisField.value = unescape(id);
}


function loopHide() {
	for(i=0; i<arguments.length; i++) {
		hideThis(arguments[i]);
	}
}

function loopShow() {
	for(i=0; i<arguments.length; i++) {
		showThis(arguments[i]);
	}
}


function setStyle(objectID,thisStyle,thisValue) {
	
	var a = getStyleObject(objectID);
	
	if (a) {
		a[thisStyle] = thisValue;
	} else {
		return false;
	}
}

function disElemBit (thisForm,thisField,whichBit) {
	var thisField = document.forms[thisForm][thisField];
	for (i=0; i<thisField.length; i++) {
		if (whichBit=="false") {
			thisField[i].disabled = false;	
		} else {
			thisField[i].disabled = true;	
		}
	}
}

function disableElement(thisForm,thisField,thisValue) {
	var thisField = document.forms[thisForm][thisField];
	if (thisField.length) {
		for(i=0; i<thisField.length; i++) {
			thisField.disabled = (thisField[i].value == thisValue) ? true : false; 
		}
	} else if (thisField.value == thisValue) {
		thisField.disabled = true; 
	}
}

function enableThis(thisForm,theseFields) {
	var thisForm = document.forms[thisForm];
	
	if (theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (i=0; i<a.length; i++) {
			thisField = a[i];
			if(thisForm[thisField]) {
				thisForm[thisField].disabled = false;
			} else {
				return false;
			}
		}
	} else if (thisForm[theseFields]) {
		thisForm[theseFields].disabled = false;
	} else {
		return false;
	}
}
	


function showThis(objectID) {
	var styleObject = getStyleObject(objectID);
	if(styleObject) {
		styleObject.display = "";
		} else {
		return false;
	}
}



function disableButton(thisButton, thisForm) {
	thisForm = document.forms[thisForm];
	thisButton = thisForm[thisButton];
	
	var thisClass = 'button_dis';
	if (arguments.length > 2) {
		thisClass = arguments[2];
	}
	
	if(thisButton) {
		thisButton.disabled = true;
		thisButton.className = thisClass;
	}
}

function disableButtons(thisForm) {
	var arrayElements = disableButtons.arguments;
	var numberArrayElements = arrayElements.length;
	var thisButton = new Array(numberArrayElements);
	
	for (i=1; i<numberArrayElements; i++) {
		var thisButton = arrayElements[i];
		disableButton(thisButton,thisForm);
	}
}

function enableButton(thisButton, thisForm) {
	var thisClass = 'button_a';
	if (arguments.length > 2) {
		thisClass = arguments[2];
	}
	document.forms[thisForm][thisButton].disabled = false;
	document.forms[thisForm][thisButton].className = thisClass;
}

function checkValues (thisForm, thisField, theseValues) {
	thisField = document.forms[thisForm][thisField];
	
	if (thisField.length) {
		for(i=0; i<thisField.length; i++) {
			if (theseValues.indexOf(",") != -1) {
				a = theseValues.split(",");
				checkFlag = 0;
				for (j=0; j<a.length; j++) {
					if(thisField[i].value == a[j]) {
						checkFlag = 1;
					}
				}
			} else {
				checkFlag = 0
				if(thisField[i].value == theseValues) {
					checkFlag = 1;
				}
			}

			if(checkFlag == 1) {
				thisField[i].checked = true;
			} else {
				thisField[i].checked = false;
			}
		}
	} else {
		if (thisField.value == theseValues) {
			thisField.checked == true;
		} else {
			thisField.checked == false;
		}
	}
}


function selDis (thisForm,thisField,thisValue,thisDis_1,thisDis_2) {
	var thisDis;
	thisForm = document.forms[thisForm];
	thisField = thisForm[thisField];
	thisDis_1 = thisForm[thisDis_1];
	thisDis_2 = thisForm[thisDis_2];
	
	for (i=0; i<thisField.length; i++) {
		if (thisField.options[i].selected) {
			if (thisField.options[i].value == thisValue) {
				thisDis_1.disabled = true;
				thisDis_2.disabled = true;
				thisDis_1.value = "NOT REQUIRED";
				thisDis_2.value = "NOT REQUIRED";
			} else {
				thisDis_1.disabled = false;
				thisDis_2.disabled = false;
				thisDis_1.value = "";
				thisDis_2.value = "";
			}
		}
	}
}


function loopClearField (theseFields, thisForm) {
	if(theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (i=0; i<a.length; i++) {
			clearField(thisForm, a[i]);
		}
	} else {
		return false;
	}
}

function loopUncheckAll (theseFields, thisForm) {
	if(theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (j=0; j<a.length; j++) {
			uncheckAll(a[j], thisForm);
		}
	} else {
		return false;
	}
}

function loopSelectFirst (theseFields, thisForm) {
	if(theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (j=0; j<a.length; j++) {
			selectFirst(a[j], thisForm);
		}
	} else {
		return false;
	}
}

function loopDisableAll (theseFields,thisForm) {
	if (theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (b=0; b<a.length; b++) {
			disableAllOptions(thisForm, a[b]);
		}
	}
}


function loopEnableAll (theseFields,thisForm) {
	if (theseFields.indexOf(",") != -1) {
		a = theseFields.split(",");
		for (b=0; b<a.length; b++) {
			enableAll(thisForm, a[b]);
		}
	}
}



function changeBit (thisForm,thisField) {
	thisValue = thisForm[thisField].value;
	var hideshow;
	
	if (thisValue==1) {
		thisForm[thisField].value = 0;
	} else {
		thisForm[thisField].value = 1;
	}
}

function showInactive(thisForm,thisField,theseDivs) {
	thisValue = thisForm[thisField].value;
	
	if (thisValue==0) {
		thisForm[thisField].value = 1;
		if (theseDivs && theseDivs != "") {
			if(theseDivs.indexOf(",") != -1) {
				a = theseDivs.split(",");
				for (b=0; b<a.length; b++) {
					showThis(a[b]);
				}
			} else {
				showThis(theseDivs);
			}
		} else {
			return false;
		}
	}
}



function loopHov (thisPanel, theseIDs, thisColor) {
	var a;
	var b;
	var panel; 
	
	a = theseIDs.split(",");
	
	for (b=0; b<a.length; b++) {
		panel = thisPanel+'_'+a[b];
		if(arguments.length==3) {
			hov2(panel, thisColor);
		} else {
			hov4(panel, thisColor);
		}
	}
}



var DHTML = (document.getElementById || document.all || document.layers);



function getObj(name)
{

  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	
	if (name.indexOf("label") == -1) {
		this.style = document.getElementById(name).style;
	}
	
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function showEmail (content,target) {
	var a = new getObj(target);
	a.obj.innerHTML = content;
	showThis(target);
}


function showJSError (thisForm,thisField,thisID,thisAction) {
	var a; // field
	var b; // error panel
	var f=1; // flag to show/hide panel; 0=hide;
	
	
	a = document.forms[thisForm][thisField];
	b = getStyleObject(thisID);
	
	
	if (a.length) {
		for(i=0; i<a.length; i++) {
			if (a[i].checked) {
				f=0;
			}
		}
		
	} else if (a.checked) {
		f=0;
	}
	
	
	if (f==0) {
		b.display = "none";
		relocateUser(thisAction,thisForm);
	} else {
		b.display = "";
	}
	
}

function checkboxHideShow (thisField,thisPanel,thisRadio,thisForm) {
	var a = document.forms[thisForm][thisRadio];
	if(thisField.checked) {
		showThis(thisPanel);
		for (i=0; i<a.length; i++) {
			if (a[i].checked) {
				showThis(a[i].value);
			} else {
				hideThis(a[i].value);
			}
		}
	} else {
		hideThis(thisPanel);
		for (i=0; i<a.length; i++) {
			hideThis(a[i].value);
		}
	}
}

function CD (thisForm,thisField,thisCheck,thisValue) {
	
	var a = document.forms[thisForm][thisField];

	for (i=0; i<a.length; i++) {
		if (a[i].value != thisValue) {
			a[i].disabled = thisCheck;
		}
	}
}

function waiverCheck (thisForm,thisField,firstField,secondField,buttonField,buttonName) {
	
	var a = document.forms[thisForm][thisField];
	if (a && a.checked) {
		agreementCheck(thisForm,firstField,secondField,buttonField,buttonName);
	} else {
		document.forms[thisForm][buttonField].disabled = true;
		var thisDisabled = arguments[5]+'_disabled';
		document.forms[thisForm][buttonField].className = thisDisabled;
	}
}

function premium (thisForm,hideAll,showThese,thisTotal,env,no_env) {
	var a = document.forms[thisForm][hideAll].value;
	var c = document.forms[thisForm][showThese];
	var tally = 0;
	// if = 0, show no_envelope; if = 1, show envelope
	var e_flag = 0;
	
	// hide all IDs in envelope
		if(a.indexOf(",") != -1) {
			var b = a.split(",");
			for (i=0; i<b.length; i++) {
				hideThis(b[i]);
			}
		} else {
			if (a != "") {
				hideThis(a);
			}
		}
	
/*
	if (c.length) {
		for (i=0; i<c.length; i++) {
			if (c[i].checked) {
				e_flag = 1;
			}
		}
	} else {
		if (c.checked) {
			e_flag = 1;
		}
	}
*/


// loop through checkbox:items, if checked show
	if (c.length) {
		for (i=0; i<c.length; i++) {
			if (c[i].checked) {
				var d = c[i].value;
				var e = d.split("|");
				showThis(e[0]);
				tally = tally + parseInt(e[1]);
				e_flag = 1;
			}
		}
	} else {
		if (c.checked) {
			var d = c.value;
			var e = d.split("|");
			showThis(e[0]);
			tally = tally + parseInt(e[1]);
			e_flag = 1;
		}
	}
	
	// write tally to total panel 
	var f = new getObj(thisTotal);

	f.obj.innerHTML = '$ '+tally;
	
	if (e_flag==1) {
		hideThis(no_env);
		showThis(env);
	} else {
		hideThis(env);
		showThis(no_env);
	}
	
}



