﻿var intNetscape = -1;
var blnClick = true;			// Must page be loaded

function determineBrowser() {
	if (navigator.appName.toLowerCase() == "netscape")
		intNetscape = 1;
	else
		intNetscape = 0;
}

function popup(intX, intY, intWidth, intHeight, blnCenter, blnToolbar, blnResizable, blnScrollbars, strUrl) {
	var intWinX, intWinY;
	var strOptions = "";
	
	if (intNetscape == -1) determineBrowser();

	intWinX = (intNetscape == 0)? window.top.screenLeft:window.top.screenX;
	intWinY = (intNetscape == 0)? window.top.screenTop:window.top.screenY;
	
	if (blnCenter) {
		intWinX += ((window.top.document.body.clientWidth / 2) - (intWidth / 2));
		intWinY += ((window.top.document.body.clientHeight / 2) - (intHeight / 2));
	}
	else {
		intWinX += intX;
		intWinY += intY;
	}
	
	strOptions = "left=" + intWinX + ",top=" + intWinY + ",width=" + intWidth + ",height=" + intHeight;
	if (blnToolbar) 
		strOptions += ",fullscreen=0,location=1,menubar=1,status=1,toolbar=1,titlebar=1";
	else
		strOptions += ",fullscreen=0,location=0,menubar=0,status=0,toolbar=0,titlebar=0";
	strOptions += ",resizable=" + ((blnResizable)? "1":"0");
	strOptions += ",scrollbars=" + ((blnScrollbars)? "1":"0");
	
	window.open(unescape(strUrl), "", strOptions);
}

function clickLink(objLink) {
	if (intNetscape == -1) determineBrowser();
	
	if (objLink.href.indexOf("javascript:") == -1) {
		if (intNetscape == 0) {
			objLink.click();
		}
		else {
			if (objLink.target != "")
				window.open(objLink.href, objLink.target);
			else
				window.location.href=objLink.href;
		}
	}
	else {
		eval(objLink.href.substring(11));
	}
}

/*
 * Login 
 */
function LoginCheckKey(objEvent, intPageID) {
	if (objEvent.keyCode == 13) {
		LoginSubmit(intPageID);
		objEvent.returnValue = false;
	}
	else {
		objEvent.returnValue = true;
	}
} 

function LoginSubmit(intPageID) {
	var objForm;
	
	objForm = document.getElementById("formlogin" + intPageID);
	if (objForm != null) objForm.submit();
	
	return false;
}

function PollSubmit(intPageID) {
	var objForm;
	
	objForm = document.getElementById("formpoll" + intPageID);
	if (objForm != null) objForm.submit();
	
	return false;
}


/*
 * Section
 */
var intCurrentSectionNr = -1;
var intStartSectionNr = -1;

function SetSection() {
	var objLink;
	var i, objItem;
	
	// Workaround for bug in IE (sometimes the cell is to wide when fetched from cache)
	for (i=1;;i++) {
		objItem = document.getElementById("G" + i);
		if (objItem != null) {
			objItem.className = 'section_idle';
			document.getElementById("GT" + i).className = 'section_text_idle';
		}
		else
			break;
	}

	blnClick = false;
	objLink = document.getElementById("G" + intStartSectionNr);
	if (objLink != null) SectionClick(intStartSectionNr);
	blnClick = true;
}

function SectionOver(intSectionNr) {
	document.getElementById("G" + intSectionNr).className = 'section_active';
	document.getElementById("GT" + intSectionNr).className = 'section_text_active';
}

function SectionOut(intSectionNr) {
	if (intCurrentSectionNr != intSectionNr) {
		document.getElementById("G" + intSectionNr).className = 'section_idle';
		document.getElementById("GT" + intSectionNr).className = 'section_text_idle';
	}
}

function SectionCombinedOver(objSender, objItem) {
	var objTD;
	// Change the class of the text when displaying a lock image in menu item
	objTD = document.getElementById("GT" + objItem.get_item().get_value())
	if (objTD != null) objTD.className = "section_text_active";
}

function SectionCombinedOut(objSender, objItem) {
	var objTD;
	
	// Change the class of the text when displaying a lock image in menu item
	objTD = document.getElementById("GT" + objItem.get_item().get_value())
	if (objTD != null) objTD.className = "section_text_idle";
}

function SectionClick(intSectionNr) {
	var objHtml;
	var objSectionLink = null;
	
	if (intCurrentSectionNr != -1) {
		document.getElementById("G" + intCurrentSectionNr).className = 'section_idle';
		document.getElementById("GT" + intCurrentSectionNr).className = 'section_text_idle';
	}
	
	objHtml = document.getElementById('GI' + intCurrentSectionNr);
	if (objHtml != null) objHtml.src = objHtml.src.replace(/Open/gi, 'Closed');
	objHtml = document.getElementById('GI' + intSectionNr);
	if (objHtml != null) objHtml.src = objHtml.src.replace(/Closed/gi, 'Open');
	intCurrentSectionNr = intSectionNr;	
	
	SectionOver(intSectionNr);
	objSectionLink = document.getElementById("SectionLink");
	objSectionLink.href = document.getElementById("G" + intCurrentSectionNr).getAttribute("href");
	if (blnClick) clickLink(objSectionLink);
}

/*
 * Menu
 */
var blnKeepParent = true;		// No open/close submenu
var blnHideShowSub = true;		// Hide/Show submenu
var objCurrentParentNode = null;
var intWantedPageID = -1;

function SetMenu() {
	// Flash workaround for 'click to activate'
	if (window.ActiveXObject) { 
		var allObjects = document.body.getElementsByTagName("Object");
		for (i=0; i < allObjects.length; i++) {
			if ((allObjects[i].classid == "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000") || (allObjects[i].classid == "clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"))  allObjects[i].outerHTML = allObjects[i].outerHTML;
		}
		allObjects = document.body.getElementsByTagName("embed");
		for (i=0; i < allObjects.length; i++) {
			allObjects[i].outerHTML = allObjects[i].outerHTML;
		}
	} 
	
	if (document.getElementById("ctl00_Menu_FlexonyMenuTree_div") != null) {
		if ((intWantedPageID > 0) && (ctl00_Menu_FlexonyMenuTree.FindNodeById(intWantedPageID) != null)) {
			MenuClickTree(ctl00_Menu_FlexonyMenuTree.FindNodeById(intWantedPageID));
		}
	}
}

function MenuClickTree(objNode) {
	var objParentNode;
	
	objParentNode = objNode.GetParentNode();
	if (objCurrentParentNode != null) {
		if (blnKeepParent) objCurrentParentNode.SetProperty("RowCssClass", "menu_idle");
		if (blnHideShowSub) {
			if (objParentNode == null)
				objCurrentParentNode.SetProperty("Expanded", false);
			else {
				if (objParentNode.ID != objCurrentParentNode.ID) objCurrentParentNode.SetProperty("Expanded", false);
			}
		}
	}
	if (objParentNode == null) {
		objCurrentParentNode = objNode;
		objNode.SetProperty("Expanded", true);
	}
	else {
		if (blnKeepParent) objParentNode.SetProperty("RowCssClass", "menu_active");
		objCurrentParentNode = objParentNode;
	}
	if (blnKeepParent || blnHideShowSub) objNode.get_parentTreeView().Render();
	return true;
}

function MenuItemSelect(objSender, objItem) {
	return true;
}

/*
 * Body
 */
function CheckFormFields(objForm) {
	var i, j;
	var objField, objField2;
	var blnNoError;
	var strError = '';
	
	while ((objForm != null) && (objForm.tagName.toUpperCase() != "FORM")) objForm = objForm.parentNode;
	
	if (objForm != null) {
		for (i = 0; i < objForm.elements.length; i++) {
			objField = objForm.elements[i];
			
			blnNoError = true;
			if ((objField.tagName.toUpperCase() == "INPUT") && ((objField.type == "text") || (objField.type == "password")))  {
				if (objField.getAttribute("Required") == "true") {
					if (objField.value.length == 0) {
						strError += objField.getAttribute("RequiredMsg") + '\n';
						blnNoError = false;
					}
				}
				if (objField.value.length > 0) {
					if (blnNoError && (objField.getAttribute("IsNumber") == "true")) {
						if (!objField.value.match("^[0-9]+$")) {
							strError += objField.getAttribute("AcceptMsg") + '\n';
							blnNoError = false;
						}
					}
					if (blnNoError && (objField.getAttribute("IsEmail") == "true")) {
						if (!objField.value.match("^[\\w-_\.]*[\\w-_\.]\@[\\w-_\.]+[\.][\\w-_\.]+[\\w-_\.]$")) {
							strError += objField.getAttribute("AcceptMsg") + '\n';
							blnNoError = false;
						}
					}
				}
				if (objField.getAttribute("SameField") != null) {
					objField2 = null;
					for (j = 0; j < objForm.elements.length; j++) {
						objField2 = objForm.elements[j];
						if ((objField2.tagName.toUpperCase() == "INPUT") && ((objField2.type == "text") || (objField2.type == "password")) && (objField2.name == objField.getAttribute("SameField"))) {
							if (objField.value != objField2.value) {
								strError += objField.getAttribute("SameMsg") + '\n';
								blnNoError = false;
							}
							break;
						}
					}
				}
			}
			
			if (blnNoError && (objField.tagName.toUpperCase() == "INPUT") && (objField.type == "file"))  {
				if (objField.getAttribute("Required") == "true") {
					if (objField.value.length == 0) strError += objField.getAttribute("RequiredMsg") + '\n';
				}
			}

			if (blnNoError && (objField.tagName.toUpperCase() == "INPUT") && ((objField.type == "checkbox") || (objField.type == "radio"))) {
				if (objField.getAttribute("Required") == "true") {
					if (objField.checked == false) strError += objField.getAttribute("RequiredMsg") + '\n';
				}
			}

			if (blnNoError && (objField.tagName.toUpperCase() == "TEXTAREA"))  {
				if (objField.getAttribute("Required") == "true") {
					if (objField.value.length == 0) strError += objField.getAttribute("RequiredMsg") + '\n';
				}
			}
		}
	}
	
	if (strError == '')
		return true;
	else {
		alert(objForm.getAttribute("ErrorTitle") + '\n\n' + strError);
		return false;			
	}
}

function InsertSmiley(strCode) {
	document.getElementById("ctl00_Body_Message").value += strCode;
}

function GivePageID() {
	var objTags = document.getElementsByTagName('meta');
	var intIndex;
	
	for (intIndex=0; intIndex <objTags.length; intIndex++) {
		if (objTags[intIndex].name == '__flexonypageid') {
			return objTags[intIndex].content;
		}
	}
	
	return 0;
}

function FlexonyFullPrint() {
	if (window.top.print) {
		window.top.print();
	}
} 

function FlexonyPrint() {
	objHtml = document.createElement("iframe");
	objHtml.id = "flexonyprintwindow";
	objHtml.name = "flexonyprintwindow";
	objHtml.style.width = "0px";
	objHtml.style.height = "0px";
	objHtml.style.borderWidth = "0px;"
	objHtml.src = "../Site/Print.aspx?PageID=" + GivePageID();
	document.body.appendChild(objHtml);
}

function FlexonyPDF() {
	var objForm;
	var objText;
	var strHTML;
	var intWidth;
		
	objForm = document.createElement("form");
	objForm.method = "post";
	objForm.style.display = "none";
	if (document.getElementById("ctl00_BodyCell") != null) {
		intWidth = document.getElementById("ctl00_BodyCell").offsetWidth;
		strHTML = document.getElementById("ctl00_BodyCell").innerHTML;
	}
	else if (document.getElementById("ctl00_bodyCell") != null) {
		intWidth = document.getElementById("ctl00_bodyCell").offsetWidth;
		strHTML = document.getElementById("ctl00_bodyCell").innerHTML;
	}
	else if (document.getElementById("ctl00_Bodycell") != null) {
		intWidth = document.getElementById("ctl00_Bodycell").offsetWidth;
		strHTML = document.getElementById("ctl00_Bodycell").innerHTML;
	}
	else if (document.getElementById("ctl00_bodycell") != null) {
		intWidth = document.getElementById("ctl00_bodycell").offsetWidth;
		strHTML = document.getElementById("ctl00_bodycell").innerHTML;
	}
	else {
		intWidth = document.body.offsetWidth;
		strHTML = document.body.innerHTML
	}
	objForm.action = "../Site/PDF.aspx?Full=0&Width=" + intWidth + "&PageID=" + GivePageID();
	objText = document.createElement("textarea");
	objText.name = "pagehtml";
	objText.value = strHTML;
	objForm.appendChild(objText);
	document.body.appendChild(objForm);
	objForm.submit();
}

function FlexonyFullPDF() {
	var objForm;
	var objText;
		
	objForm = document.createElement("form");
	objForm.method = "post";
	objForm.style.display = "none";	
	objForm.action = "../Site/PDF.aspx?Full=1&PageID=" + GivePageID();
	objText = document.createElement("textarea");
	objText.name = "pagehtml";
	objText.value = document.getElementsByTagName("HTML")[0].innerHTML;
	objForm.appendChild(objText);
	document.body.appendChild(objForm);
	objForm.submit();
}

function FlexonyLogout() {
	window.location.replace("../Site/Logout.aspx");
}

function FlexonyInfo(intInfoID, intPageID) {
	window.location.href = "../Info/Display.aspx?PageID=" + intPageID + "&ID=" + intInfoID;
}

function FlexonyProduct(intMode, intProductID) {
	if (intMode == 1) {
		window.location.href = "../Products/Product.aspx?PageID=" + GivePageID() + "&PID=" + intProductID;
	}
	else {
		window.location.href = "../Products/OverView.aspx?PageID=" + GivePageID() + "&PID=" + intProductID;
	}
}

function FlexonyProfile() {
	window.location.replace("../Site/Profile.aspx?PageID=" + GivePageID());
}

var strFriendPreviousOverflow = "";
function FlexonyMailAFriend() {
	var objDiv, objFrame;

	strFriendPreviousOverflow = document.body.style.overflow;
	document.body.style.overflow = "hidden";
	objDiv = document.getElementById("flexonyfriendwindow");
	if (objDiv == null) {
		objFrame = document.createElement("iframe");
		objFrame.allowTransparency = true;
		objFrame.frameBorder = "0"
		objFrame.src = "../Site/MailAFriend.aspx";
		objFrame.style.width = "100%";
		objFrame.style.height = "100%";

		objDiv = document.createElement("div");
		objDiv.id = "flexonyfriendwindow";
		objDiv.style.position = "absolute";
		objDiv.style.left = 0;
		objDiv.style.top = 0;
		objDiv.style.width = "100%";
		objDiv.style.height = "100%";
		objDiv.style.display = "none";
		objDiv.style.zIndex = "80000";
		objDiv.appendChild(objFrame);
		document.body.appendChild(objDiv);
	}
	else {
		objDiv.style.display = "";
		objDiv.focus();
	}
}

function FlexonyCloseMailAFriend() {
	var objDiv;

	objDiv = document.getElementById("flexonyfriendwindow");
	if (objDiv != null) {
		objDiv.parentNode.removeChild(objDiv);
	}
	document.body.style.overflow = strFriendPreviousOverflow;
}