/*#################################################################
// (^_^) VERSION INFO /////////////////////////////////////////////
//	Version	: 2
// 	File	: site/scripts/site.js
// 	Date	: August 12, 2006 1:52 AM
//	Name	: Errol 
//	Purpose	: Utility type functions for site
// (^_^) VERSION INFO /////////////////////////////////////////////
##################################################################*/
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
// Microsoft Stupidity Check
if (ie4) {
	if((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {ie5 = true;}
	if(ns6){ns6=false;}
}

function fnValidUnP(theForm, obj){
	var msg = "";
	for (var i=theForm.length-1 ; i>=0 ; i--) {
		if ((theForm.elements[i].value == ""  || theForm.elements[i].value.length < 4) && theForm.elements[i].type != "checkbox") {
			msg += "Please enter 4 characters or more for " + theForm.elements[i].name + "\n"  ;
			theForm.elements[i].focus(); 
		}
	}
	if (msg != "") {
		window.alert("The following errors occured .. \n\n" + msg);
		return false;
	} else {
		if (obj.checked) { 
			saveCookie('username', document.forms[0].Username.value);
		}
		return true;
	}
}
//========================================================================================================//
function newWindow(pageURL, winName, settings, shouldScroll){
	var newWin, conditions, w, h;
	if(typeof(shouldScroll)=="undefined"){shouldScroll="no";}
	if((ie4)||(ie5)&&(window.showModelessDialog)){
		w=settings.substring(6,settings.indexOf(",")); h=settings.substring(settings.lastIndexOf("=")+1,settings.length);
		newWin = window.showModelessDialog(pageURL ,window, "dialogHeight:"+h+"px; dialogWidth:"+w+"px; scroll:"+shouldScroll+"; center:yes; help:no; resizable:no; status:no; unadorned:yes");// dialogLeft:20px; dialogTop:20px;
	}else{
		conditions = "toolbar=no,directories=no,status=no,scrollbars="+shouldScroll+",resizable=no,menubar=no,top=0,left=0,";//can use 
		conditions += settings;//settings will store arg of width and height
		newWin = window.open(pageURL, winName, conditions);//open the window
		newWin.focus();//set the focus to the window
	}
}//end window function
//========================================================================================================//
function normalWindow(pageURL, winName, settings, shouldScroll){
	var newWin, conditions, w, h;
	if(typeof(shouldScroll)=="undefined"){shouldScroll="no";}
	conditions = "toolbar=no,directories=no,status=yes,scrollbars="+shouldScroll+",resizable=no,menubar=no,top=0,left=0,";//can use 
	conditions += settings;//settings will store arg of width and height
	newWin = window.open(pageURL, winName, conditions);//open the window
	newWin.focus();//set the focus to the window
}//end window function

//========================================================================================================//
/*function normalWindow(pageURL, winName, settings){
		conditions = "toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,top=0,left=0,";//can use 
		conditions += settings;//settings will store arg of width and height
		newWin = window.open(pageURL, winName, conditions);//open the window
		newWin.focus();//set the focus to the window
}*/
//========================================================================================================//
function bookmark(){
	if(document.all){window.external.AddFavorite(parent.location.href,parent.document.title); 
	}else{window.alert("Press Ctrl + D to bookmark this page");}
}
//========================================================================================================//
function breakFrames(){
	if (top != self){top.location.replace(self.location.href.toLowerCase());}
}
//========================================================================================================//
function setCookie(cookieName, cookieVal){
	expireDate = new Date(); expireDate.setYear(expireDate.getYear()+1);
	document.cookie = cookieName+"="+cookieVal+"; expires=" + expireDate.toGMTString();
}
//========================================================================================================//
function cookiesEnabled(){
	var blnFlag = false;
	if(navigator.cookieEnabled){blnFlag = true;}
	return blnFlag;
}
//========================================================================================================//
function fnReadCookie(){
	var thisCookie="", theVal=0;
	if (cookiesEnabled() && document.cookie) {
			thisCookie = document.cookie.split("; "); 
			for(var i=0;i<thisCookie.length;i++){
				if(thisCookie[i].split("=")[0]=="username"){
					theVal=thisCookie[i].split("=")[1];
					(theVal=="undefined" && typeof(document.forms[0].Username)!="undefined")? theVal=0 :document.forms[0].Username.value = theVal;document.forms[0].Password.focus();
				}
			}//end for
	}
}
//========================================================================================================//
function saveCookie (cookieName, cookieVal) {
	if (cookiesEnabled()) {
		setCookie(cookieName, cookieVal);	
	}
}
//========================================================================================================//
function fnGetTextFromSelect (obj) {
	if (obj.type == "hidden") {
		return obj.value;
	} else {
		for (var i=0; i < obj.options.length; i++) {
			if(obj.options[i].selected ) {
				return obj.options[i].text;
			}
		}
		return "";
	}
}
//========================================================================================================//
function fnGetValueFromSelect (obj) {
	if (typeof obj == "undefined" || typeof obj == null || typeof obj == "" || obj.disabled || obj == "") {
		return "";
	} else {
		if (obj.type == "hidden") {
			return obj.value;
		} else {
			for (var i=0; i < obj.options.length; i++) {
				if(obj.options[i].selected ) {
					if (obj.options[i].value == null) {
						return "";
					} else
						return obj.options[i].value;
				}
			}
			return "";
		}
	}	
}
//========================================================================================================//
function fnGetValueFromField (obj) {
	if (typeof obj == "undefined" || typeof obj == null || typeof obj == "" || obj.disabled) {
		return "";
	} else {
		return obj.value;
	}	
}
function fnWriteDiv(oDiv, tStyle, tValue) {
	if ( fnIsNullOrEmptyValue(tValue) || fnIsNullOrEmptyValue(oDiv) ) {
		//nothing to do
	} else {
		oDiv.innerHTML = "<span class=\"" + tStyle + "\">" + tValue + "</span>";
	}
}
/* _________________________________________________________________________________________________________________________________ */
//	Name 		- fnWriteDivTable ------------------------------------------------------------------------------------------------
//  Purpose		- To Build Dynamic Divs in forms
//	Args 		- oDiv(name of div)
/* ________________________________________________________________________________________________________________________________ */
function fnWriteDivTable(oDiv) {
	if ( fnIsNullOrEmptyValue(oDiv) ) {
		//nothing to do
	} else {
		if ( eval(oDiv + ".innerHTML") == "" ) {
			switch (oDiv) {
				case "dvAddressDetails" :
					dvAddressDetails.innerHTML ='<table width="100%" border="0" cellspacing="0" cellpadding="0">'
							+'<tr>'
								+'<td class="tdGreyAndBlue" colspan="4"><span class="spnSpacedHeading">Address:</span></td>'
							+'</tr>'
							+'<tr>'
								+'<td width="130" class="tdGreyAndBlue">Street address</td>'
								+'<td class="tdPadOnly"><input type="text" name="tStreet_Address" id="tStreet_Address" value="" class="txtStandard" /><span class="spnRequired">&nbsp;&#149;</span></td>'
								+'<td class="tdGreyAndBlue">Suburb / town</td>'
								+'<td class="tdPadOnly"><input type="text" name="tSuburb_Town" id="tSuburb_Town" value="" class="txtStandard" /><span class="spnRequired">&nbsp;&#149;</span></td>'
							+'</tr>'
							+'<tr>'
								+'<td width="130" class="tdGreyAndBlue">City</td>'
								+'<td class="tdPadOnly"><input type="text" name="tCity" id="tCity" value="" class="txtStandard" /><span class="spnRequired">&nbsp;&#149;</span></td>'
								+'<td class="tdGreyAndBlue">State</td>'
								+'<td class="tdPadOnly"><select name="tState">'
									+'<option value="">-- state/territory --</option>'
									+'<option value="VIC">Victoria</option>'
									+'<option value="NSW">New South Wales</option>'
									+'<option value="SA">South Australia</option>'
									+'<option value="WA">Western Australia</option>'
									+'<option value="QLD">Queensland</option>'
									+'<option value="ACT">Australian Capital Territory</option>'
									+'<option value="NT">Northern Territory</option>'
									+'<option value="TAS">Tasmania</option>'
								+'</select><span class="spnRequired">&nbsp;&#149;</span></td>'
							+'</tr>'
							+'<tr>'
								+'<td width="130" class="tdGreyAndBlue">Postcode</td>'
								+'<td class="tdPadOnly"><input type="text" name="tPostcode" id="tPostcode" value="" class="txtStandard" maxlength="4" /><span class="spnRequired">&nbsp;&#149;</span></td>'
								+'<td class="tdGreyAndBlue">Phone/mobile</td>'
								+'<td class="tdPadOnly"><input type="text" name="tPhone_Mobile" id="tPhone_Mobile" value="" class="txtStandard" /><span class="spnRequired">&nbsp;&#149;</span></td>'
							+'</tr>'
						+'</table>';
					break ;
				default :
					//
			}
		} else {
			fnClearDiv(oDiv);
		}
	}
}
/* _________________________________________________________________________________________________________________________________ */
//	Name 		- fnClearDiv ------------------------------------------------------------------------------------------------
//  Purpose		- To Clear Dynamic Divs in forms
//	Args 		- oDiv(name of div)
/* ________________________________________________________________________________________________________________________________ */
function fnClearDiv(oDiv){
	if ( fnIsNullOrEmptyValue(oDiv) ) {
		//nothing to do
	} else {
		eval(oDiv + ".innerHTML = ''") ;
	}
}
/* _________________________________________________________________________________________________________________________________ */
//	Name 		- fnGetLocationForModuleBySite ------------------------------------------------------------------------------------------------
//  Purpose		- Get location dependant on Module and Site
//	Args 		- url(url & qs), ctl(id for query string from select), ctl2 ditto
/* ________________________________________________________________________________________________________________________________ */
function fnGetLocationForModuleBySite(url, ctl, ctl2) {
	var href = "";
	var objVal = "";
	var objVal2 = "";
	objVal = fnGetValueFromSelect (ctl);
	objVal2 = fnGetValueFromSelect (ctl2);
	if (url != "" && objVal != "" ) {
		if ((!isNaN(objVal) && objVal >= 1) || (typeof(objVal)=="string" && objVal != "")) {
			href = url + objVal;
			if ((!isNaN(objVal2) && objVal2 >= 1) || (typeof(objVal2)=="string" && objVal2 != "")) {
				href += "&" + ctl2.name + "=" + objVal2;
			}
			location.href = href;		
		} else {
			return;	
		}
	} else {
		return;	
	}
}