/* ajax utils(inicio)....................................................................*/
var AjaxConst = {
	XMLHTTP_STATUS_LOADING	: 1,
	XMLHTTP_STATUS_COMPLETE	: 4,
	HTTP_RESPONSE_STATUS_OK	: 200
};//;

var outputResponse = {
	HTTP_RESPONSE_NULL 								: 0,
	HTTP_RESPONSE_ERROR 							: 1,
	HTTP_RESPONSE_OK 									: 2,
	HTTP_RESPONSE_FINISHED_AUTHORIZED	: 3,
	HTTP_RESPONSE_FINISHED_NORMAL			: 4
};//;

function getRequestBody(oForm) {
	var sParam = "";
	var aParams = new Array();
	var eFormElement				= "";
	var eFormElementName		= "";
	var eFormElementValue		= "";
	
	for(var i=0; i < oForm.elements.length; i++) {
		eFormElement = oForm.elements[i];
		eFormElementName = eFormElement.name;
		eFormElementValue = eFormElement.value;
		
		if(eFormElement.type=="checkbox" || eFormElement.type=="radio") {
				sParam = encodeURIComponent(eFormElementName);
				sParam += "=";		
			if(eFormElement.checked) {
				sParam +=  encodeURIComponent(eFormElementValue);
			} else {
				sParam +=  encodeURIComponent("off");
			}
		} else {
			sParam = encodeURIComponent(eFormElementName);
			sParam += "=";
			sParam +=  encodeURIComponent(eFormElementValue);
		}
		aParams.push(sParam);
	}
	return aParams.join("&");
}//;

function postData() {

	var oForm = document.forms[0];
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.setRequestHeader("Accept-Charset", "iso-8859-1");
	
	oXmlHttp.onreadystatechange = function() {
		//-->
		var loadingState = (oXmlHttp.readyState == AjaxConst.XMLHTTP_STATUS_LOADING) ? "loading" : "";
		var ostatusWrapper = document.getElementById("buttonregwrap");
		ostatusWrapper.className = loadingState;
		//<--
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
				validatingRegister(oXmlHttp.responseText);
			} else {
				validatingRegister("Ocurrio un error. " + oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);

}//;

function postDataV2() {

	var oForm = document.forms[1];
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.setRequestHeader("Accept-Charset", "iso-8859-1");
	
	oXmlHttp.onreadystatechange = function() {
		//-->
		var loadingState = (oXmlHttp.readyState == AjaxConst.XMLHTTP_STATUS_LOADING) ? "loading" : "";
		var ostatusWrapper = document.getElementById("buttonregwrap");
		ostatusWrapper.className = loadingState;
		//<--
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
				validatingRegister(oXmlHttp.responseText);
			} else {
				validatingRegister("Ocurrio un error. " + oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);

}//;
/* ajax utils(fin).......................................................................*/

/* DOM utils(fin).......................................................................*/
function clearingInnerHtml(elementToClearing) {
	while(elementToClearing.firstChild) {
		elementToClearing.removeChild(elementToClearing.firstChild);
	}
}//;
function addOptions(eSelect, sValue, sText) {
		var eNewOption = document.createElement('option');
		eNewOption.value = sValue;
		eNewOption.text = sText;
		try {
			eSelect.add(eNewOption, null);		// standard compliant
		} catch(ex) {
			eSelect.add(eNewOption); 					// for ie only
		}
}//;


//~ function clearPreviusOptions() {
	//~ var eSelect = document.getElementById("cbosubcategory");
	//~ var numItems = eSelect.length;
	//~ if(numItems > 1) {
		//~ for(i=numItems-1;i>0;i--) {
			//~ eSelect.remove(i);
		//~ }
	//~ }
//~ }//;

function clearPreviusOptions(eToClear) {
	var numItems = eToClear.length;
	if(numItems>1) {
		for(var i=numItems-1;i>0;i--) {
			eToClear.remove(i);
		}
	}
}//;

function drawWarnings(eWrap, sWarningList, sClassWrap) {
		
		var eListWarnings = document.createElement("ul");
		for(var i=0; i<sWarningList.length; i++) {
			var eItemWarning = document.createElement("li");
			var sWarningText = replaceWithEntitiesIn(sWarningList[i]);
			eItemWarning.appendChild(document.createTextNode(sWarningText));
			eListWarnings.appendChild(eItemWarning);
		}
		eWrap.className = sClassWrap;
		eWrap.appendChild(eListWarnings);
}
function drawGoToEdit(eWrap, aNoticeParams, sClassWrap) {
		var sPathUrl		= aNoticeParams[0];
		var iUserId			= parseInt(aNoticeParams[1], 10);
		
		var eListNotice	= document.createElement("ul");
		var eItemNotice	= document.createElement("li");
		var eUrl				= document.createElement("a");
		
		eUrl.setAttribute("href",sPathUrl+"editar-usuario.asp?user="+iUserId);
		
		eUrl.target		= "_blank";
		var eUrlText 	= "Te invitamos a que edites tus datos de registro.";
		eUrlText 			= eUrlText.replace('&iacute;','\xed');
		
		eUrl.appendChild(document.createTextNode(eUrlText));
		eItemNotice.appendChild(eUrl);
		eListNotice.appendChild(eItemNotice);
		eWrap.className = sClassWrap;
		eWrap.appendChild(eListNotice);
}
/* DOM utils(fin).......................................................................*/
function addLoadEvent(func) {
  if (!document.getElementById | !document.getElementsByTagName)
		return;
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}//;

function popupFactory(sUrl, sHtmlTitle, iWidth, iHeight, showScrollbars) {
	var iXPosition = ((screen.width - iWidth)/2);
	var iYPosition = ((screen.height - iHeight)/2);
	
	var params = 	"width=" 	+ iWidth.toString() 			+ ",";
			params +=		"height=" + iHeight.toString() 			+ ",";
			params +=		"left=" 	+ iXPosition.toString() 	+ ",";
			params +=		"top=" 		+ iYPosition.toString() 	+ ",";
			params +=		"toolbar=no,";
			params +=		"resizable=yes,";
			params +=		(showScrollbars == 'Yes') ? "scrollbars=yes" : "scrollbars=no";
	
	window.open(sUrl, sHtmlTitle, params);
}//;

function replaceWithEntitiesIn(sTextToParse) {
	var sReturnValue = "";
	sReturnValue = sTextToParse;
	//~ '\xe1' (á), '\xe9' (é), '\xed' (í), '\xf3' (ó), '\xfa' (ú), '\xf1' (ñ)
	sReturnValue = sReturnValue.replace(/&aacute;/g,'\xe1');
	sReturnValue = sReturnValue.replace(/&eacute;/g,'\xe9');
	sReturnValue = sReturnValue.replace(/&iacute;/g,'\xed');
	sReturnValue = sReturnValue.replace(/&oacute;/g,'\xf3');
	sReturnValue = sReturnValue.replace(/&uacute;/g,'\xfa');
	sReturnValue = sReturnValue.replace(/&ntilde;/g,'\xf1');
	return sReturnValue;
}//;

function addEvent(elm, evType, fn, useCapture) {
	if(elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
	} else if(elm.attachEvent) {
		elm.attachEvent('on'+evType, fn);
	}
}//;

function removeEvent(elm, evType, fn, useCapture) {
	if(elm.removeEventListener) {
		elm.removeEventListener(evType, fn, useCapture);
	} else if(elm.detachEvent) {
		elm.detachEvent("on"+evType, fn);
	}
}//;

function hiddenThis(oElements) {
	var elementToAppy;
	for(var i=0; i < oElements.length; i++) {
		elementToAppy = document.getElementById(oElements[i]);
		elementToAppy.className = "elementHidden";
	}
}//;

function setmaxlength(oElement) {
	var mlength=oElement.getAttribute? parseInt(oElement.getAttribute("maxlength")) : "";
	if (oElement.getAttribute && oElement.value.length>mlength) {
		oElement.value=oElement.value.substring(0,mlength);
	}
		
}//;

function virtual(URL) {
	var pl = Math.floor((screen.width - 800) / 2);
	var pt = Math.floor((screen.height - 600) / 2);
	newWin = open(URL, "Banca_Virtual_Banco_de_Guayaquil", "width=800,height=600,left=" + pl + ",top=" + pt + "", "true");
	if (newWin.opener == null) {
		newWin.opener = self;
	}
}//;

function cleanFormElements() {
	var eInputs = document.getElementsByTagName("input");
	for(var i=0; i<eInputs.length; i++) {
		if(eInputs[i].type == "text") {
			eInputs[i].value = "";
		}
		if(eInputs[i].type == "radio") {
			eInputs[i].checked = false;
		}
	}

  //~ for (var i = 0; (i < document.forms.length); i++) {
    //~ document.forms[i].reset();
  //~ }

}//;

function clearBlockCard1() {
	var oVRad1 = document.getElementById("radvisa1");
	//~ var oVPoints1 = document.getElementById("txtpuntosvisa1");
	//~ var oVBin1 = document.getElementById("txtBINvisa1");
	//~ var oVNum1 = document.getElementById("txtNrovisa1");

	var oMRad1 = document.getElementById("radmastercard1");
	//~ var oMPoints1 = document.getElementById("txtpuntosmastercard1");
	//~ var oMBin1 = document.getElementById("txtBINmastercard1");
	//~ var oMNum1 = document.getElementById("txtNummastercard1");
	
	oVRad1.checked = false;
	//~ oVPoints1.value = "";
	//~ oVBin1.value = "";
	//~ oVNum1.value = "";

	oMRad1.checked = false;
	//~ oMPoints1.value = "";
	//~ oMBin1.value = "";
	//~ oMNum1.value = "";
}

function clearBlockCard2() {
	var oVRad2 = document.getElementById("radvisa2");
	//~ var oVPoints2 = document.getElementById("txtpuntosvisa2");
	//~ var oVBin2 = document.getElementById("txtBINvisa2");
	//~ var oVNum2 = document.getElementById("txtNrovisa2");
	
	var oMRad2 = document.getElementById("radmastercard2");
	//~ var oMPoints2 = document.getElementById("txtpuntosmastercard2");
	//~ var oMBin2 = document.getElementById("txtBINmastercard2");
	//~ var oMNum2 = document.getElementById("txtNummastercard2");
	
	oVRad2.checked = false;
	//~ oVPoints2.value = "";
	//~ oVBin2.value = "";
	//~ oVNum2.value = "";
			
	oMRad2.checked = false;
	//~ oMPoints2.value = "";
	//~ oMBin2.value = "";
	//~ oMNum2.value = "";
}

