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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección e-mail válida.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' debe ser especificado.\n'; }
  } if (errors) alert('Información obligatoria:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function changeCountry(paginaActual) { //v1.0
  //alert (paginaActual)
  	pName = escape(document.orderform.name.value)
  	pLastName = escape(document.orderform.lastName.value)
  	// pCustomerCompany = document.orderform.customerCompany.value
  	pPhone = escape(document.orderform.phone.value)
  	pEmail = escape(document.orderform.email.value)
  	pCedula_rif = escape(document.orderform.cedula_rif.value)
  	pAddress = escape(document.orderform.address.value)
  	pZip = escape(document.orderform.zip.value)
  	pStateCode = escape(document.orderform.stateCode.value)
  	pCity = escape(document.orderform.city.value)
  	pIdPayment = escape(document.orderform.idPayment.value)
	pSeparateShipping = escape(document.orderform.separateShipping.checked)
	parms = "?newCountry=" + escape(document.orderform.countryCode.value)
	parms = parms + "&pName=" + pName + "&pLastName=" + pLastName
	parms = parms /*+ "&pCustomerCompany=" + pCustomerCompany */+ "&pPhone=" + pPhone
	parms = parms + "&pEmail=" + pEmail + "&pCedula_rif=" + pCedula_rif
	parms = parms + "&pAddress=" + pAddress + "&pZip=" + pZip
	parms = parms + "&pStateCode=" + pStateCode + "&pCity=" + pCity
	parms = parms + "&pIdPayment=" + pIdPayment + "&pSeparateShipping=" + pSeparateShipping
	// *** sustituye doble comillas ***
	// parms = parms.replace(/%22/, "%27")
  document.location = "" + paginaActual + parms + "";
}

function changeCountry_CustRegForm(paginaActual) { //v1.0
  //alert (paginaActual)
  	//pCustomerName = document.cutR.customerName.value
  	//pLastName = document.cutR.lastName.value
  	//pCustomerCompany = document.cutR.customerCompany.value
  	//pPhone = document.cutR.phone.value
  	//pEmail = document.cutR.email.value
  	//pCedula_rif = document.cutR.cedula_rif.value
  	//pAddress = document.cutR.address.value
  	//pZip = document.cutR.zip.value
  	//pStateCode = document.cutR.stateCode.value
  	//pCity = document.cutR.city.value
	parms = "?newCountry=" + document.cutR.countryCode.value
	//parms = parms + "&pCustomerName=" + pCustomerName + "&pLastName=" + pLastName
	//parms = parms + "&pCustomerCompany=" + pCustomerCompany + "&pPhone=" + pPhone
	//parms = parms + "&pEmail=" + pEmail + "&pCedula_rif=" + pCedula_rif
	//parms = parms + "&pAddress=" + pAddress + "&pZip=" + pZip
	//parms = parms + "&pStateCode=" + pStateCode + "&pCity=" + pCity
  document.cutR.action = "" + paginaActual + parms + "";
  //alert (document.cutR.action)
}

function changeCountry_CustModForm(paginaActual) { //v1.0
  //alert (paginaActual)
  	//pCustomerName = document.modCust.customerName.value
  	//pLastName = document.modCust.lastName.value
  	//pCustomerCompany = document.modCust.customerCompany.value
  	//pPhone = document.modCust.phone.value
  	pEmail = document.modCust.email.value
  	//pCedula_rif = document.modCust.cedula_rif.value
  	//pAddress = document.modCust.address.value
  	//pZip = document.modCust.zip.value
  	//pStateCode = document.modCust.stateCode.value
  	//pCity = document.modCust.city.value
	parms = "?newCountry=" + document.modCust.countryCode.value
	//parms = parms + "&pCustomerName=" + pCustomerName + "&pLastName=" + pLastName
	//parms = parms + "&pCustomerCompany=" + pCustomerCompany + "&pPhone=" + pPhone
	//parms = parms + "&pEmail=" + pEmail + "&pCedula_rif=" + pCedula_rif
	parms = parms + "&pEmail=" + pEmail
	//parms = parms + "&pAddress=" + pAddress + "&pZip=" + pZip
	//parms = parms + "&pStateCode=" + pStateCode + "&pCity=" + pCity
  document.modCust.action = "" + paginaActual + parms + "";
  //alert (document.modCust.action)
}

function changeShippingCountry() { //v1.0
  	pShippingAddress = escape(document.shippingform.shippingAddress.value)
  	pShippingCity = escape(document.shippingform.shippingCity.value)
  	pShippingZip = escape(document.shippingform.shippingZip.value)
  	pShippingStateCode = escape(document.shippingform.shippingStateCode.value)
  	parms = "?newShippingCountry=" + escape(document.shippingform.shippingCountryCode.value)
	parms = parms + "&pShippingAddress=" + pShippingAddress + "&pShippingCity=" + pShippingCity
	parms = parms + "&pShippingZip=" + pShippingZip + "&pShippingStateCode=" + pShippingStateCode
	// *** sustituye doble comillas ***
	// parms = parms.replace(/%22/, "%27")
document.location = "checkShippingAddress.asp" + parms + "";
}

function SaveOrder(){
if (document.saveorder.agree.checked == false)
{
alert('Para continuar, por favor indique que acepta las Normas');
}else
document.saveorder.submit();
}

// ************** OPEN POPUP NORMAS *********************
var hwndPopup_29cf;
function openpopup_29cf(url){
var ua = window.navigator.userAgent;
var isOpera = (ua.indexOf("Opera") > -1);
if (isOpera) {
	var i = ua.indexOf("Opera");
	var operaVersion = ua.substring(i + 6, ua.indexOf(" ", i + 8));		
	if (operaVersion > 7.00) {
		var isAccessible = false;
		eval("try { isAccessible = ( (hwndPopup_29cf != null) && !hwndPopup_29cf.closed ); } catch(exc) {  } ");
		if (!isAccessible) {
			hwndPopup_29cf = null;
		}
	}			
}
	
if ( (hwndPopup_29cf == null) || hwndPopup_29cf.closed ) {		
	hwndPopup_29cf = window.open("","popupwin_29cf","toolbar=0, scrollbars=1, menubar=0, status=0, resizable=0");
	hwndPopup_29cf.resizeTo(400, 500);
	hwndPopup_29cf.moveTo((screen.width-400)/2, (screen.height-500)/2);
	hwndPopup_29cf.focus(); 
	with(hwndPopup_29cf.document) {
		open();
		write("<ht"+"ml><he"+"ad></he"+"ad><bo"+"dy onLoad=\"document.location='" + url + "'\"></bo"+"dy></ht"+"ml>");
		close();
	}
} else {
	hwndPopup_29cf.focus();
	hwndPopup_29cf.location.href = url;
}
}

// ************** OPEN POPUP EVENT-EDITOR *********************
var hwndPopup_eventos;
function openpopup_eventos(url){
var ua = window.navigator.userAgent;
var isOpera = (ua.indexOf("Opera") > -1);
if (isOpera) {
	var i = ua.indexOf("Opera");
	var operaVersion = ua.substring(i + 6, ua.indexOf(" ", i + 8));		
	if (operaVersion > 7.00) {
		var isAccessible = false;
		eval("try { isAccessible = ( (hwndPopup_eventos != null) && !hwndPopup_eventos.closed ); } catch(exc) {  } ");
		if (!isAccessible) {
			hwndPopup_eventos = null;
		}
	}			
}
	
if ( (hwndPopup_eventos == null) || hwndPopup_eventos.closed ) {		
	hwndPopup_eventos = window.open("","popupwin_eventos","toolbar=0, scrollbars=1, menubar=0, status=0, resizable=0");
	hwndPopup_eventos.resizeTo(680, 500);
	hwndPopup_eventos.moveTo((screen.width-680)/2, (screen.height-500)/2);
	hwndPopup_eventos.focus(); 
	with(hwndPopup_eventos.document) {
		open();
		write("<ht"+"ml><he"+"ad></he"+"ad><bo"+"dy onLoad=\"document.location='" + url + "'\"></bo"+"dy></ht"+"ml>");
		close();
	}
} else {
	hwndPopup_eventos.focus();
	hwndPopup_eventos.location.href = url;
}
}

function SetFocusToSubmit1() {
//alert ('hola');
document.form_buscar.btnBuscar.focus();
}

function SetFocusToSubmit2() {
//alert ('hola');
document.orderform.Submit.focus();
}

function SetFocusToSubmit3() {
//alert ('hola');
document.shippingform.Submit.focus();
}

function SetFocusToSubmit4() {
//alert ('hola');
document.cutR.save.focus();
}

function SetFocusToSubmit5() {
//alert ('hola');
document.modCust.modify.focus();
}

function errorimagen(img)
{
document.images[img.name].src = "/media/no_disponible.jpg"
}

function Confirma(msg) { //v1.0
  var resultado = confirm(msg);
  if (resultado) {
  document.MM_returnValue = true;
  }
  else {
  document.MM_returnValue = false;
  }
}

function ConfirmaEliminarEvento(msg, evt) { //v1.0
  var resultado = confirm(msg);
  if (resultado) {
  //document.MM_returnValue = true;
  document.location="/nueva/store/xw_EventosExec.asp?act=del&evt="+evt+"";
  }
  else {
  //document.MM_returnValue = false;
  }
}

function ConfirmaModificarEvento(msg, evt) { //v1.0
  var resultado = confirm(msg);
  if (resultado) {
  document.MM_returnValue = true;
  document.form_eventos.action="xw_EventosExec.asp?act=edt&evt="+evt+"";
  //document.form_eventos.submit();
  }
  else {
  document.MM_returnValue = false;
  }
}

function ClearField(obj)
{
	obj.value = "";
	obj.onfocus="";
}

// *********** función para imagen captcha de boletines *********
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

// ********** función para extraer parametros del querystring *******
// ********** Se usa en la función addproduct jquery ****************
function getURLVar(urlStr,urlVarName) { 
    var urlHalves = urlStr.split('?'); 
    var urlVarValue = ''; 
    if(urlHalves[1]) { 
        var urlVars = urlHalves[1].split('&'); 
        for(i=0; i<=(urlVars.length); i++){ 
            if(urlVars[i]){ 
                var urlVarPair = urlVars[i].split('='); 
                if (urlVarPair[0] && urlVarPair[0] == urlVarName) { 

                    urlVarValue = urlVarPair[1]; 
                    break; 
                } 
            } 
        } 
    } 
    //alert ("hola")
	return urlVarValue 
}

