var msgValidEmail=' debe contener un e-mail valido. ';
var JsCheck=' Revise la siguiente informaciÃ³n ';
var MustNumber=' debe contener un nÃºmero ';
var MustNumberBetween=' debe contener un nÃºmero entre ';
var Jsand=' y ';
var isReq=' es obligatorio ';
var PassShould=' La contraseÃ±a debe tener al menos 6 dÃ­gitos ';
var PassRetype=' Por favor chequear que contraseÃ±a se ingresada correctamente las dos veces ';

function redirect(url) { //v4.0
  document.location.href = url;
  return false;
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

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]);nm = args[i+1];
    if (val) {  if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' '+msgValidEmail+'.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+ MustNumber+'.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+MustNumberBetween +min+ Jsand +max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+isReq+ '\n'; }
  } if (errors) alert(JsCheck+':\n'+errors);
  document.MM_returnValue = (errors == '');
}

function ValidPassword(p1,p2)
{
var objp1=eval("document.getElementById('"+p1+"')")
var objp2=eval("document.getElementById('"+p2+"')")

if (objp1.value.length<6){
		objp1.select();
		objp1.focus();
		alert(PassShould);
		return false;
}

if (objp1.value != objp2.value)
{
		objp2.select();
		objp2.focus();
		alert(PassRetype);
		return false;
}
return true;
}

function abreventana(direccion,nomven,propiedades) {
  MiVentana=open(direccion,nomven,propiedades);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function HideShowTotal(div1, div2)
 {

    var objUsd=document.getElementById(div1);
    if (null!=objUsd)  objUsd.style.display = "block";

    var objLocal=document.getElementById(div2);
    if (null!=objLocal) objLocal.style.display = "none";

    if (null!=document.getElementById("TotalCur")) document.getElementById("TotalCur").value=div1;
    
 }

 function HideShowDiv(div1, div2)
 {

    var objUsd=document.getElementById(div1);
    if (null!=objUsd)  objUsd.style.display = "block";

    var objLocal=document.getElementById(div2);
    if (null!=objLocal) objLocal.style.display = "none";

 }

function HideShow3divs(div1, div2,div3)
 {

    var objdiv1=document.getElementById(div1);

    if (null!=objdiv1)  objdiv1.style.display = "block";

    var objdiv2=document.getElementById(div2);
    if (null!=objdiv2) objdiv2.style.display = "block";

    var objdiv3=document.getElementById(div3);
    if (null!=objdiv3) objdiv3.style.display = "none";


 }

 function HideDiv(div1)
 {

    var objdiv1=document.getElementById(div1);
    if (null!=objdiv1)  objdiv1.style.display = "none";
 }

 function ShowDiv(div1)
 {

    var objdiv1=document.getElementById(div1);
    if (null!=objdiv1)  objdiv1.style.display = "";
 }
  String.prototype.trim = function()
 {
 	return this.replace(/^\s+|\s+$/g,"");
 }

 String.prototype.ltrim = function()
 {
 	return this.replace(/^\s+/,"");
 }

 String.prototype.rtrim = function()
 {
 	return this.replace(/\s+$/,"");
 }



function CheckWLM(iValue) {
                  document.getElementById("MuestraImagen").value = "";
	document.getElementById("divWLMType1").style.display = 'none';
	document.getElementById("divWLMType2").style.display = 'none';
                  if (iValue < 3) {
		document.getElementById("divWLMType" + iValue).style.display = '';
		if (iValue == 1) { document.getElementById("divWLMSelection").innerHTML = "Marca denominativa"; }
		if (iValue == 2) { document.getElementById("divWLMSelection").innerHTML = "Logo (s&#243;lo como marca figurativa)"; }
	} else if (iValue == 3) {
		document.getElementById("divWLMType1").style.display = '';
		document.getElementById("divWLMType2").style.display = '';
		document.getElementById("divWLMSelection").innerHTML = "Marca denominativa + Logo";
	}
//	document.getElementById("divWLMNote").style.display = 'none';
	updateTotal();
}

function CheckForm(){
var ImageIsReq='Debe subir la imagen';
MM_validateForm('Marca','Marca','R','Descripcion','Haga una breve descripciÃ³n de los productos y/o servicios para los cuales se usarÃ­a la marca:','R');
if (document.MM_returnValue == true) {

}
else {
 return false;
}


document.form1.submit();
}


var venvios = [6,5,19,17,12,10,60,50,,0]

	var enviosIdx		= 0
	var NomPais			= "EspaÃ±a"
	var Service			= "Digital"
	var hasExtensive	= false
	var my_total3
	var my_total4
	// ---
	var cvbasic		= [71.75, 246, 105, 350] // content vector basic
	var cevbasic	= [, , , ]
	var cvclass		= [71.75, 123, 105, 175]
	var cevclass	= [, , , ]
	var cvmax		= [3825, 3825, 5395, 5395]
	var cevmax		= [, , , ]
	var vbasic
	var ExchangeAmount=Number("0.7092")
	//alert(ExchangeAmount);
	var vclass
	var vmax
	// ---
	function initMyTotal()
	{
		if(!my_total3)
			my_total3 = 0
		if(!my_total4)
			my_total4 = 0
	}

	function Init()
	{
		document.getElementById("trFirstLoad").style.display = "";
		updateTotal();
	}
	
	function updateTotal(tipo) {
	var res;
        var tipo1 = parseFloat ( $('#precio_t1').val() );
        var tipo1 = tipo1.toFixed(2);
        var tipo2 = parseFloat ( $('#precio_t2').val() ) ;
        var tipo2 = tipo2.toFixed(2);
		if(document.getElementById("ValorP4").value==""){
	
			if (tipo==true){
			//document.getElementById("ValorP4").value=581.30;
                        $("#ValorP4").val(tipo1);
			}else{
			$("#ValorP4").val('');
			}
		
		}else{
									   
			if (tipo==true){
			res=parseFloat(document.getElementById("ValorP4").value)+parseFloat(tipo2);
			res=res.toFixed(2);
			document.getElementById("ValorP4").value=res;
			}else{
				if (document.getElementById("ValorP4").value==tipo1){
			document.getElementById("ValorP4").value="";
				}else{
				res=parseFloat(document.getElementById("ValorP4").value)-parseFloat(tipo2) ;
				res=res.toFixed(2);
				document.getElementById("ValorP4").value=res;
				}
			}
		}
	}
	
	
	
		function updateTotalFactibilidad(tipo)
	{
		
		if(document.getElementById("ValorP4").value==""){
	
			if (tipo==true){
			document.getElementById("ValorP4").value=77;
			}else{
			document.getElementById("ValorP4").value="";	
			}
		
		}else{
									   
			if (tipo==true){
			document.getElementById("ValorP4").value=parseFloat(document.getElementById("ValorP4").value)+77;
			}else{
				if (document.getElementById("ValorP4").value==77){
				document.getElementById("ValorP4").value="";
				}else{
				document.getElementById("ValorP4").value=parseFloat(document.getElementById("ValorP4").value)-77;	
				}
			}
		}
	}
	

	function calculateDelivery(PaisTitular) // id of the country in the 'PaisesTitulares' table
	{
		if(NomPais == PaisTitular)
			switch(Service)
			{
				case "CorreoNormal":
					enviosIdx = 0
				break;
				case "CorreoCourier":
					enviosIdx = 1
				break;
			}
		else
			switch(Service)
			{
				case "CorreoNormal":
					enviosIdx = 2
				break;
				case "CorreoCourier":
					enviosIdx = 3
				break;
			}
		updateTotal();
	}


function CheckLogo(logo){
  if(logo == "si"){
	document.getElementById("2A").style.display = "block";

	}
  else{
	document.getElementById("2A").style.display = "none";
	document.getElementById("MuestraImagen").value="";
	}
	updateTotal();
}

function CheckTipoEstudio(tipo)
{
	switch(tipo)
	{
		case "base":
			hasExtensive = false
			updateTotal();
		break;
		case "extensivo":
			hasExtensive = true
			updateTotal();
		break;
	}
}

function SumarRegistropatente(){
    var tipo1 = parseFloat ( $('#precio_t1').val() );
        var tipo2 = parseFloat ( $('#precio_t2').val() ) ;
	if (document.getElementById("ValorP4").value!=""){
	document.getElementById("ValorP4").value=Math.round ( parseFloat(document.getElementById("ValorP4").value) + tipo2 );
	}else{
	//document.getElementById("ValorP4").value=626.77;
        document.getElementById("ValorP4").value=tipo1;
	}
	
	}

function BorraRegistropatente(caja){
         var tipo1 = parseFloat ( $('#precio_t1').val() );
        var tipo2 = parseFloat ( $('#precio_t2').val() ) ;
	if(document.getElementById(caja).value!="" ){

            if(document.getElementById("ValorP4").value!=tipo1 ){
                document.getElementById("ValorP4").value=Math.round (  parseFloat(document.getElementById("ValorP4").value) - tipo2 );
                document.getElementById(caja).value="";
                }
            else {
                document.getElementById("ValorP4").value="";
                document.getElementById(caja).value="";
                }
        }
	

}
function BorraRegistroDisenoIndustrial(caja){
        var tipo1 = parseFloat ( $('#precio_t1').val() );
        var tipo2 = parseFloat ( $('#precio_t2').val() ) ;
	if(document.getElementById(caja).value!="" ){

            if(document.getElementById("ValorP4").value!=tipo1 ){
                document.getElementById("ValorP4").value=Math.round (  parseFloat(document.getElementById("ValorP4").value) - tipo2 );
                document.getElementById(caja).value="";
                }
            else {
                document.getElementById("ValorP4").value="";
                document.getElementById(caja).value="";
                }
        }
	

}

function SumarRegistroDisenoIndustrial(){
        var tipo1 = parseFloat ( $('#precio_t1').val() );
        var tipo2 = parseFloat ( $('#precio_t2').val() ) ;
	if (document.getElementById("ValorP4").value!=""){
	document.getElementById("ValorP4").value=Math.round ( parseFloat(document.getElementById("ValorP4").value) + tipo2 );
	}else{
	//document.getElementById("ValorP4").value=626.77;
        document.getElementById("ValorP4").value=tipo1;
	}
	if(document.getElementById("logo1").value=="" && document.getElementById("logo2").value=="" && document.getElementById("logo3").value=="" && document.getElementById("logo4").value=="" && document.getElementById("logo5").value=="" ){
			document.getElementById("ValorP4").value="";
	}
	
}


function CheckMedio(medio){

document.getElementById("M2").style.position = "Static";
document.getElementById("M2").style.display = "block";


switch(medio)
{
		case "D":
			Service = "Digital"
			document.getElementById("M2").style.position = "absolute";
			document.getElementById("M2").style.display = "none";
			document.getElementById("img2").style.display = "none";
			document.getElementById("img1").style.display = "block";

		break;
		case "N":
			Service = "CorreoNormal"
			calculateDelivery(document.form1.envPais[document.form1.envPais.selectedIndex].value)
			document.getElementById("img1").style.display = "none";
			document.getElementById("img2").style.display = "block";
		break;
		case "C":
			Service = "CorreoCourier"
			calculateDelivery(document.form1.envPais[document.form1.envPais.selectedIndex].value)
			document.getElementById("img1").style.display = "none";
			document.getElementById("img2").style.display = "block";
		break;

}
updateTotal();
}
