var IFrameObj; //IFrame object
function callToServer( URL ) {
	if (!document.createElement) {
        return true
    };
	var IFrameDoc;

	if ( URL == '' ) {
      return false
    };

	if ( !IFrameObj && document.createElement ) {
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);

			if (document.frames) {
				IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			iframeHTML='<iframe id="RSIFrame" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}

	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		setTimeout('callToServer("'+ URL +'")',10);
		return false;
	}

	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument;
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}

    IFrameDoc.location.replace( URL );
	return false;
}

function llenarComboProvincia( provincias, formName, preselect ) {
    /* Siempre limpiar combo ciudad */
    document[formName].cmb_city.length = 0;
    document[formName].cmb_city.options[0] = new Option( 'Seleccione la Localidad', '' );
    /* Luego cargar el combo */
    cmb = document[formName].cmb_province;
    cmb.length = 0;
    for ( var i=0; i < provincias.length; i++) {
      cmb.options[i] = new Option( provincias[i][1], provincias[i][0] );
      if ( preselect == provincias[i][0] )
        cmb.options[i].selected = true;
    }
}
function llenarComboLocalidad( localidades, formName, preselect ) {
    cmb = document[formName].cmb_city;
    cmb.length = 0;
    for ( var i=0; i < localidades.length; i++) {
      cmb.options[i] = new Option( localidades[i][1], localidades[i][0] );
      if ( preselect == localidades[i][0] )
        cmb.options[i].selected = true;
    }
}
/* Funciones para NewUser */
function getPaisId() {
    cmb = document.frmNewUser.cmb_country;
    return cmb.options[ cmb.selectedIndex ].value;
}
function getProvinceId() {
    cmb = document.frmNewUser.cmb_province;
    return cmb.options[ cmb.selectedIndex ].value;
}
/* Validar e-mail */
function isValidEMail( e_mail ) {
    return ( e_mail.indexOf(".") > 2 ) && ( e_mail.indexOf("@") > 0 );
}
/* Elimina los espacios de los bordes de un String */
function trim( str ) {
    if ( str == "" ) {
        return str;
    } else {
        return str.replace(/^\s*|\s*$/g, "");
    }
}
/* Validar formulario NewUser */
function validateNewUser() {
    if ( trim( document.frmNewUser.email.value ) == "" ) {
        document.frmNewUser.email.focus();
        alert('Falta ingresar el e-mail');
        return false;
    }
    if ( ! isValidEMail( document.frmNewUser.email.value ) ) {
        document.frmNewUser.email.value = trim( document.frmNewUser.email.value );
        document.frmNewUser.email.focus();
        alert('El e-mail ingresado no es valido');
        return false;
    }
    if ( trim( document.frmNewUser.first_name.value ) == "" ) {
        document.frmNewUser.first_name.focus();
        alert('El nombre ingresado no es valido');
        return false;
    }
    if ( trim( document.frmNewUser.last_name.value ) == "" ) {
        document.frmNewUser.last_name.focus();
        alert('El apellido ingresado no es valido');
        return false;
    }
    if ( ( trim( document.frmNewUser.passwd.value ) == "" ) ||
         ( trim( document.frmNewUser.passwd2.value ) == "" ) ) {
        document.frmNewUser.passwd.focus();
        alert('La clave ingresada no es valida');
        return false;
    }
    if ( document.frmNewUser.passwd.value.toLowerCase() != document.frmNewUser.passwd2.value.toLowerCase() ) {
        document.frmNewUser.passwd.focus();
        alert('Las claves no coinciden');
        return false;
    }
    if (document.frmNewUser.cmb_country.value == 0){
        alert('Debe elegir un país');
        return
    }
    document.frmNewUser.submit()
}
/* Validar formulario NewComment */
function validateNewComment() {
    if ( trim( document.frmNewComment.title.value ) == "" ) {
        document.frmNewComment.title.focus();
        alert('Falta ingresar el título');
        return false;
    }
    if ( trim( document.frmNewComment.comment.value ) == "" ) {
        document.frmNewComment.comment.focus();
        alert('Falta ingresar el comentario');
        return false;
    }

    return true;
}

/* Funciones de la deseñadora */
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 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_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 showHide(choice){
  if( document.getElementById(choice).style.display == 'none'){
    document.getElementById(choice).style.display = '';
  }else{
    document.getElementById(choice).style.display = 'none';
  }
}

function submit_on_enter(event,ourform) {
  if (event && event.which == 13) {
    /* Mozilla */
	ourform.submit();
  } else if (event && event.keyCode == 13) {
    /* IE */
	ourform.submit();
  } else {
	return true;
  }
}