window.onload = handleFormEvents;
var ycs_isIe, ycs_isNS, ycs_isIEMac, ycs_gEvt;

function handleFormEvents() {
	if ((formName != null) && (enableButtonArray != null)) {	
		ycs_detectBrowsers();
			
		var elType;
		for (idx = 0; idx < document[formName].elements.length; idx++) {
			elType = document[formName].elements[idx].type;
			
			if ((elType == "checkbox") || (elType == "password") || (elType == "radio") || (elType == "select-one") || (elType == "select-multiple") || (elType == "text") || (elType == "textarea")) {
				if ((elType == "password") || (elType == "select-one") || (elType == "select-multiple") || (elType == "text") || (elType == "textarea")) {
					if (ycs_isNS) { //ns
						document[formName].elements[idx].addEventListener('change', activateButton, false);
					} else if (ycs_isIe) { //ie pc
						document[formName].elements[idx].attachEvent("onchange", activateButton);
					} else if (ycs_isIEMac) { //ie mac
						ycs_gEvt.attachEvent('onchange', activateButton, document[formName].elements[idx]);
					} else {}
				} else if ((elType == "checkbox") || (elType == "radio")) {
					if (ycs_isNS) { //ns
						document[formName].elements[idx].addEventListener('click', activateButton, false);
					} else if (ycs_isIe) { //ie pc
						document[formName].elements[idx].attachEvent('onclick', activateButton);
					} else if (ycs_isIEMac) { //ie mac
						ycs_gEvt.attachEvent('onclick', activateButton, document[formName].elements[idx]);
					} else {}
				}
			}
		}
	}
}

function activateButton() {
	for (idx = 0; idx < enableButtonArray.length; idx++) {
		var btnObj = eval("document." + formName + "['" + enableButtonArray[idx] + "']");
		if (btnObj.disabled == true) {
			btnObj.disabled = false;
			btnObj.className = "ygbtem";
		}
		if (btnObj.className != "ygbtem") {
			btnObj.className = "ygbtem";
		}
	}
}


function deactivateButton(whichForm, whichButton) {
	for (idx = 0; idx < document[whichForm].elements.length; idx++) {
		if (document[whichForm].elements[idx].name == whichButton) {
			document[whichForm].elements[idx].disabled = true;
			document[whichForm].elements[idx].className = "ygbtdssm";
		}
	}
}

function confirmAction(thisStr) {
	return confirm(thisStr);
}
	
function doCancelFlow(lang) {
	if ((lang != null) && (lang == "fr")) {
		retStr = "L'installation d'Internet haute vitesse Yahoo! de Rogers n'est pas complète. Êtes-vous sûr vous voulez-vous décommander?";
	} else {
		retStr = "Rogers Yahoo! Hi-Speed Internet Setup is not complete.  Are you sure you want to cancel?";
	}
	return confirm(retStr);
}

function openWin(thisURL, thisName, thisW, thisH, thisScroll) {
	if (thisScroll == null) {
		thisScroll = "yes";
	}
	newWin = window.open(thisURL, thisName, "toolbar=no, scrollbars=" + thisScroll + ", resizable=yes, width=" + thisW + ", height=" + thisH);
	newWin.focus();
}

function setCatSetting(thisCat, thisValue) {
    document.getElementById(thisCat + 'Ictr').style.visibility = 'visible';
	
	if (thisValue == 0) {
	    document.getElementById(thisCat).width = "";
	} else {
	    document.getElementById(thisCat).width = (Math.round(thisValue/10) * 10) + "%";
	}
}

function swapText(whichDiv, whichText) {
	txtObj = document.getElementById(whichDiv);
	txtObj.innerHTML = whichText;
}

function toggleAccessSet(curCbx, thisCat, onValue, offValue) {
	var tblObj, curWidth;
	tblObj = document.getElementById(thisCat);
	if (tblObj.width == "") {
		curWidth = 0;
	} else {
		if (tblObj.width.indexOf("%") > -1) {
			curWidth = tblObj.width.substring(0, tblObj.width.indexOf("%"));
		}
	}
	
	onValue = onValue.toString(); offValue = offValue.toString();
	
	// check to see if this is incrementing by value
	if (onValue.indexOf("+") > -1) {
		onValue = onValue.substring(1);
		onValue = Math.abs(curWidth) + Math.abs(onValue);
	} else if (onValue.indexOf("-") > -1) {
		onValue = onValue.substring(1);
		onValue = Math.abs(curWidth) - Math.abs(onValue);
	}
	
	if (offValue.indexOf("+") > -1) {
		offValue = offValue.substring(1);
		offValue = Math.abs(curWidth) + Math.abs(offValue);
	} else if (offValue.indexOf("-") > -1) {
		offValue = offValue.substring(1);
		offValue = Math.abs(curWidth) - Math.abs(offValue);
	}
	
	if (curCbx.checked) {
		setCatSetting(thisCat, onValue);
	} else {
		setCatSetting(thisCat, offValue);
	}
}









/* event handlers for Mac IE */
function ycs_detectBrowsers() {
	ycs_isIe = ycs_isNS = ycs_isIEMac = false;
	ycs_gEvt = null;
	
	if (document.getElementById && !document.all) {
		ycs_isNS = true;
	} else if (document.all) {
		if (document.attachEvent) {
			ycs_isIe = true;
		} else {
			ycs_isIEMac = true;
			ycs_gEvt = new ycs_EvtGlobal();
		}
	}
}

function ycs_EvtGlobal() {
	this.ycs_EvtElements = new Array();
	this.attachEvent = ycs_attachEvent;
	this.getObjIdx	 = ycs_getObjIdx;
	this.handleEvent = ycs_handleEvent;
}

function ycs_EvtElement(onEvt, tElement) {
	this.oElement = tElement;
	this.aFunctions = new Array();		
}

function ycs_attachEvent(onEvt, callFunction, tElement) {
	var isEvtAlreadyAssigned = eval("(typeof(tElement." + onEvt + ") == 'function');")
	var globalEvtIndex = this.getObjIdx(onEvt, tElement);
	var isInEvtGlobal = (globalEvtIndex == -1) ? false : true;
  
	if (!isEvtAlreadyAssigned) {
		eval("tElement." + onEvt + " = " + callFunction + ";");
	} else if (isEvtAlreadyAssigned && !isInEvtGlobal) {
		var newIndex = this.ycs_EvtElements.length;
		this.ycs_EvtElements[newIndex] = new ycs_EvtElement(onEvt, tElement);
		this.ycs_EvtElements[newIndex].aFunctions[0] = eval("tElement." + onEvt);
		this.ycs_EvtElements[newIndex].aFunctions[1] = callFunction;
		eval("tElement." + onEvt + " = ycs_gEvt.handleEvent;");
	}
}

function ycs_getObjIdx(onEvt, tElement) {
	numEvtObj = this.ycs_EvtElements.length;
	for (i=0; i < numEvtObj; i++) {
		tempObj = this.ycs_EvtElements[i];
		if (tempObj.oElement == tElement) {
			return i;
		}
	}
	return -1;
}

function ycs_handleEvent(evt) {
	var evt = ycs_getEvent(evt);
	var sEventName = evt.type;
	if (sEventName.substring(0, 2) != "on") {
		sEventName = "on" + sEventName;
	}
	var tElement = ycs_getEventTarget(evt);
	var gObjIdx = ycs_gEvt.getObjIdx(evt, tElement);
	for (var i=0; i < ycs_gEvt.ycs_EvtElements[gObjIdx].aFunctions.length; i++) {
		ycs_gEvt.ycs_EvtElements[gObjIdx].aFunctions[i](evt);
	}
}

function ycs_getEvent(evt) {
	return(evt) ? evt : ((window.event) ? event : null);
}

function ycs_getEventTarget(evt) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if ( evt ) {
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

		// if element contains a text node then need to pop up one
		while ( elem.nodeType == 3 ) {
			elem = elem.parentNode;
		}
		return elem;
	}
	return null;
}
