// Eonic Ltd

/*
 * Handlers for automated loading
 */ 

 _LOADERS = Array();

function callAllLoaders() {
	var i, loaderFunc;
	for(i=0;i<_LOADERS.length;i++) {
	loaderFunc = _LOADERS[i];
		if(loaderFunc != callAllLoaders) loaderFunc();
	}
}

function appendLoader(loaderFunc) {
	if(window.onload && window.onload != callAllLoaders)
		_LOADERS[_LOADERS.length] = window.onload;

	window.onload = callAllLoaders;
	_LOADERS[_LOADERS.length] = loaderFunc;
}

_UNLOADERS = Array();

function callAllUnLoaders() {
	var i, loaderFunc;
	for(i=0;i<_UNLOADERS.length;i++) {
	unloaderFunc = _UNLOADERS[i];
		if(unloaderFunc != callAllUnLoaders) unloaderFunc();
	}
}

function appendUnLoader(unloaderFunc) {
	if(window.onunload && window.onunload != callAllUnLoaders)
		_UNLOADERS[_UNLOADERS.length] = window.onunload;

	window.onunload = callAllUnLoaders;
	_UNLOADERS[_UNLOADERS.length] = unloaderFunc;
}


// Wellards specific
function showTimer() {
	/* Note - this is just a clientside countdown of what is being maintained from the server end */
	/* The quiz/exam server does not rely on this to run the timer */
	var dy = document.getElementById("time_d");
	var h = document.getElementById("time_h");
	var m = document.getElementById("time_m");
	var s = document.getElementById("time_s");
	var nd,nh,nm,ns;

	var d = Date();
	var udMSSecond = 1000;
	
	var nSecsPassed = nTimeSecs - Math.floor((Date.parse(d)-Date.parse(dDateOriginal))/udMSSecond);
	
	nd = Math.floor(nSecsPassed/86400);
	nh = Math.floor((nSecsPassed%86400)/3600);
	nm = Math.floor((nSecsPassed%3600)/60);
	ns = Math.floor(nSecsPassed%60);
	
	if (dy!=undefined) {dy.innerHTML=nd;}
	if (h!=undefined) {h.innerHTML=nh;}
	if (m!=undefined) {m.innerHTML=nm;}
	if (s!=undefined) {s.innerHTML=ns;}
	if (nd<=0 && nh<=0 && nm<=0 && ns<=0) {
		alert('The time limit has been reached.\n Press OK to Finish the Quiz.');
		var oHInput = document.createElement("input")
		oHInput.type="hidden"
		oHInput.name="qmCmd"
		oHInput.value="Out of Time"
		document.forms[0].appendChild(oHInput)
		document.forms[0].submit();
	} else {
		setTimeout('showTimer()',1000)
	}
}

function showClearForm(formName,link) {
	document.getElementById('tr_'+formName).style.display='block'; 
	link.style.display='none';
	document.getElementById('button_' + formName).focus();
	return false;
}

function toggle(obj) {

	if (obj.style) {
		obj.style.display = (obj.style.display!="block" ||  obj.style.display=="") ?  "block" : "none" 
	}

}
// Common functions
var lockmenu = 0;
var menuNode;

function adminMenu(elmnt,condn){

	var oPop = document.getElementById("popup_menu")
	var nGutter = 4

	switch (condn) {
		case "on":
			if (lockmenu == 0){
	
				// Get the menu we wish to clone.  Display it briefly to get it's positional information
				var oUL = getChildUL(elmnt)
				oUL.style.display = "block";				

				var nL = getLeft(oUL) 		
				var nT = getTop(oUL)
				var nH = oUL.clientHeight
				var nW = oUL.clientWidth
				var nB = nT + nH;
				var nR = nL + nW;
				oUL.style.display = "none";
				var sB = getVisHeight() + getScrollTop();
				var sR = getVisWidth() + getScrollLeft();				

				if (nB > sB) { nT = sB - nH - nGutter }
				if (nR > sR) { nL = sR - nW - nGutter }
				
				// Transfer the inner HTML and position to our popup menu
				oPop.innerHTML = oUL.innerHTML 

				
				// Display the popup menu
				oPop.className+=" overpop";
				
				// Adjust the positioning (accounts for the exact rendering of the popup div, in case it's different from the cloned UL), 
				// hence we only re-adjust once the popup is visible
				nL = getLeft(elmnt) + getWidth(elmnt) - getWidth(oPop) - nGutter
				nH = oPop.clientHeight
				nW = oPop.clientWidth
				nB = nT + nH;
				nR = nL + nW;
				
				if (nB > sB) { nT = sB - nH - nGutter  }
				if (nR > sR - nGutter) { nL = sR - nW - nGutter }
								
				oPop.style.top=nT + "px"
				oPop.style.left=nL + "px"
			}
		break	
		case "off":
			if (lockmenu == 0){
				oPop.className = oPop.className.replace(' overpop','');
			}
		break
		case "onMenu":
			lockmenu = 1;		
			oPop.className+=" overpop";
		break
		
		case "offMenu":
			lockmenu = 0;
			oPop.className = oPop.className.replace(' overpop','');
		break
	}
}

function getChildUL(obj) {
	for (i=0; i<obj.childNodes.length; i++){
		child = obj.childNodes[i]
		if (child.className != null) {
			if (child.className.indexOf("inlinePopupLabel") >= 0){
				for (j=0; j<child.childNodes.length; j++){
					if (child.childNodes[j].nodeName=="UL") { return child.childNodes[j];break;}
				}
			}
		}
	}
}

function divSwitch(parentContainerId,activeId) {

	parentContainer = document.getElementById(parentContainerId)
	children = parentContainer.getElementsByTagName("div")
	activeId = document.getElementById(activeId)
	
	// hide all the children of the parent container
	for (var i = 0; i < children.length; i++) 
	{
	    if (children[i].id != 'imageDescription'){
		    children[i].style.display = "none";
		}
	}

	// show the activeId
	activeId.style.display = "block";
}

function gallerySwitch(imgName,imgSrc,nWidth,nHeight,cCaption){
	var img = document.images["pic"]
	var cap = document.getElementById("imgCaption")
	
	// Change the img
	img.src = imgSrc;
	img.width = nWidth
	img.height = nHeight
	
	// Change the caption
	// cap.firstChild.nodeValue = cCaption

}

function getAppVersion() {
	appname= navigator.appName;
	appversion = navigator.appVersion;
	majorver = appversion.substring(0, 1);
	if ( (appname == "Netscape") && ( majorver >= 3 ) ) return 1;
	if ( (appname == "Microsoft Internet Explorer") && (majorver >= 4) ) return 1;
	return 0;
}



function loadImageArray() {
		if (getAppVersion()) {
		img = new Array();
		for (i = 0; i < imgsrc.length; i++) {
			img[i] = new Image();
			img[i].src = imgsrc[i];
		}
	}
}

function loadImageArray2() {
		if (getAppVersion()) {
		img2 = new Array();
		for (i = 0; i < imgsrc2.length; i++) {
			img2[i] = new Image();
			img2[i].src = imgsrc2[i];
		}
	}
}

function loadImageArray3() {
		if (getAppVersion()) {
		img3 = new Array();
		for (i = 0; i < imgsrc3.length; i++) {
			img3[i] = new Image();
			img3[i].src = imgsrc3[i];
		}
	}
}

function setHome(arg, urlName){
	
if(navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE") + 5) >= 5 && navigator.platform.indexOf("Win16") == -1 
 && navigator.platform.indexOf("Mac") == -1){
 		arg.style.behavior='url(#default#homepage)';
 		arg.setHomePage(urlName);
 		arg.href="#";
 		return true;
 	}
 	else {return false}
}

function swtch(num, imgname) {
	if (getAppVersion()) {
		document[imgname].src = img[num].src;
	}
}

function swtch2(num, imgname) {
	if (getAppVersion()) {
		document[imgname].src = img2[num].src;
	}
}

function swtch3(num, imgname) {
	if (getAppVersion()) {
		document[imgname].src = img3[num].src;
	}
}

function arrayStep(num, dir, imgname) {
	if (getAppVersion()) {
	
	if (dir=="next"){
		if (imgpos==img.length-1){
			imgpos=1
		}
		else {
			imgpos=num+1;
			}
		}
	else	{
		if (imgpos<=1){
			imgpos=img.length-1;
		}
		else{
			imgpos=num-1;
		}
	}

	document[imgname].src = img[imgpos].src;
	}
}

function rollover(imgpath,imgName) {
	var newSrc = imgpath + "_ov.gif"
	document.images[imgName].src = newSrc
}

function imgReplace(imgpath,imgName) {
	var newSrc = imgpath
	document.images[imgName].src = newSrc
}

function rollout(imgpath,imgName) {
	var newSrc = imgpath + ".gif"
	document.images[imgName].src = newSrc
}

function OpenWindow(theURL,winName,features) { 
//featureStr = 'toolbar=yes,scrollbars=yes,resize=yes,location=no,menubar=yes,width=700,height=560' 
  featureStr = features;
  
 // these lines make the pickImage facility work in firefox, every other time?? 
 // theURL = unescape(theURL);
 //theURL=theURL.replace('&amp;',/\&/g).replace('&amp;',/\&/g).replace('&amp;',/\&/g).replace('&amp;',/\&/g).replace('&amp;',/\&/g);
  
  opener = window.open(theURL,winName,featureStr);
  opener.focus();
}

function openWindow350450(theURL,winName) { 
	featureStr = 'toolbar=no,scrollbars=yes,resize=no,location=no,menubar=no,width=350,height=450' 
 // featureStr = features;
  opener = window.open(theURL,winName,featureStr);
}

function openWindow600600(theURL,winName) { 
	featureStr = 'toolbar=no,scrollbars=yes,resize=no,location=no,menubar=no,width=600,height=600' 
 // featureStr = features;
  opener = window.open(theURL,winName,featureStr);
}

function openWindow600600Resize(theURL,winName) { 
	featureStr = 'toolbar=no,scrollbars=yes,resize=yes,location=no,menubar=no,width=600,height=600' 
 // featureStr = features;
  opener = window.open(theURL,winName,featureStr);
}

 function showHideExplorer(){
  if(document.body) var iWidth = document.body.clientWidth;
  if(iWidth > 950) 
		{
		document.getElementById('explorerSpan').style.display = "";
		
		
		}
		else
		{
			 document.getElementById('explorerSpan').style.display = 'none';
		}
 }

function makedate(formName,dateField){
	var dayval;
	
	if ("undefined" == typeof(document.forms[formName].elements['day_' + dateField])) {
		dayval = '01';
	} else {
		dayval = document.forms[formName].elements['day_' + dateField].value
	}
	document.forms[formName].elements[dateField].value = dayval + " " + document.forms[formName].elements['month_' + dateField].value + " " + document.forms[formName].elements['year_' + dateField].value;
}

function loaddate(formName,dateField){
   dateStr = document.forms[formName].elements[dateField].value
   dateArr = dateStr.split(" ",4)
   
    document.forms[formName].elements['day_' + dateField].value = dateArr[0]
    document.forms[formName].elements['month_' + dateField].value = dateArr[1]
    document.forms[formName].elements['year_' + dateField].value = dateArr[2]
    // alert(document.forms[formName].elements['month_' + dateField].selectedIndex)
}


// XML DATE VARIANTS
function makeXmlDate(formName,dateField){
	var f = document.forms[formName]
	var dayval;
	
	if ("undefined" == typeof(f.elements['day_' + dateField])) {
		dayval = '01';
	} else {
		dayval = f.elements['day_' + dateField].value
	}
	
	f.elements[dateField].value = f.elements['year_' + dateField].value + "-" + f.elements['month_' + dateField].value + "-" + dayval;
	//alert(f.elements[dateField].value)
}

function loadXmlDate(formName,dateField){
	var f = document.forms[formName]
		
   dateStr = f.elements[dateField].value
   dateArr = dateStr.split("-",4)
   
    f.elements['day_' + dateField].value = dateArr[2].substr(0,2)
    f.elements['month_' + dateField].value = dateArr[1]
    f.elements['year_' + dateField].value = dateArr[0]
    // alert(document.forms[formName].elements['month_' + dateField].selectedIndex)
}

function makedatemmyy(formName,dateField){
	document.forms[formName].elements[dateField].value = document.forms[formName].elements['month_' + dateField].value + " " + document.forms[formName].elements['year_' + dateField].value;
}

function loaddatemmyy(formName,dateField){
   dateStr = document.forms[formName].elements[dateField].value
   dateArr = dateStr.split(" ",4)
   
    document.forms[formName].elements['month_' + dateField].value = dateArr[0]
    document.forms[formName].elements['year_' + dateField].value = dateArr[1]
    // alert(document.forms[formName].elements['month_' + dateField].selectedIndex)
}


// Links dropdown
function getSelect(s) {
  return s.options[s.selectedIndex].value
}

// --------------------------------- Date and Time ----------------------------------

function screenDate(){
// Store the date in a variable
d = new Date()
dateText = ""

// Get the current day and convert it to the name of the day
dayValue = d.getDay()
if (dayValue == 0)
    dateText += "Sunday"
else if (dayValue == 1)
    dateText += "Monday"
else if (dayValue == 2)
    dateText += "Tuesday"
else if (dayValue == 3)
    dateText += "Wednesday"
else if (dayValue == 4)
    dateText += "Thursday"
else if (dayValue == 5)
    dateText += "Friday"
else if (dayValue == 6)
    dateText += "Saturday"

// Get the current month and convert it to the name of the month
monthValue = d.getMonth()
dateText += " "
if (monthValue == 0)
    dateText += "January"
if (monthValue == 1)
    dateText += "February"
if (monthValue == 2)
    dateText += "March"
if (monthValue == 3)
    dateText += "April"
if (monthValue == 4)
    dateText += "May"
if (monthValue == 5)
    dateText += "June"
if (monthValue == 6)
    dateText += "July"
if (monthValue == 7)
    dateText += "August"
if (monthValue == 8)
    dateText += "September"
if (monthValue == 9)
    dateText += "October"
if (monthValue == 10)
    dateText += "November"
if (monthValue == 11)
    dateText += "December"

// Get the current year; if it's before 2000, add 1900
if (d.getYear() < 2000) 
    dateText += " " + d.getDate() + ", " + (1900 + d.getYear())
else 
    dateText += " " + d.getDate() + ", " + (d.getYear())

// Get the current minutes
minuteValue = d.getMinutes()
if (minuteValue < 10)
    minuteValue = "0" + minuteValue

// Get the current hours
hourValue = d.getHours()

// Customize the greeting based on the current hours
if (hourValue < 12)
    {
    greeting = "Good morning!"
    timeText = " - " + hourValue + ":" + minuteValue + " AM"
    }
else if (hourValue == 12)
    {
    greeting = "Good afternoon!"
    timeText = " - " + hourValue + ":" + minuteValue + " PM"
    }
else if (hourValue < 17)
    {
    greeting = "Good afternoon!"
    timeText = " - " + (hourValue-12) + ":" + minuteValue + " PM"
    }
else
    {
    greeting = "Good evening!"
    timeText = " - " + (hourValue-12) + ":" + minuteValue + " PM"
    }
// Write the greeting, the date, and the time to the page
// document.write(greeting + " It's " + dateText + timeText)
document.write(dateText + timeText)
}

var i=0
var intHide
var intShow

function ewShowMenu(elmnt)
{
//alert(elmnt);
document.getElementById(elmnt).style.visibility="visible"
//clearInterval(intHide)
//intShow=setInterval("show("+ elmnt +")",10)
}
function ewHideMenu(elmnt)
{
document.getElementById(elmnt).style.visibility="hidden"
//clearInterval(intShow)
//intHide=setInterval("hide("+ elmnt +")",10)
}

function ewShow(elmnt)
{
if (i>-100)
	{
	i=i-1
	document.getElementById(elmnt).style.bottom=i
	}
}

function ewHide(elmnt)
{
if (i<0)
	{
	i=i+1
	document.getElementById(elmnt).style.bottom=i
	}
}

  function areyousure(qText,link){
     var agree = false;
     agree = confirm(qText);
     if(agree){
      location=link
       }
    }
    
    
 

//define objects for the main list
function ListItem(nvalue,description){
        //function for defining the elements of the main list
        this.nvalue=nvalue;
        this.description=description;
}

//define objects for the dependent list
function ListSubItem(category,nvalue,description){
        //function for defining the elements of the sublists
        this.category=category;
        this.nvalue=nvalue;
        this.description=description;
}


function reFillList(formName,mainlist,sublist,ArrList){
 var selValue;
 var nOption;
 selValue=document.forms[formName].elements[mainlist][document.forms[formName].elements[mainlist].selectedIndex].value;
 
 // clear the actual list by setting its length to 0
 document.forms[formName].elements[sublist].length=0
 document.forms[formName].elements[sublist].options[0]=new Option('Please Select','0');
 for (var i=0; i < ArrList.length;i++){
        //fill the box with the values corresponding to
        //the category in the first box
       //alert(ArrList[i].category + " - " + selValue + "(" + mainlist + ")")
        if (Number(ArrList[i].category)==Number(selValue)) {
                nOption=document.forms[formName].elements[sublist].length;
                document.forms[formName].elements[sublist].options[nOption]=new Option(ArrList[i].description,ArrList[i].nvalue);
        }
 }
 document.forms[formName].elements[sublist].options[0].selected=true;
}

function reFillList1(){
 var selValue;
 var nOption;
 selValue=document.form1.sublist[document.form1.sublist.selectedIndex].value;
 //alert("Selected value=" +selValue);
 // clear the actual list by setting its length to 0
 document.form1.sublist1.length=0
 for (var i=0; i < SubList1.length;i++){
        //fill the box with the values corresponding to
        //the category in the first box
        if (SubList1[i].category==selValue) {
                nOption=document.form1.sublist1.length;
                document.form1.sublist1.options[nOption]=new Option(SubList1[i].description,SubList1[i].nvalue);
        }
 }
 document.form1.sublist1.options[0].selected=true;
 return;
}

function clearList(formname,ddName){

	//alert("options - " + document.forms[formname].elements[ddName].options.length)
	document.forms[formname].elements[ddName].options.length = 0
	return;
}

function populate(sId,formname,biglist) {
	//find sId in lowest level -- levels below are length = 0 or please select
	var sLevel;
	var nOptionIndex;
	var arr = new Array(0,0,0,0);
	var nId = document.forms[formname].elements[sId].value;
	for (var i=2;i >= 0;i--){
		for(var j=0;j < biglist[i].length;j++){
//			alert(i + ',' + j + '> ' + biglist[i][j].nvalue + ' == ' + nId + ' ?');
			if (Number(nId) == Number(biglist[i][j].nvalue)) {
//			alert('hiya');
				arr[i]= biglist[i][j].nvalue;
				nId = biglist[i][j].category;
				j = biglist[i].length;
			}
		}
	}
	//here we have our values for each of the 4 levels
	// just need to 'select' the right option in each 
	//alert( 'PgId is' + sId + 'array is...' + arr[0] + ',' + arr[1] + ',' + arr[2] + ',' + arr[3]);
	for (var i=0;i<3;i++){
		
		sLevel = 'level_' + (i + 1) + '_' + sId;
		nOptionIndex = 0;
	//alert(sLevel);
	//	alert(i+':'+ document.forms[formname].elements[sLevel].options.length);
		for (j=0;j<document.forms[formname].elements[sLevel].options.length;j++) {
	//		alert(j+' == ' + arr[i]);
			if (Number(document.forms[formname].elements[sLevel].options[j].value) == Number(arr[i])) {
				nOptionIndex = j;
				j = document.forms[formname].elements[sLevel].options.length;
			}
		}
		
		document.forms[formname].elements[sLevel].selectedIndex = nOptionIndex;
		//alert(i + '> selected ' + nOptionIndex);
		if (i < 2) {
			sLevelNext = 'level_' + (i + 2) + '_' + sId;
			reFillList(formname,sLevel,sLevelNext,biglist[i+1])
		}
	}
	return;
}

function setsId(formname,sId) {
	var sListName;
	var sLink;
	sLink = '';
	for (var i=3; i > 0;i--){
		sListName='level_' + i + '_' + sId;
	//	alert(sListName);
		if (document.forms[formname].elements[sListName].length!=0) {
			selValue=document.forms[formname].elements[sListName][document.forms[formname].elements[sListName].selectedIndex].value;
	//		alert('selValue=' + selValue + ',i=' + i);
			if (selValue!='0') {
				i=0;
				document.forms[formname].elements[sId].value = selValue;
			}
		} 
		//alert(document.forms[formname].elements[sId].value);
	}
	return;
}

function tmpsetsId(formname,sId) {
	var sListName;
	var sLink;
	sLink = '';
	for (var i=4; i > 0;i--){
		sListName='level_' + i + '_' + sId;
		alert(sListName);
		if (document.forms[formname].elements[sListName].length == 0) {
		} else {
			selValue=document.forms[formname].elements[sListName][document.forms[formname].elements[sListName].selectedIndex].value;
			sLink += '>';
			sLink += selValue;
		}
	}
	document.forms[formname].elements[sId].value = sLink
	return;
}



function checkvalues(){
//show the selected values
        var val1;
        var val2;
		var val3;
        var cString;
        val1=document.form1.mainlist[document.form1.mainlist.selectedIndex].value;
        val2=document.form1.sublist[document.form1.sublist.selectedIndex].value;
		val3=document.form1.sublist1[document.form1.sublist1.selectedIndex].value;
        cString="Main List=value:" + val1 + "-Description:"+MainList[val1].description
        cString+="\n"
        cString+="Sub List=value:" + val2+ "-Description:"+SubList[val2].description
        cString+="\n"
        cString+="Sub List1=value:" + val3+ "-Description:"+SubList1[val3].description

        alert(cString);
}   

function setEditableDropdown(editfield,formName,fieldName){
//show the selected values
        var lastIndex;
        lastIndex = document.forms[formName].elements[fieldName].options.length - 1;      
        document.forms[formName].elements[fieldName].options[lastIndex].selected=true;
        document.forms[formName].elements[fieldName][document.forms[formName].elements[fieldName].selectedIndex].value = editfield.value      
}


// Admin function for Shipping Options Valid Regions List
function checkShippingLocationsForm(oCurrent) {
	toggleShipLocList(oCurrent.parentNode, oCurrent.checked, true)
}

function toggleShipLocList(oLI, bChecked, bIsTopLevel) {
	
	var oChildren, oChild, oListChildren, i, j, bCheckbox
	
	// Check the children, if they exist
	oChildren = oLI.childNodes
	bCheckbox = false
	for(i=0;i<oChildren.length;i++){
		oChild = oChildren.item(i)
		if (oChild.nodeName == 'SPAN' && !bIsTopLevel) { (bChecked)?oChild.className = 'locationName locationDisabled':oChild.className = 'locationName' }		
		if (oChild.type == 'checkbox' && !bIsTopLevel) { oChild.disabled = bChecked; bCheckbox = oChild.checked;}
		if (oChild.nodeName == 'UL') { 
		    oListChildren = oChild.childNodes
		    for(j=0;j<oListChildren.length;j++){
				toggleShipLocList(oListChildren.item(j), (bChecked || bCheckbox), false)
			}
		}
	}
	
}

function setupShipLocUL(oUL) {
	var oChildren, oChild
	// Check the children LIs
	oChildren = oUL.childNodes
	for(i=0;i<oChildren.length;i++){
		oChild = oChildren.item(i)
		if (oChild.nodeName == 'LI') { setupShipLocList(oChild, false) }
	}
}

function setupShipLocList(oLI, bChecked) {
	
	var oChildren, oChild, oListChildren, i, j, bParCheck
	
	// Check the children, if they exist
	oChildren = oLI.childNodes
	bParCheck = bChecked
	for(i=0;i<oChildren.length;i++){
		oChild = oChildren.item(i)
		if (oChild.nodeName == 'SPAN') { (bChecked)?oChild.className = 'locationName locationDisabled':oChild.className = 'locationName' }		
		if (oChild.type == 'checkbox') { 
			oChild.disabled = bChecked; 
			if (!bParCheck) {bParCheck = oChild.checked}
		}
		if (oChild.nodeName == 'UL') {			
		    oListChildren = oChild.childNodes
		    for(j=0;j<oListChildren.length;j++){
				setupShipLocList(oListChildren.item(j), bParCheck)
			}
		}
	}
	
}

//validate forms, checking that all required fields/options have been specified
function validate(oForm)
{
	emailAdd=oForm.sEmail.value.indexOf("@");
//	txt=oForm.txt.value;
	submitOK="True";
	
	if (oForm.sCompany.value=="")
	{
		alert("Please enter your Company");
		submitOK="False";
	}

	if (emailAdd==-1) 
	{
		alert("Please enter a valid e-mail address");
		submitOK="False";
	}

	if (submitOK=="False")
	{
		return false;
	}
}

function formReset(oForm)
{
	oForm.reset()
}

function form_check_old(oForm) {
	return true;
}

var disableButtonMessage = "Please Wait..."

function disableButton(oBtn,disableMessage) {
	
	var oElem,i;
	var oForm = oBtn.form
	if (disableMessage)
	{
    disableButtonMessage = disableMessage
    }
	// Create a hidden input field spoofing the information of the submit button
	var oNewElem = document.createElement('input')
	oNewElem.type = 'hidden'
	oNewElem.id = 'ewSubmitClone_' + oBtn.id
	oNewElem.name = 'ewSubmitClone_' + oBtn.name
	oNewElem.value = oBtn.value
	oForm.appendChild(oNewElem)

}

function form_disable_button(oForm,btnID,btnName) {
	for (i=0; i<oForm.length;i++ ) {
		oElem = oForm.elements[i];
		if (oElem.id==btnID && oElem.name==btnName){
			oElem.id+='_old'
			oElem.name+='_old'
			oElem.value = disableButtonMessage
		}	
	}
}

function form_check(oForm) {
	var oElem, i,bValid,cCheckRadio,cTestName,oOptions,bSelected, nElemTypeGroup, cId, cName;
	var aRadioCheck = new Array();
	var bHasDisabledButton = false
	bValid = true;
	
	
	for (i=0; i<oForm.length;i++ ) {
		oElem = oForm.elements[i]
		
		switch (oElem.type) {
			case "text": nElemTypeGroup = 1; break;
			case "textarea": nElemTypeGroup = 1; break;
			case "checkbox": nElemTypeGroup = 3; break;
			case "radio": nElemTypeGroup = 3; break;
			case "select-one": nElemTypeGroup = 2; break;
			case "select-multiple": nElemTypeGroup =2; break;
			default: nElemTypeGroup = 0; break;
		}
		
		// Check if the element is required
		if (oElem.className.toLowerCase().indexOf("required")>=0) {
			switch (nElemTypeGroup) {

				case 1:
				    if (form_check_value(oElem.value)) {
						form_alert("required",oElem)
						bValid = false
					}
					break;
				case 2: 
					if (oElem.selectedIndex < 0) {
						form_alert("required",oElem)
						bValid = false						
					}
					else if (form_check_value(oElem.options[oElem.selectedIndex].text)) {
						form_alert("required",oElem)
						bValid = false					
					}
					break;					
				case 3:
					// Check if the checkbox group has already been checked through
					cCheckRadio = "," + aRadioCheck.join(",") + ","
					cTestName = "," + oElem.name + ","
					if (cCheckRadio.indexOf(cTestName)<0) {
						
						// Not found - let's do the checks
						aRadioCheck.push(oElem.name)
						oOptions = document.getElementsByName(oElem.name)
						bSelected = false;
						if (oOptions.length>1) {
							for (i=0; i<oOptions.length;i++) { if(oOptions[i].checked) { bSelected = true; break } }
						}
						if (!bSelected && oOptions.length>1) {
							form_alert("required",oElem)
							bValid = false	
						}
					}
					break;		
			}
			if (!bValid) { break }
		}
	}
	
	if (bValid) {
		for (i=0; i<oForm.length;i++ ) {
			oElem = oForm.elements[i]		
			if (oElem.type == 'text' ||  oElem.type == 'textarea') {
				if (form_check_value(oElem.value)) {oElem.value = '';}
			}
		}
	}
	
	if (bValid) {
		// Check for Disabled Buttons
		for (i=0; i<oForm.length;i++ ) {
			oElem = oForm.elements[i];
			if (oElem.type=="hidden" && oElem.id.indexOf("ewSubmitClone_")==0) {
				cId = oElem.id.replace(/ewSubmitClone_/,"")
				cName = oElem.name.replace(/ewSubmitClone_/,"")
				form_disable_button(oForm,cId,cName)
				oElem.id=cId
				oElem.name=cName
				bHasDisabledButton = true;
			}
		}
		
		if (bHasDisabledButton) {
			for (i=0; i<oForm.length;i++ ) {
				oElem = oForm.elements[i];
				if (oElem.type=="submit" || oElem.type=="button") {oElem.disabled=true;}
			}
		}	
	}
	
	return bValid;
}

function form_alert(cAlertType,oElem) {

	var cLabel
	// Get the label	
	cLabel = form_get_label(oElem)
	switch (cAlertType) {
	
		case "required":
			if (cLabel=="") {
				alert("You must complete all the required information")
			}
			else {
				alert("You have not any information in the field : " + cLabel)
			}
			oElem.focus()
			break;
	}
}


function form_get_label(oElem) {

	var cLabel, oLabels, i

	cLabel=""
	oLabels = document.getElementsByTagName("label")

	for (i=0; i<oLabels.length;i++ ) {
		if (oLabels[i].htmlFor == oElem.name) { cLabel = oLabels[i].firstChild.nodeValue; break; }
	}
	
	return cLabel;


}

function form_check_value(cValue) {

	var aKeyDefs = new Array("please enter","[please enter","[select ","please select","[please select","por favor preencha o","Svp complet")
	var bIsDefault,i
	
	bIsDefault = false
	cValue = cValue.toString()
	cValue = cValue.toLowerCase();
	for (i=0; i<aKeyDefs.length;i++ ) {
		if (cValue.substr(0,aKeyDefs[i].length).toLowerCase() == aKeyDefs[i].toLowerCase() || cValue=="") { bIsDefault = true }
	}
	
	return bIsDefault
}

function form_batch_checkbox(oForm, bChecked) {
	var oElem, i
	a = 0
	for (i=0; i<oForm.length;i++ ) {
		oElem = oForm.elements[i];
		if (oElem.type=="checkbox") {oElem.checked = bChecked;}
	} 
}

function pollCheck(o) { 
	var pVal;
	pVal = false;
	for(i=0;i<o.length; i++) {
		if (o.elements[i].type=='radio' && o.elements[i].checked) { pVal = true; }
	}
	if (!pVal) {alert('You have not selected anything to vote for!');}
	return pVal;
}

// AliG functions - recursive position finders.
  function getLeft(obj) {
    var nLeft=obj.offsetLeft;
    while((obj=obj.offsetParent)!=null) { nLeft+=obj.offsetLeft; }
    return nLeft;
  }

  function getTop(obj) {
    var nTop=obj.offsetTop;
    while((obj=obj.offsetParent)!=null) { nTop+=obj.offsetTop; }
    return nTop;
  }  

  function getRight(obj) {
    var nRight=obj.offsetRight;
    while((obj=obj.offsetParent)!=null) { nRight+=obj.offsetRight; }
    return nRight;
  }

  function getBottom(obj) {
    var nBottom=obj.offsetBottom;
    while((obj=obj.offsetParent)!=null) { nBottom+=obj.offsetBottom; }
    return nBottom;
  } 

  function getWidth(obj) {
    var nWidth=obj.offsetWidth;
    return nWidth;
  } 

  function getScrollTop() {
	return document.documentElement['scrollTop'] ? document.documentElement['scrollTop'] : document.body['scrollTop'];
  }

  function getScrollLeft() {
	return document.documentElement['scrollLeft'] ? document.documentElement['scrollLeft'] : document.body['scrollLeft'];
  }
  function getVisHeight() {
    return document.documentElement['clientHeight'] ? document.documentElement['clientHeight'] : document.body['clientHeight']
  }
  function getVisWidth() {
    return document.documentElement['clientWidth'] ? document.documentElement['clientWidth'] : document.body['clientWidth']
  }
//
//
//
//

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Expand and Detract Menu Admin-Page Layouts

function pageLayoutToggle(titleDiv, layoutDiv, operation) {
	if (operation=1){
		document.getElementById(layoutDiv).style.display = "block";
		document.getElementById(toggleButtonExpand).style.display = "none";
		document.getElementById(toggleButtonDetract).style.display = "block";
	}
	if (operation=0){
		document.getElementById(layoutDiv).style.display = "none";
		document.getElementById(toggleButtonExpand).style.display = "block";
		document.getElementById(toggleButtonDetract).style.display = "none";
	}
	
}

// Hide and show an element
	//hiddenElement = hidden element that will be shown and hidden
	//operation = (1=show 0=hide)

function hideAndShow(hiddenElement, operation){
	if (operation=1){
		document.getElementById(hiddenElement).style.display = "block";
	}
	if (operation=0){
		document.getElementById(hiddenElement).style.display = "none";
	}
}


/**
    Created by: Michael Synovic
    on: 01/12/2003
    
    This is a Javascript implementation of the Java Hashtable object.
    
    Contructor(s):
     Hashtable()
              Creates a new, empty hashtable
    
    Method(s):
     void clear() 
              Clears this hashtable so that it contains no keys. 
     boolean containsKey(String key) 
              Tests if the specified object is a key in this hashtable. 
     boolean containsValue(Object value) 
              Returns true if this Hashtable maps one or more keys to this value. 
     Object get(String key) 
              Returns the value to which the specified key is mapped in this hashtable. 
     boolean isEmpty() 
              Tests if this hashtable maps no keys to values. 
     Array keys() 
              Returns an array of the keys in this hashtable. 
     void put(String key, Object value) 
              Maps the specified key to the specified value in this hashtable. A NullPointerException is thrown is the key or value is null.
     Object remove(String key) 
              Removes the key (and its corresponding value) from this hashtable. Returns the value of the key that was removed
     int size() 
              Returns the number of keys in this hashtable. 
     String toString() 
              Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space). 
     Array values() 
              Returns a array view of the values contained in this Hashtable. 
            
*/
function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
    return this.hashtable[key];
}

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){
    var rtn = this.hashtable[key];
    this.hashtable[key] = null;
    return rtn;
}

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {      
        if (this.hashtable[i] != null) 
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";   
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            values.push(this.hashtable[i]);
    }
    return values;
}

var _priceHash = new Hashtable();

function updatePrice(priceId,optionId,value)
{
    //alert(priceId + ' - ' + value);
    nPrice = (document.getElementById(priceId).innerHTML * 1 )
    //add to array
    
    if (_priceHash.containsKey(optionId) == true){
    //deduct the old price
    nPrice = nPrice - _priceHash.get(optionId);
    _priceHash.put(optionId,value);
    }
    else {
    _priceHash.put(optionId,value)
    }
   
    document.getElementById(priceId).innerHTML = formatAsMoney(nPrice + (value * 1 ))
}
 //  Adds up all the selected items in the options forms and changes the price to include the option cost
 
function updatePriceCbox(priceId,optionId,value,checkboxElmt)
{
    
    if (checkboxElmt.checked){
    updatePrice(priceId,optionId,value)
    }
    else{
    nPrice = (document.getElementById(priceId).innerHTML * 1 )
    nPrice = nPrice - value;
    _priceHash.remove(optionId)
    document.getElementById(priceId).innerHTML = formatAsMoney(nPrice)
    }   
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}


// Takes an array and a SELECT element and calls the updateprice function
function updateSelectPrice(obj,priceId,optionId,priceArray) {

    // Get the selected element
    var index = obj.selectedIndex
    updatePrice(priceId,optionId,priceArray[index]);
}

//  Increments the quantity
//  Does not allow a negative quantity !!

function incrementQuantity(inputName,operator)
{
    if (operator == '+')
    {
        document.getElementById(inputName).value = (document.getElementById(inputName).value*1) + 1;
    }
    else
    {
        if (document.getElementById(inputName).value > 0)
        {
            document.getElementById(inputName).value = (document.getElementById(inputName).value*1) - 1;
        }
        
    }
    
    
}

    function PadDigits(n, totalDigits) 
    { 
        n = n.toString(); 
        var pd = ''; 
        if (totalDigits > n.length) 
        { 
            for (i=0; i < (totalDigits-n.length); i++) 
            { 
                pd += '0'; 
            } 
        } 
        return pd + n.toString(); 
    } 


function checkAll(field) 
{ 
   
        for (i = 0; i < field.length; i++) 
            { 
            field[i].checked = true;
            } 
    
} 
function uncheckAll(field) 
{ 
 
   
  
       for (i = 0; i < field.length; i++) 
            { 
            field[i].checked = false;
            } 
    
} 

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;

