function MM_findObj(n, d) { //v3.0
  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); 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];}
}
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_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 CheckSearchBox(txtSearch, strOldValue, strNewValue){
	if (txtSearch.value == strOldValue){
		txtSearch.value = strNewValue;
	}
}

//mailwin
function mailwin(theurl) {
	window.open(strWebRoot + "inc/mailpage.cfm?theurl="+theurl,"mailwin","width=400,height=280,status=no,scrollbars=yes,location=no,toolbar=no,menubar=no,resizable=yes");
}



function IsNumeric(val) {
	var ValidChars = "0123456789.";
	for (i=0; i<val.length; i++) {
		if (ValidChars.indexOf(val.charAt(i)) == -1) return false
	}
	return true
}

function IsEmpty(val) {
	for (i=0; i<val.length; i++) { 
		if (val.charAt(i) != ' ') return false
	}
	return true
}

function IsValidEmail(val) {
	var iLen = val.length;
	if 	((iLen < 6) || (val.indexOf('@') < 1) || ((val.charAt(iLen - 3) != '.') && (val.charAt(iLen - 4) != '.')) ) return false
	return true
}
/* 2009.5.13, Ye Wang
function formVal(formID){
	var msg = "";
	var typeList = "text,password,select-one";
	curForm = document.getElementById(formID);

	for (var i=0; i<curForm.elements.length; i++){
		tag = curForm.elements[i];
		if (typeList.indexOf(tag.type) >= 0 && tag.getAttribute('required') == 1 && tag.value == "") {
			msg = msg + "<li>" + tag.title + " </li>";
		};
		if (tag.name.indexOf("email") >= 0  && tag.value.length != 0) {
			flag = IsValidEmail(tag.value);
			if (!flag) {
				msg = msg + "<li>" +  tag.title + " is invalid</li>";
			}
		};
		if (tag.type == "password" && tag.value.length > 0  && tag.value.length < 4) {
			msg = msg + "<li>" + "Password is too short</li>";
		}
		if (tag.name == "password2" && tag.value != "" && tag.value != curForm.password.value)
			msg = msg + "<li>" + "Password confirmation</li>";
	};
	
	document.getElementById('err').innerHTML = "";
	if (msg != "") {
		document.getElementById('err').innerHTML = "The following fields are required: <ul>" + msg + "</ul>";
		//window.scrollTo(0,100);
		return false;
	} else {
		return true;
	}
}
*/
function formVal(){
	var msg = "";
	var typeList = "text,password,select-one,textarea";

	if (arguments.length > 0)  {
		//var curForm = eval("document.forms[arguments[0]]");
		curForm = document.getElementById(arguments[0]);
	} else {
		curForm = document.forms["form"];
	}
	for (var i=0; i<curForm.elements.length; i++){
		tag = curForm.elements[i];
		tag.value = trim(tag.value);
		if (typeList.indexOf(tag.type) >= 0 && tag.getAttribute('required') == 1 && tag.value == "") {
			msg = msg + "<li>" + tag.title + "</li>";
		};
	
		if (tag.name == "email" && tag.value.length != 0) {
			flag = IsValidEmail(tag.value);
			if (!flag) {
				msg = msg + "<li>Please enter a valid email address</li>";
			}
		};
		if (tag.type == "password" && tag.value.length > 0  && tag.value.length < 4) {
			msg = msg + "<li>" + "Password is too short: four-character minimum" + "</li>";
		}
		/*
		if (tag.name == "password2" 
			&& (tag.value != "")
			&& (tag.value != document.getElementById('password').value))
			msg = msg + "<li>" + "Password confirmation" + "</li>";
		*/
		if (tag.name.indexOf("conf") == 0 
			&& checkRetype(document.getElementById(tag.id)) == false) {
			msg = msg + "<li>" + tag.title  + " de nuevo</li>";
		} 
	};
	// Optin in   
	if ($("input[name='optin']").length > 0 && $("input[name='optin']:checked").length == 0) {
		msg = msg + "<li>Receive Email option</li>";
	};      
	document.getElementById('err').innerHTML = "";
	if (msg != "") {
		document.getElementById('err').innerHTML = "These fields are required: <ul>" + msg + "</ul>";
		return false;
	} else {
		return true;
	}  
}
/******************************************************
	Trim functions:
*******************************************************/
function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}
function lTrim(str) {
	return str.replace(/^\s+/,"");
}
function rTrim(str) {
	return str.replace(/\s+$/,"");
}
// compare two fields:
function checkRetype(obj) { 
	var targetObj = document.getElementById(obj.id.replace("conf", "")); 
	//var curLabel = getLabel(obj);
	var curLabel = document.getElementById(obj.id + "label");
	 
	if (targetObj.value == "" || targetObj.value != obj.value) {
		curLabel.innerHTML = "Escriba el " + targetObj.getAttribute("title") + " de nuevo:";
		curLabel.className = "label-confirm";
		return false;
	} else {
		curLabel.innerHTML = "Escriba el " + targetObj.getAttribute("title") + ":";
		curLabel.className = "label-required";
		return true;
	}  
	obj.parentNode.className = curLabel.className;
}
function getLabel(obj) {	
	var prevNode = obj.previousSibling; 
	while (prevNode.nodeType != 1 || prevNode.tagName != "LABEL") {
		prevNode = prevNode.previousSibling;
	}
	return prevNode;
} 
/***************************************************************
	END OF FORM VALIDATION: GENERAL
***************************************************************/

function NumCBGroupChecked(f,strName){
	var colEl = f.elements;
	var iChecked = 0;
	for (var i=0; i<colEl.length; i++){
		el = colEl[i];
		if (el.name && (el.name == strName) && el.checked) iChecked++;
	}
	return iChecked;
}

function LTrim(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;
		s = s.substring(j, i);
	}
	return s;
}

function RTrim(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(s) {
   return RTrim(LTrim(s));
}




// 2005.3.21, Ye Wang: new sites DHTML menu
function toggleSites () {
	dImg = document.getElementById("navBoxLogo");
	dMenu = document.getElementById("navBox");
	if (dMenu.style.visibility == "visible") {
		dMenu.style.visibility = "hidden";
		dImg.src = "img/logo_sites.gif";
		
	} else {
		dMenu.style.visibility = "visible";
		dImg.src = "img/logo_sites_f2.gif";
	}
}
// DHTML dropdown menu functions;
function Browser() {
	var ua, s, i;
	this.version = 0;
	this.ok = false;
	
	ua = ua=navigator.userAgent.toLowerCase();
	
	this.isOpera = ua.indexOf('opera') != -1;
	this.isKonq = ua.indexOf('konqueror') != -1;
	this.isIE = ua.indexOf('msie') != -1;
	if (this.isIE) this.version = parseFloat(ua.substr(ua.indexOf('msie') + 4));
	this.isAol = ua.indexOf('aol') != -1;
	this.isNav = ua.indexOf('netscape6/') != -1;
	if (this.isNav) this.version = parseFloat(ua.substr(ua.indexOf('netscape6/') + 10));
	this.isGecko = ua.indexOf('gecko') != -1;
	if (this.isGecko){
		this.isNav = true;
		this.version = 6.1;
	}
	this.isSafari = ua.indexOf("safari") != -1;
	
	this.isMac = ua.indexOf('mac') != -1;
	this.isWin = ua.indexOf('win') != -1;
	this.isLin = !(this.bMac || this.bWin);
	
	this.isMacIE = this.isIE && this.isMac;
	
	this.ok = 	(this.isIE && this.isWin && this.version >= 4) || 
				(this.isIE && this.isMac && this.version >= 5) || 
				(this.isNavigator && this.version >= 5) || 
				(this.isGecko) || 
				(this.Safari);
	//alert(this.ok);
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------
var activeButton = null;
function dmRootButtonGo(event, menuId, xOffset, yOffset) {
	var button;
	// Get the target button element.
	if (browser.isIE) button = window.event.srcElement;
	else button = event.currentTarget;
	
	button.blur();		// Blur focus from the link to remove that annoying outline.

	// Associate the named menu to this button if not already done.
	// Additionally, initialize menu display.
	if (button.menu == null) {
		button.menu = document.getElementById(menuId);
		if (button.menu.isInitialized == null) menuInit(button.menu);
	}

	// Set mouseout event handler for the button, if not already done.	
	if (button.onmouseout == null) button.onmouseout = buttonOrMenuMouseout;
	
	// Exit if this button is the currently active one.
	if (button == activeButton) return false;

	// Reset the currently active button, if any.
	if (activeButton != null) dmResetRootButton(activeButton);
	
	// Activate this button, unless it was the currently active one.
	if (button != activeButton) {
		dmDepressRootButton(button, xOffset, yOffset);
		activeButton = button;
	} else activeButton = null;
	
	return false;
}

function dmRootButtonOver(event, menuId, xOffset, yOffset) {
	var button;
	
	if (!browser.ok) return;
	bMouseOut = false;
	
	if (!xOffset) xOffset = 0;
	if (!yOffset) yOffset = 0;

	// Activates this button's menu if no other is currently active.
	if (activeButton == null) {
		dmRootButtonGo(event, menuId, xOffset, yOffset);
		return;
	}
	
	// Find the target button element.
	if (browser.isIE) button = window.event.srcElement;
	else button = event.currentTarget;
	
	// If any other button menu is active, make this one active instead.
	if (activeButton != null && activeButton != button) dmRootButtonGo(event, menuId, xOffset, yOffset);
}

function dmDepressRootButton(button, xOffset, yOffset) {
	var x, y;
	// Update the button's style class to make it look like it's depressed.
	// and opens the submenu
	
	//button.className += " dmRootButtonActive";
	
	// Set mouseout event handler for the button, if not already done.
	if (button.onmouseout == null) button.onmouseout = buttonOrMenuMouseout;
	if (button.menu.onmouseout == null) button.menu.onmouseout = buttonOrMenuMouseout;
	
	// Position the associated drop down menu under the button and show it.
	x = getPageOffsetLeft(button) + xOffset;
	y = getPageOffsetTop(button) + button.offsetHeight + yOffset;
	
	/*
	// For IE, adjust position.
	if (browser.isIE) {
		x += button.offsetParent.clientLeft;
		y += button.offsetParent.clientTop;
	}
	*/
	
	dmHideBleeders(button.menu.id);
	
	button.menu.style.left = x + "px";
	button.menu.style.top  = y + "px";
	button.menu.style.visibility = "visible";
}

function dmResetRootButton(button) {
	// Restore the button's style class.	
	//removeClassName(button, "dmRootButtonActive");

	// Hide the button's menu, first closing any sub menus.
	if (button.menu != null) {
		closeSubMenu(button.menu);
		dmUnHideBleeders(button.menu.id);
		button.menu.style.visibility = "hidden";
	}
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function dmMenuMouseover(event) {
	var menu;
	
	bMouseOut = false;
	
	// Find the target menu element.
	if (browser.isIE) menu = getContainerWith(window.event.srcElement, "DIV", "dmMenu");
	else menu = event.currentTarget;
	
	// Close any active sub menu.
	if (menu.activeItem != null) closeSubMenu(menu);
}
function dmMenuMouseout(event) {
	var menu;
	
	bMouseOut = true;
	
	// Find the target menu element.
	if (browser.isIE) menu = getContainerWith(window.event.srcElement, "DIV", "dmMenu");
	else menu = event.currentTarget;
	
	// Close any active sub menu.
	closeSubMenu(menu);
}

function dmMenuItemMouseover(event, menuId) {
	var item, menu, x, y;
	// Find the target item element and its parent menu element.
	
	bMouseOut = false;
		
	if (browser.isIE) item = getContainerWith(window.event.srcElement, "A", "dmMenuItem");
	else item = event.currentTarget;
	menu = getContainerWith(item, "DIV", "dmMenu");
	
	// Close any active sub menu and mark this one as active.
	if (menu.activeItem != null) closeSubMenu(menu);
	menu.activeItem = item;
	
	// Highlight the item element.
	item.className += " dmMenuItemHighlight";
	
	// Initialize the sub menu, if not already done.
	if (item.subMenu == null) {
		item.subMenu = document.getElementById(menuId);
		if (item.subMenu.isInitialized == null) menuInit(item.subMenu);
	}

	// Set mouseout event handler for the sub menu, if not already done.
	if (item.subMenu.onmouseout == null) item.subMenu.onmouseout = buttonOrMenuMouseout;
		
	// Get position for submenu based on the menu item.
	x = getPageOffsetLeft(item) + item.offsetWidth;
	y = getPageOffsetTop(item);
	
	// Adjust position to fit in view.
	var maxX, maxY;
	
	if (browser.isNav) {
		maxX = window.scrollX + window.innerWidth;
		maxY = window.scrollY + window.innerHeight;
	} else if (browser.isMacIE) {
		maxX = document.body.scrollLeft + document.body.clientWidth;
		maxY = document.body.scrollTop + document.body.clientHeight;
	} else if (browser.isIE) {
		maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
		(document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
		maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
		(document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
	}
	maxX -= item.subMenu.offsetWidth;
	maxY -= item.subMenu.offsetHeight;

	if (x > maxX) x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth + (menu.offsetWidth - item.offsetWidth));
	y = Math.max(0, Math.min(y, maxY));

	dmHideBleeders(item.subMenu.id);
	
	// Position and show the sub menu.
	item.subMenu.style.left = x + "px";
	item.subMenu.style.top  = y + "px";
	item.subMenu.style.visibility = "visible";

	// Stop the event from bubbling.
	if (browser.isIE) window.event.cancelBubble = true;
	else event.stopPropagation();
}

function closeSubMenu(menu) {
	if (menu == null || menu.activeItem == null) return;
	// Recursively close any sub menus.
	if (menu.activeItem.subMenu != null) {
		closeSubMenu(menu.activeItem.subMenu);
		dmUnHideBleeders(menu.activeItem.subMenu.id);
		menu.activeItem.subMenu.style.visibility = "hidden";
		menu.activeItem.subMenu = null;
	}
	removeClassName(menu.activeItem, "dmMenuItemHighlight");
	menu.activeItem = null;
}


var bMouseOut = false;
function buttonOrMenuMouseout(event) {
	var el;
	// If there is no active button, exit.
	if (activeButton == null) return;
	
	// Find the element the mouse is moving to.
	if (browser.isIE) el = window.event.toElement;
	else if (event.relatedTarget != null) el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
	
	// If the element is not part of a menu, reset the active button.
	if (getContainerWith(el, "DIV", "dmMenu") == null) {
		bMouseOut = true;
		setTimeout('buttonOrMenuMouseout_2();', 500);
	}
}

function buttonOrMenuMouseout_2(){
	if (bMouseOut){
		bMouseOut = false;
		dmResetRootButton(activeButton);
		activeButton = null;
	}
}

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------
function menuInit(menu) {
	var itemList, spanList;
	var textEl, arrowEl;
	var itemWidth;
	var w, dw;
	var i, j;
	
	// Find the width of a menu item.
	itemList = menu.getElementsByTagName("A");
	if (itemList.length > 0) itemWidth = itemList[0].offsetWidth;
	else return;
	
	if (browser.isIE && browser.isMac){
		itemList[0].style.display = 'inline';
		iMaxItemWidth = itemList[0].offsetWidth;
		for (i=1; i < itemList.length; i++) {
			itemList[i].style.display = 'inline';
			iMaxItemWidth = Math.max(iMaxItemWidth, itemList[i].offsetWidth);
			itemList[i].style.display = 'block';
		}
		for (i=0; i < itemList.length; i++) itemList[i].style.width = iMaxItemWidth;
	} else if (browser.isIE) {
		// Fix IE hover problem by setting an explicit width on first item of the menu.	
		w = itemList[0].offsetWidth;
		itemList[0].style.width = w + "px";
		dw = itemList[0].offsetWidth - w;
		w -= dw;
		itemList[0].style.width = w + "px";
	}
	
	// Mark menu as initialized
	menu.isInitialized = true;
}


//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

var colDmBleeders = new Object();
function dmHideBleeders(mnID){
	if (!colDmBleeders[mnID]) return;
	var arBleedIds = colDmBleeders[mnID];
	for (var i=0; i<arBleedIds.length; i++){
		document.getElementById(arBleedIds[i]).style.visibility = 'hidden';
	}
}

function dmUnHideBleeders(mnID){
	if (!colDmBleeders[mnID]) return;
	var arBleedIds = colDmBleeders[mnID];
	for (var i=0; i<arBleedIds.length; i++){
		document.getElementById(arBleedIds[i]).style.visibility = 'inherit';
	}
}

function getContainerWith(node, tagName, className) {
	// Starting with the given node, find the nearest containing element with the specified tag name and style class.
	while (node != null) {
		if (node.tagName != null && node.tagName == tagName && hasClassName(node, className)) return node;
		node = node.parentNode;
	}	
	return node;
}

function hasClassName(el, name) {
	var i, list;
	// Return true if the given element currently has the given class name.
	list = el.className.split(" ");
	for (i = 0; i < list.length; i++) if (list[i] == name) return true;
	return false;
}

function removeClassName(el, name) {
	var i, curList, newList;
	if (el.className == null) return;
	// Remove the given class name from the element's className property.
	newList = new Array();
	curList = el.className.split(" ");
	for (i = 0; i < curList.length; i++) if (curList[i] != name) newList[newList.length] = (curList[i]);
	el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
	var x;
	x = el.offsetLeft;
	if (browser.isSafari && getContainerWith(window.event.srcElement, "DIV", "dmMenu")){
		x -= document.getElementsByTagName('BODY').item(0).offsetLeft;
	} else if (browser.isMacIE && getContainerWith(window.event.srcElement, "DIV", "dmMenu")) {
		x += parseInt(document.body.currentStyle.marginLeft) - 8;
	}
	while (el.offsetParent != null){
		el = el.offsetParent;
		x += el.offsetLeft;
	}
	return x;
}

function getPageOffsetTop(el) {
	var y;
	y = el.offsetTop;
	//alert(el.nodeName+':'+el.offsetTop);
	if (browser.isSafari && getContainerWith(window.event.srcElement, "DIV", "dmMenu")){
		y -= document.getElementsByTagName('BODY').item(0).offsetTop;
	} else if (browser.isMacIE && getContainerWith(window.event.srcElement, "DIV", "dmMenu")) {
		y += parseInt(document.body.currentStyle.marginTop) - 6;
	}
	while (el.offsetParent != null){
		el = el.offsetParent;
		//alert(el.nodeName+':'+el.offsetTop);
		y += el.offsetTop;
	}
	return y;
}
// END OF DHTML DROPDOWN MENU;

// 2007.3.6, Ye Wang:
// Article: Printer version
function Print() {
	urls = window.location.href + "&ispf=1";
	window.open(urls, "", "toolbar=no,resizable=yes,scrollbars=yes");
}