// THIS FILE IS MIRRORED ON PAYGRO.COM - PLEASE BE SURE TO SYNC IT WHEN YOU MAKE CHANGES

function changeBG(){
 	for(var i = 1; i < arguments.length; i++)
		{	
		if(document.getElementById||(document.all && !(document.getElementById)))
			{
 		    arguments[i].style.background = "url(images/colors/" + arguments[0] + "_empty_label_frame.gif)";
			}
		}				

 }
function changeButtonBG(){
 	for(var i = 1; i < arguments.length; i++)
		{	
		if(document.getElementById||(document.all && !(document.getElementById)))
			{
 		    arguments[i].style.background = "url(images/colors/" + arguments[0] + "_empty_lf_sm.gif)";
			}
		}				

 }

function ImgSwap(img, color)
	{
	img.src ="images/nav/" + img.name + "_" + color + ".gif";
	}
	

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function checkall(runit)
	{
	if (runit)
		fldArray = new Array("frm_email","email",false,"frm_first_name","fname",false,"frm_last_name","lname",false,"frm_address_1", "blank", false,"frm_city","blank",false,"frm_state","state",false,"frm_zip","zip",false,"frm_phone","phone",false,"frm_message","blank",false);
	else
		fldArray = new Array("frm_email","email",false);
	for (x = 0; x < fldArray.length; x++)
		{
		a_obj = fldArray[x];
		x++;
		a_type = fldArray[x];
		x++;
		a_isEmptyOK = fldArray[x];
		if (!checkVal(a_obj, a_type, a_isEmptyOK))
			return false;
		}
	}

function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
	} else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	//for(i=0; i < document.layers.length; i++)
	//	{ 
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getObject(objectId);
    if(styleObject) {
	//alert(styleObject);
	styleObject.style.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	//alert ("nope");
	return false;
    }
} // changeObjectVisibility

// global error messages
var REQUIRED = "You must fill in all required information.";
var PASSWD = "Please enter a password of at least 6 characters.";
var PASS_MATCH = "Your passwords do not match.";
var EMAIL = "Please enter a valid email address.";
var BAD_PHONE = "Please enter a valid phone number.";
var F_NAME = "Please enter your first name.";
var L_NAME = "Please enter your last name.";
var STATE = "Please enter a US state in postal format.\n (i.e. CA for California)";
var ZIP = "Please enter a valid US zip code\n (i.e. 11111 or 11111-2222)";
// check form values
function checkVal(obj, type, OKifEmpty)
	{
	var str;
	var str2;
	if(obj == "passwords")
		{
		str = getObject("password");
		str2 = getObject("password2");
		}
	else
		str = getObject(obj);
	
	switch(type)
		{
		case 'blank':
			if(isWhitespace(str.value))
				{
				warnInvalid(str, "Please enter a value.");
				return false;
				}
			else
				return true;
			break;
		case 'school':
			if(isWhitespace(str.value))
				{
				warnInvalid(str, "Please enter the name of your School, City/Community or Child Care Facility");
				return false;
				}
			else
				return true;
			break;
		case 'contest':
			if(isWhitespace(str.value))
				{
				warnInvalid(str, "Please enter an essay of no more than 200 words.");
				return false;
				}
			else
				return true;
			break;
		case "state":
			if(isEmpty(str.value))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, STATE);
					return false;
					}
				break;
				}	
			else if(!isStateCode(str.value.toUpperCase()))
				{
				warnInvalid(str, STATE);
				return false;
				}
			else
				str.value=str.value.toUpperCase();
				return true;
			break;
		case "zip":
			var zip = stripCharsNotInBag (str.value, digits);
			if(isEmpty(zip))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, ZIP);
					return false;
					}
				break;
				}	
			else if(!isZIPCode(zip))
				{
				warnInvalid(str, ZIP);
				return false;
				}
			else
				{
				str.value = reformatZIPCode (zip);
				return true;
				}
			break;
		case "password":
			if(isWhitespace(str.value))
				{
				warnInvalid(str, PASSWD);
				return false;
				}
			else if(!isCorrectSize(str.value, 6, 10))
				{
				warnInvalid(str, PASSWD);
				return false;
				}
				else if(str.value != str2.value)
					{
					warnInvalid(str, PASS_MATCH);
					return false;
					}
				else	
					{
					return true;
					}
				break;
		
		case "email":
			var email = str.value;
			if(isEmpty(email))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, EMAIL);
					return false;
					}
				break;	
				}	
			else if(!isEmail(email))
					{
					warnInvalid(str, EMAIL);
					return false;
					}
				else
					{
					return true;
					}
				break;
		
		case "phone":
			var phone_num = stripCharsNotInBag (str.value, digits);
			if(isEmpty(phone_num))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, BAD_PHONE);
					return false;
					}
				}	
			else if(!isUSPhoneNumber(phone_num))
				{
				//alert(phone_num);
				warnInvalid(str, BAD_PHONE);
				return false;
				}
			else
				{
				str.value = reformatUSPhone (phone_num)
				return true;
				}
			break;
		
		case "fname":
			if (isEmpty(str.value))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, F_NAME);
					return false;
					}
				break;
				}	
			else if (isWhitespace(str.value))
				{
				warnInvalid(str, F_NAME);
				return false;
				}
			else
				return true;
			break;
		case "lname":
			if (isEmpty(str.value))
				{
				if(OKifEmpty)
					{
					return true;
					}
				else
					{
					warnInvalid(str, L_NAME);
					return false;
					}
				}	
			else if (isWhitespace(str.value))
				{
				warnInvalid(str, L_NAME);
				return false;
				}
			else
				return true;
			break;
		
		default:
			break;
		}
	}

// blank all text fields in a form
 function clearForm(formid)
	{
	formid = getObject(formid);
	formid.reset();
	/*for(i=0; i<formid.elements.length; i++)
		{
		if(formid.elements[i].type == "text" || formid.elements[i].type == "password")
			formid.elements[i].value = "";
		}
	*/
	}

///////////////////////////////////////////////////////
var csec2 = 15;
var images = new Array(8);
var cameras = new Array(1,9,3,4,2,6,15,16);
var count = 0;
function DownRepeat() 
	{
	if(count == 0)
		{
		rfsh = new Date();
    	          rfsh = "?" + rfsh.getTime();		
		image = new Image();
		
	//	document.Paygro1.src = image.src;
	for(i=0; i<8; i++)
			{
			image.src = "http://www.garick.com/cameras/Paygro" + cameras[i] + "/Paygro" + cameras[i] + "_00001.jpg" + rfsh;
			var img = eval("document.Paygro" + cameras[i]);
			img.src = image.src
			}
	}        
	if(csec2 == 7)
	   {
	    rfsh = new Date();
       	 rfsh = "?" + rfsh.getTime();
        for(i=0; i<8; i++)
			{
	   	 images[i] = new Image();
		 images[i].src = "http://www.garick.com/cameras/Paygro" + cameras[i] + "/Paygro" + cameras[i] + "_00001.jpg" + rfsh;
	  		}
	   }
	if(csec2 == 0)
	   {
	//   document.Paygro1.src = images[0].src;
	 //	alert(document.Paygro1.src);
	 for(i=0; i<8; i++)
			{
			var image = eval("document.Paygro" + cameras[i]);
			image.src = images[i].src;
			}
	 
	   }
	csec2--; 
	if(csec2 == -1)
	   {
	   csec2 = 15;
	   setTimeout("DownRepeat()", 1000);
	   }
	else
	   {
	   setTimeout("DownRepeat()", 1000);
	   }
count++;	
}
function GetLiveCam(camera)
	{
	URL = "http://www.garick.com/main.php/paygro_cameras?cam=" + camera;
	popUp(URL);
	}
function popUp(URL,width,height,scrolling) {

day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars="+scrolling+",location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+"+,left = 125,top = 60');");
}




function isBlank(varString) {
	var boolStringIsBlank = true
	var intI

	if(varString) {
		for(intI=0; intI < varString.length; intI++) {
			if(varString.charAt(intI) != " ") {
				boolStringIsBlank = false
				break
			}
		}
	}
	return boolStringIsBlank
}

function doCalc() {
	var boolPerform = true
	var strMsg
	var intDepth
	var intArea
	var sngResult

	if(isBlank(document.MulchCalc.thickness.value)) {
		boolPerform = false
		strMsg = "Thickness is required."
		document.MulchCalc.thickness.focus()
	}

	if(boolPerform)
		if(isBlank(document.MulchCalc.area.value)) {
			boolPerform = false
			strMsg = "Total Area is required."
			document.MulchCalc.area.focus()
		}
	if(boolPerform) {
		intDepth = document.MulchCalc.thickness.value
		intArea = document.MulchCalc.area.value

		// The following comments relate to the calculation that follows them:
		// Multiply area by 144 to convert to square inches.
		// Assume 46656 cubic inches to the cubic yard...
		//	27 cubic feet per cubic yard
		//	x 1728 cubic inches per cubic foot
		//	= 46656 cubic inches per cubic yard
		// Before rounding, multiply by 100 (144 becomes 14400) to preserve 2 decimal positions.
		// After rounding, divide by 100 to restore the 2 decimal positions.

		sngResult = Math.round((intDepth * intArea * 14400) / 46656) / 100
		document.MulchCalc.Total.value = sngResult
	}

	else

		alert(strMsg)
}



/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Oct 21st, 2003.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
/*
var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined")
revivecontent()
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

*/