// STRINGDBASE.JS
/** StringDBase.js
 *  6 OCT 00
 *  Requires Java 1.1 for the section with cookies and 1.0 for the
 *  section with String Manipulation.  It also will require 1.2 if
 *  you prototype the string section.
 *  This code is designed for two reasons 1 to make your life easier
 *  when it comes to cookies and strings that will contain ordered
 *  information that will be contained in strings.
 */

var failCode = -1;  // if you use numbers you can change the error code to letters
var cookieValue = "";  //value of the cookie
var oneYear = 31536000000;  //262800000; // one year in microseconds


function cookieJar(chip)
{
	this.cookieName = chip;
	this.cookieDefault="ES________";
	this.delim = "_";  // standard delimiter for cookies
	this.getVal = getCookieVals;
	this.setVal = setCookieVals;
	this.setDefault = setCookieDefault;
	this.setDelim =	setDelimiter;
	this.eat = killCookie;
	this.exists = existence;
	this.check = cookieCheck;
}

function getCookieVals(value)
{
	if ((cookieValue=GetCookie(this.cookieName)) == null) return failCode;
	return extractStringPiece(cookieValue, value, this.delim);
}

function setCookieVals(value,setTo)
{
	if (((cookieValue=GetCookie(this.cookieName)) == null)||(cookieValue == "")) {
	cookieValue = this.cookieDefault;
	}
	cookieValue = replaceStringPiece(cookieValue, setTo, value, this.delim);
	expDate = new Date();
	expDate.setTime( expDate.getTime() + oneYear );
	SetCookie(this.cookieName, cookieValue, expDate);
}

function setCookieDefault(value){ this.cookieDefault = value;}

function setDelimiter(deli){ this.delim = deli;}

function killCookie()
{
	DeleteCookie(this.cookieName);
}

function existence()
{
	if (((cookieValue=GetCookie(this.cookieName)) != null) && (cookieValue != "")) return true;
	else return false;
}

function cookieCheck()
{
  if(existence()){
   return "deactivated"; 
  }else{ 
   return "activated";
  }//end del if 
  
}//end de la funci?n

function redirect(whereTo)
{
	if (((cookieValue=GetCookie(this.cookieName)) != null) && (cookieValue != "")) 
	{
 	 location.href = whereTo;
	}
}

/* This is a generic version of the UNIX database by strings into JavaScript
 * this will build fast delimited based string databases
 * all of these are based on zero indexed  delimited strings
 * to create a non-stream modifying dbase
 * save the value Over top to makes the changes fixed..
 */

function getDelimitSize(stringName, delimiter)
{
	if((stringName == "")||(stringName == null)) return failCode;
	var currentIndex = 0;
	var size = 0;
	while(currentIndex > -1)
	{
		size++;
		currentIndex = stringName.indexOf(delimiter, currentIndex + delimiter.length);
	}
	return size;
}


function getStartPos(stringName, varc, delimiter)
{
	if((getDelimitSize(stringName, delimiter) < varc)||(0 > varc)) return failCode;
	var currentIndex = 0; // position in Characters
	var currentPos = 0; // position based on delimitation
	while(( currentPos < varc )&&(currentIndex < stringName.length)) 
	{
		currentPos++;
		currentIndex = stringName.indexOf(delimiter, currentIndex + delimiter.length);
	}
	return (0 == varc )?currentIndex:currentIndex+1;
}


function getStopPos(stringName, varc, delimiter)
{
	if((getDelimitSize(stringName, delimiter) < varc)||(0 > varc)) return failCode;
	var currentIndex = 0; // position in Characters
	var currentPos = 0; // position based on delimitation
	while(( currentPos < varc+1 )&&(currentIndex < stringName.length)) 
	{
		currentPos++;
		currentIndex = stringName.indexOf(delimiter, currentIndex + delimiter.length);
	}
	return (varc != (getDelimitSize(stringName, delimiter)-1))?currentIndex-1:stringName.length-1;
}


function extractStringPiece(stringName, varc, delimiter)
{
	if((getDelimitSize(stringName, delimiter) <= varc )||( varc < 0 )) return failCode;
	//if((getStartPos(stringName,varc, delimiter)<0)||(getStopPos(stringName, varc, delimiter)<0)) return "";
	return stringName.substring( getStartPos(stringName,varc, delimiter), getStopPos(stringName, varc, delimiter) +1);
}


function replaceStringPiece(stringName, replaceString, varc, delimiter)
{
	if((getDelimitSize(stringName, delimiter )  < varc )||( varc < 0 )) return failCode;
	return stringName.substring(0, getStartPos(stringName,varc, delimiter)) + replaceString + stringName.substring( getStopPos(stringName, varc, delimiter ) + 1, stringName.length);
}


function deleteStringPiece(stringName, varc, delimiter)
{
	var totalSize = getDelimitSize( stringName, delimiter );
	if(( totalSize < varc )||( varc < 0 )) return failCode;
	if( 0 == totalSize ) return "";
	var retVal =  stringName.substring(0, getStartPos(stringName,varc, delimiter) - delimiter.length);
	if( varc == totalSize) return retval;
	if(0 != varc) return retVal + stringName.substring( getStopPos(stringName, varc, delimiter) + delimiter.length, stringName.length);
	else return stringName.substring( getStopPos(stringName, varc, delimiter) + delimiter.length + 1, stringName.length);
}


function insertStringPiece(stringName, insertString, varc, delimiter)
{
	var totalSize = getDelimitSize( stringName, delimiter );
	if(( totalSize < varc )||( varc < 0 )) return failCode;
	if( 0 == totalSize ) return insertString;
	if( totalSize == varc ) return stringName + delimiter + insertString;
	var addDelimiter = (0 == varc)?"":delimiter;
	var add2Delimiter = (0 != varc)?"":delimiter;
	var retVal =  stringName.substring(0, getStartPos(stringName,varc, delimiter) - delimiter.length);
	return retVal+addDelimiter + insertString +add2Delimiter + stringName.substring(getStartPos(stringName,varc, delimiter) - delimiter.length, stringName.length);

//	if(0 != varc) return retVal + this.stringName.substring( this.getStopPos(this.stringName, varc, delimiter ) + this.delim.length, this.stringName.length);
//	else return this.stringName.substring( this.getStopPos(varc) + this.delim.length + 1, this.stringName.length);
}


// ---------------------------------------------------------------
//  Cookie Functions - Second Helping  (21-Jan-96)
//  Written by:  Bill Dortch, hIdaho Design <BDORTCH@NETW.COM>
//  The following functions are released to the public domain.
//
//  The Second Helping version of the cookie functions dispenses with
//  my encode and decode functions, in favor of JavaScript's new built-in
//  escape and unescape functions, which do more complete encoding, and
//  which are probably much faster.
//	  http://www.netscape.com/newsref/std/cookie_spec.html

/* documentation canceled to save space */

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value, expires)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : "mangoshop.com";
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
 	"; path=" + "/" +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);  // This cookie is history
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//FIN STRINGDBASE.JS


var mangoCookie = new cookieJar("mangoShopCookie");
var idioma = mangoCookie.getVal(0);
var moneda = mangoCookie.getVal(1); // Ahora pais
var idCliente = mangoCookie.getVal(2);
var nCliente = mangoCookie.getVal(3);
var fecha = mangoCookie.getVal(4);
var talla = mangoCookie.getVal(5);
var almacen = mangoCookie.getVal(6);
var entradaUsa = mangoCookie.getVal(7);
var ready = false;


function precioMoneda(precio)
{//La funcion precioMoneda ya no se utiliza ha sido substituida por cantidadConIva(precio)
	moneda = mangoCookie.getVal(1);

	switch(moneda)
	{
		case 'PTS': return formatnumber(precio * 166.386,0);
		case 'FB': return formatnumber(precio * 40.3399,1); // Franco belga
		case 'DM': return formatnumber(precio * 1.95583,2);  // marco alem?n
		case 'FF': return formatnumber(precio * 6.55957,2); // franco franc?s
		case 'IR': return formatnumber(precio * 0.787564,2); // Libra irlandesa
		case 'Lit': return formatnumber(precio * 1936.27,0);// Lira italiana
		case 'FL': return formatnumber(precio * 40.3399,1); //Franco luxemburgu?s
		case 'f': return formatnumber(precio * 2.20371,2); //Flor?n holand?s
		case 'ATS': return formatnumber(precio * 13.7603,2); // Chel?n austr?aco
		case 'ESC': return formatnumber(precio * 200.482,0); //Escudo portugu?s
		case 'Mk': return formatnumber(precio * 5.94573,2);// Marco finland?s
		default: return('--');
	}
}

function cantidadConIva(precio) {//A?ade el iva al precio

	var iva = DevolverIva(); 	
  	if(iva!=null) 
  		return (formatnumber((Math.round((precio * ((iva/100)+1))*100)/100),2));
    else 
    	return (formatnumber(precio,2));
}


function DevolverPais()//Devuelve el nombre del pa?s seg?n idioma
{
	idpais = mangoCookie.getVal(1);//Devuelve el codigo del pais
  idioma = mangoCookie.getVal(0);//Devuelve el codigo del idioma
    
	switch(idpais+idioma)
	{//SELECT 'case '||chr(39)||ID||IDIOMA||chr(39)||': result = '||chr(39)||NVL(DESC_REDUCIDA,DESCRIPCION)||chr(39)||';break;' FROM MNGBD.PAIS Tbl WHERE EUROPEO = 'S' ORDER BY IDIOMA,ID ASC
		case '001AL': result = 'Spanien';break;
		case '003AL': result = 'Niederlande';break;
		case '004AL': result = 'Deutschland';break;
		case '005AL': result = 'Italien';break;
		case '006AL': result = 'Vereinigtes Königreich';break;
		case '007AL': result = 'Irland';break;
		case '008AL': result = 'Dänemark';break;
		case '009AL': result = 'Griechenland';break;
		case '010AL': result = 'Portugal';break;
		case '011AL': result = 'Frankreich';break;
		case '015AL': result = 'Monaco';break;
		case '017AL': result = 'Belgien';break;
		case '018AL': result = 'Luxemburg';break;
		case '019AL': result = 'Kanalinseln';break;
		case '021AL': result = 'Kanarische Inseln';break;
		case '022AL': result = 'Ceuta';break;
		case '023AL': result = 'Melilla';break;
		case '028AL': result = 'Norwegen';break;
		case '030AL': result = 'Schweden';break;
		case '032AL': result = 'Finnland';break;
		case '036AL': result = 'Schweiz';break;
		case '037AL': result = 'Liechtenstein';break;
		case '038AL': result = 'Österreich';break;
		case '043AL': result = 'Andorra';break;
		case '046AL': result = 'Malta';break;
		case '053AL': result = 'Estland';break;
		case '054AL': result = 'Lettland';break;
		case '055AL': result = 'Lituanien';break;
		case '060AL': result = 'Polen';break;
		case '061AL': result = 'Tschechische Republik';break;
		case '063AL': result = 'Slowakei';break;
		case '064AL': result = 'Ungarn';break;
		case '091AL': result = 'Slowenien';break;
		case '600AL': result = 'Zypern';break;
		case '001CA': result = 'Espanya';break;
		case '003CA': result = 'Països Baixos';break;
		case '004CA': result = 'Alemanya';break;
		case '005CA': result = 'Itàlia';break;
		case '006CA': result = 'Regne Unit';break;
		case '007CA': result = 'Irlanda';break;
		case '008CA': result = 'Dinamarca';break;
		case '009CA': result = 'Grècia';break;
		case '010CA': result = 'Portugal';break;
		case '011CA': result = 'França';break;
		case '015CA': result = 'Mònaco';break;
		case '017CA': result = 'Bèlgica';break;
		case '018CA': result = 'Luxemburg';break;
		case '019CA': result = 'Illes Anglonormandes';break;
		case '021CA': result = 'Illes Canàries';break;
		case '022CA': result = 'Ceuta';break;
		case '023CA': result = 'Melilla';break;
		case '028CA': result = 'Noruega';break;
		case '030CA': result = 'Suècia';break;
		case '032CA': result = 'Finlàndia';break;
		case '036CA': result = 'Suïssa';break;
		case '037CA': result = 'Liechtenstein';break;
		case '038CA': result = 'Àustria';break;
		case '043CA': result = 'Andorra';break;
		case '046CA': result = 'Malta';break;
		case '053CA': result = 'Estònia';break;
		case '054CA': result = 'Letònia';break;
		case '055CA': result = 'Lituània';break;
		case '060CA': result = 'Polònia';break;
		case '061CA': result = 'República Txeca';break;
		case '063CA': result = 'Eslovàquia';break;
		case '064CA': result = 'Hongria';break;
		case '091CA': result = 'Eslovènia';break;
		case '600CA': result = 'Xipre';break;
		case '001ES': result = 'España';break;
		case '003ES': result = 'Países Bajos';break;
		case '004ES': result = 'Alemania';break;
		case '005ES': result = 'Italia';break;
		case '006ES': result = 'Reino Unido';break;
		case '007ES': result = 'Irlanda';break;
		case '008ES': result = 'Dinamarca';break;
		case '009ES': result = 'Grecia';break;
		case '010ES': result = 'Portugal';break;
		case '011ES': result = 'Francia';break;
		case '015ES': result = 'Mónaco';break;
		case '017ES': result = 'Bélgica';break;
		case '018ES': result = 'Luxemburgo';break;
		case '019ES': result = 'Islas del Canal';break;
		case '021ES': result = 'Islas Canarias';break;
		case '022ES': result = 'Ceuta';break;
		case '023ES': result = 'Melilla';break;
		case '028ES': result = 'Noruega';break;
		case '030ES': result = 'Suecia';break;
		case '032ES': result = 'Finlandia';break;
		case '036ES': result = 'Suiza';break;
		case '037ES': result = 'Liechtenstein';break;
		case '038ES': result = 'Austria';break;
		case '043ES': result = 'Andorra';break;
		case '046ES': result = 'Malta';break;
		case '053ES': result = 'Estonia';break;
		case '054ES': result = 'Letonia';break;
		case '055ES': result = 'Lituania';break;
		case '060ES': result = 'Polonia';break;
		case '061ES': result = 'República Checa';break;
		case '063ES': result = 'Eslovaquia';break;
		case '064ES': result = 'Hungría';break;
		case '091ES': result = 'Eslovenia';break;
		case '600ES': result = 'Chipre';break;
		case '001FR': result = 'Espagne';break;
		case '003FR': result = 'Pays-Bas';break;
		case '004FR': result = 'Allemagne';break;
		case '005FR': result = 'Italie';break;
		case '006FR': result = 'Royaume-Uni';break;
		case '007FR': result = 'Irlande';break;
		case '008FR': result = 'Danemark';break;
		case '009FR': result = 'Grèce';break;
		case '010FR': result = 'Portugal';break;
		case '011FR': result = 'France';break;
		case '015FR': result = 'Monaco';break;
		case '017FR': result = 'Belgique';break;
		case '018FR': result = 'Luxembourg';break;
		case '019FR': result = 'Îles Anglo-Normandes';break;
		case '021FR': result = 'Îles Canaries';break;
		case '022FR': result = 'Ceuta';break;
		case '023FR': result = 'Melilla';break;
		case '028FR': result = 'Norvège';break;
		case '030FR': result = 'Suède';break;
		case '032FR': result = 'Finlande';break;
		case '036FR': result = 'Suisse';break;
		case '037FR': result = 'Liechtenstein';break;
		case '038FR': result = 'Autriche';break;
		case '043FR': result = 'Andorre ';break;
		case '046FR': result = 'Malte';break;
		case '053FR': result = 'Estonie';break;
		case '054FR': result = 'Lettonie';break;
		case '055FR': result = 'Lituanie';break;
		case '060FR': result = 'Pologne';break;
		case '061FR': result = 'République Tchèque';break;
		case '063FR': result = 'Slovaquie';break;
		case '064FR': result = 'Hongrie';break;
		case '091FR': result = 'Slovénie';break;
		case '600FR': result = 'Chypre';break;
		case '001IN': result = 'Spain';break;
		case '003IN': result = 'Netherlands';break;
		case '004IN': result = 'Germany';break;
		case '005IN': result = 'Italy';break;
		case '006IN': result = 'United Kingdom';break;
		case '007IN': result = 'Ireland';break;
		case '008IN': result = 'Denmark';break;
		case '009IN': result = 'Greece';break;
		case '010IN': result = 'Portugal';break;
		case '011IN': result = 'France';break;
		case '015IN': result = 'Monaco';break;
		case '017IN': result = 'Belgium';break;
		case '018IN': result = 'Luxembourg';break;
		case '019IN': result = 'Channel Islands';break;
		case '021IN': result = 'Canary Islands';break;
		case '022IN': result = 'Ceuta';break;
		case '023IN': result = 'Melilla';break;
		case '028IN': result = 'Norway';break;
		case '030IN': result = 'Sweden';break;
		case '032IN': result = 'Finland';break;
		case '036IN': result = 'Switzerland';break;
		case '037IN': result = 'Liechtenstein';break;
		case '038IN': result = 'Austria';break;
		case '043IN': result = 'Andorra';break;
		case '046IN': result = 'Malta';break;
		case '053IN': result = 'Estonia';break;
		case '054IN': result = 'Latvia';break;
		case '055IN': result = 'Lithuania';break;
		case '060IN': result = 'Poland ';break;
		case '061IN': result = 'Czech Republic';break;
		case '063IN': result = 'Slovakia';break;
		case '064IN': result = 'Hungary';break;
		case '091IN': result = 'Slovenia';break;
		case '400IN': result = 'USA';break;
		case '600IN': result = 'Cyprus';break;
    default: result = null;break;//Si no es ninguno de estos paises se devuelve null
	}//end del switch
  
  //Ahora comprobamos si el pais contiene un nombre m?s concreto entre par?ntesis, si el asi, mostramos solo este nombre
  if((result!=null)&&(nombreReducido())&&(result.indexOf('(')!=-1)&&(result.indexOf(')')!=-1))result=result.substring(result.indexOf('(')+1,result.indexOf(')'));
  
  return result;
  
}//end de la funcion DevolverIva()

var idpais = '';
    
function DevolverIva()//Devuelve el iva 
{   
	if (idpais == '')	
		idpais = mangoCookie.getVal(1);//Devuelve el codigo del pais
  
	switch(idpais)//%
	{//Ejecutar SELECT DISTINCT 'case '||chr(39)||ID||chr(39)||': return 0;' FROM MNGBD.PAIS Tbl WHERE EUROPEO = 'S' ORDER BY 1
    case '001': return 0;
    case '003': return 0;
    case '004': return 0;
    case '005': return 0;
    case '006': return 0;
    case '007': return 0;
    case '008': return 0;
    case '009': return 0;
    case '010': return 0;
    case '011': return 0;
    case '015': return 0;
    case '017': return 0;
    case '018': return 0;
    case '019': return 0;
    case '021': return 0;
    case '022': return 0;
    case '023': return 0;
    case '028': return 0;
    case '030': return 0;
    case '032': return 0;
    case '036': return 0;
    case '037': return 0;
    case '038': return 0;
    case '043': return 0;
    case '046': return 0;
    case '053': return 0;
    case '054': return 0;
    case '055': return 0;
    case '060': return 0;
    case '061': return 0;
    case '063': return 0;
    case '064': return 0;
    case '091': return 0;
    // case '400': return 0;
    case '600': return 0;
		default: return null;//Si no es ninguno de estos paises se devuelve null
	}//end del switch
}//end de la funcion DevolverIva()

function esPaisArancelario(){//Nos dice si el pais contiene aranceles
  
  idpais = mangoCookie.getVal(1);//Devuelve el codigo del pais de la cookie actual
    
	switch(idpais)
	{//SELECT DISTINCT 'case '||chr(39)||ID||chr(39)||': return true;' FROM MNGBD.PAIS Tbl WHERE EUROPEO = 'S' AND COD_ARANCEL IS NOT NULL ORDER BY 1
  case '021': return true;
  case '022': return true;
  case '023': return true;
  case '028': return true;
  case '036': return true;
  case '037': return true;
  case '043': return true;
  //Los dos pa?ses siguiente aparencen en esta funcion ya que para las nueva temporada 1, utilizan multiprice
  //por lo que para que shop1.jsp funcione correctamente debemos incluirlos aqui.(Emilio)NO LO EXPLICO MAS PQ ESTO ES TEMPORAL!
  case '004': return true;//Alemania no es arancelario pero esta funcion se utiliza temporalmente para el Multiprice
  case '011': return true;//Francia no es arancelario pero esta funcion se utiliza temporalmente para el Multiprice
  default: return false;//Si no es ninguno de estos paises se devuelve null
	}//end del switch

}//end del la funcion esPaisArancelario()

function nombreReducido(){
  
  idpais = mangoCookie.getVal(1);//Devuelve el codigo del pais de la cookie actual
    
	switch(idpais)
	{ //SELECT DISTINCT 'case '||chr(39)||ID||chr(39)||': return true;' FROM MNGBD.PAIS Tbl WHERE desc_reducida is not null ORDER BY 1
	case '001': return true;
	case '019': return true;
	case '021': return true;
	case '022': return true;
	case '023': return true;
  default: return false;//Si no es ninguno de estos paises se devuelve null
	}//end del switch

}//end del la funcion esPaisArancelario()

function tallaTallaje(talla)
{
	tallaje = mangoCookie.getVal(5);

	switch(tallaje)
	{
		case '004': return talla+'alemania';
		case '001': return talla+'espa?a';
		case '001': return talla+'francia';
		case '005': return talla+'italia';
		case '412': return talla+'mexico';
		case '006': return talla+'reino unido';
		case '400': return talla+'usa';
		default: return('--')
	}
}

function tallaPais()
{
	talla = mangoCookie.getVal(5);
	idioma =  mangoCookie.getVal(0);
	tallaidioma = talla+idioma;

	switch(tallaidioma) {
		case '004ES': return 'alemania';
		case '001ES': return 'espa?a';
		case '001ES': return 'francia';
		case '005ES': return 'italia';
		case '412ES': return 'mexico';
		case '006ES': return 'reino unido';
		case '400ES': return 'usa';
		default: return('--')
	}
}


function goToShop(flag,prod,estilo,prenda,color,precio)
{
  var oldURL = window.location.href;
  var newURL = '';
    
  if(flag){
		newURL = 'http://www.mangoshop.com/index.jsp?item='+prod+'&estilo='+estilo+'&prenda='+prenda+'&color='+color+'&precio='+precio;
	}else{
    newURL = 'http://www.mangoshop.com/index.jsp';
  }//end del if(flag)
  
  //Comprobamos si en la url existe el parametro cid(change idioma, el idioma ha sido cambiado)
  if(oldURL.indexOf("cid")!=-1){
    if(oldURL.indexOf("?")!=-1)newURL = newURL.concat("?cid");
      else newURL = newURL.concat("?cid");
  }//end del if(url.indexOf("cid")!=-1)
    
  parent.top.document.location = newURL;//Redireccionamos a la nueva URL
}

function formatnumber(number,decimals)
{
 	var i,len;
 	var st='';

 	var d10 = 1;
 	for(i=0;i<decimals;i++)  d10 = d10 * 10

 	num = (Math.round(number*d10))/d10;
 	num = num + "";

 	var posit = num.indexOf(".");

	if (num!='0' && posit == -1)  // no t? decimals
	{
		if (decimals>1) st='.';
		for(i=0;i<decimals;i++) st+='0';
		num += st;
	}
	else
	{
		if (posit == 0)
		{
			num = '0' + num;
			posit++;
		}
		len = num.length
		if (num!='0') for (i=0;i<=decimals-len+posit;i++) num+='0'
	}
 	return(num);
}

function mensaje(msg)
{
	window.status = msg;
	document.valor = true;
}

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_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_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);
	}
	x = d[n];
  	if (!x && d.all) x=d.all[n];
  	if (!x && d.getElementById) x=d.getElementById(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_showHideLayers() { //v3.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) { 
			v = (v=='show')?'visible':(v='hide')?'hidden':v; 
			//}
			obj.style.visibility=v; 
		}
	}	
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

var newwin;

function MM_openBrWindow(theURL,winName,features)  //v2.0
{
	newwin = window.open(theURL,winName,features);
	setTimeout('newwin.focus();',250);
}

function tmt_fullscreen(url,name,features)
{
	var larg_schermo = screen.availWidth - 10;
  var altez_schermo = screen.availHeight - 30;
  newwin = window.open(url, name, "width=" + larg_schermo + ",height=" + altez_schermo + features);
	setTimeout('newwin.focus();',250);
}

function maximizar()
{
	var larg_schermo = screen.availWidth;
	var altez_schermo = screen.availHeight;
	window.moveTo(0,0);
	window.resizeTo(larg_schermo,altez_schermo);
}

function Abreventana(url,name,features)
{
 if (screen.height > '600')
 {
	 MM_openBrWindow(url,name,features);
 }
 else
 {
	 tmt_fullscreen(url,name,features);
 }
}

function tmt_winComm(bers, ord)
{
	return eval(bers + "." + ord);
}

// Funciones para la apertura de las distintas ventanas
var idioma_dir = 's';

	if (idioma == 'ES')	{	idioma_dir = 's';	}
	if (idioma == 'CA')	{	idioma_dir = 'c';	}
	if (idioma == 'AL')	{	idioma_dir = 'd';	}
	if (idioma == 'FR')	{	idioma_dir = 'f';	}
	if (idioma == 'IN')	{	idioma_dir = 'e';	}

function Mangoes()
{	tmt_fullscreen('http://www.mango.com','mnges',',left=0,top=0'); }

function Localizador()
{	MM_openBrWindow('http://www.mango.com/'+idioma_dir+'/tiendas/tiendas.htm?company=si&pais='+mangoCookie.getVal(1)+'&idioma='+idioma_dir,'localizador','width=788,height=540,top=0,left=0'); }

function Catalogo()
{	tmt_fullscreen('http://www.mango.com/' + idioma_dir + '/catalogo/catalogo.asp','cat',',left=0,top=0');}

function Company()
{
	if (screen.height > 600) MM_openBrWindow('http://www.company.mango.com/'+idioma_dir+'/index.htm','company','toolbar=yes,menubar=yes,width=790,height=620,left=0,top=0');
	else MM_openBrWindow('http://www.company.mango.com/'+idioma_dir+'/index.htm','company','toolbar=yes,menubar=yes,width=790,height=465,left=0,top=0');
}

function copyright()
{	MM_openBrWindow('copyright_'+idioma+'.htm','copy','width=410,height=420,top=0,left=0,scrollbars=yes');}

function Tallas()
{	
  MM_openBrWindow('/medidas/medidas.htm#0'+ '_'+ idioma ,'medidas','width=427,height=410,top=0,left=0');
}

function Devolucion(pedido)
{	MM_openBrWindow('../printForm/devolucion_print.jsp?pedido='+pedido,'devolucion','width=700,height=480,top=0,left=0,scrollbars=auto');}

function Medidas()
{
	var x = FichaObj.familia;
	if (x == '' || x == null) x = '0';
	MM_openBrWindow('/medidas/medidas.htm#'+ x + '_'+ idioma ,'medidas','width=427,height=410,top=0,left=0');
}

function Cambiar_talla()
{
	MM_openBrWindow('/tallas/talla.htm','tallas','width=410,height=400,top=0,left=0');
}

function Impuestos()
{
	MM_openBrWindow('/impuestos/impuestos.htm' ,'impuestos','width=460,height=470,top=0,left=0,scrollbars=yes');
}

function Tallas_Impuestos()
{
	MM_openBrWindow('/impuestos/tallas_impuestos.htm' ,'impuestos','width=460,height=460,top=0,left=0,scrollbars=yes');
}

function Contacto()
{	MM_openBrWindow('/contratos/contacto.htm', 'Contacto', 'width=400,height=320,left=0,top=0');}

function Faqs()
{	MM_openBrWindow('/faqs/faqs.htm', 'Faqs', 'width=427,height=410,top=0,left=0,scrollbars=yes');}

function Condiciones(){	
	if(almacen="400") MM_openBrWindow('http://www.mangoshop.com/ayuda/us/ayuda.jsp?seccion=contrato', 'Condicionescompra', 'width=781,height=536,left=0,top=0');
	else MM_openBrWindow('http://www.mangoshop.com/ayuda/'+idioma+'/ayuda.jsp?seccion=contrato', 'Condicionescompra', 'width=781,height=536,left=0,top=0');
}

function Condiciones_tarjeta_empleado()
{	MM_openBrWindow('http://www.mangoshop.com/ayuda/empleado/contrato.htm','ayuda','scrollbars=yes,directories=false,menubar=false,resizable=no,width=575,height=470');}
 
function Condcheque()
{	MM_openBrWindow('/contratos/contratocheq.htm', 'Condicionescompra', 'width=427,height=470,left=0,top=0');}

function Devoluciones(){	
	if(almacen="400") MM_openBrWindow('ayuda/us/ayuda.jsp?seccion=cambios','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('ayuda/'+idioma+'/ayuda.jsp?seccion=cambios','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function Registro(){
	if(almacen="400") MM_openBrWindow('/ayuda/us/ayuda.jsp?seccion=registro&subseccion=confidencialidad','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('/ayuda/'+idioma+'/ayuda.jsp?seccion=registro&subseccion=confidencialidad','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function RegistroUSA()
{	MM_openBrWindow('/ayuda/us/ayuda.jsp?seccion=registro&subseccion=confidencialidad','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');}

function Transporte(){	
	if(almacen="400") MM_openBrWindow('ayuda/us/ayuda.jsp?seccion=transporte','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('ayuda/'+idioma+'/ayuda.jsp?seccion=transporte','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function Cobertura(){	
	if(almacen="400") MM_openBrWindow('ayuda/us/ayuda.jsp?seccion=transporte','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('ayuda/'+idioma+'/ayuda.jsp?seccion=transporte','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function Pago(){	
	if(almacen="400") MM_openBrWindow('ayuda/us/ayuda.jsp?seccion=pago','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('ayuda/'+idioma+'/ayuda.jsp?seccion=pago','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function Moneda_impuestos(){	
	if(almacen="400") MM_openBrWindow('ayuda/us/ayuda.jsp?seccion=contrato&subseccion=moneda','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
	else MM_openBrWindow('ayuda/'+idioma+'/ayuda.jsp?seccion=contrato&subseccion=moneda','ayuda','directories=false,menubar=false,resizable=no,width=781,height=536');
}

function Sign(fichero)
{	MM_openBrWindow(fichero,'login','width=410,height=200,top=0,left=0,scrollbars=no');}

function Tiendas()
{ MM_openBrWindow('http://www.mango.com/'+idioma_dir+'/tiendas/tiendas.htm?company=si&pais='+mangoCookie.getVal(1)+'&idioma='+idioma_dir,'localizador','width=788,height=540,top=0,left=0'); }

function Formatcliente(){
MM_openBrWindow('http://www.mango.com/formulari/formshop_'+idioma_dir+'.asp','form','width=560,height=542,scrollbars=yes');
}
function FormatclienteUsa()
{	MM_openBrWindow('http://www.mango.com/formulari/formshop_usa.asp','form','width=560,height=542,scrollbars=yes');}

function FormatclienteChat()
{	MM_openBrWindow('http://www.mango.com/formulari/formshop_'+idioma_dir+'.asp?proc=EC','form','width=560,height=542,scrollbars=yes');}

function FormatclienteChatUsa()
{	MM_openBrWindow('http://www.mango.com/formulari/formshop_usa.asp?proc=EC','form','width=560,height=542,scrollbars=yes');}

function FormatclientewebChat(){
	MM_openBrWindow('http://www.mango.com/formulari/form_'+idioma_dir+'.asp?proc=EC','form','scrollbars=yes,width=560,height=540');
}

// Funciones de cambio de moneda y talla llamadas externamente
function Cambio()
{
	var form = document.canvi;
	for (i=0;i<form.elements.length;i++)
	{
		if ((form.elements[i].checked) && (form.elements[i].type == "radio"))
		{
			var newmoneda = form.elements[i].value;
			mangoCookie.setVal(1,newmoneda);
			if(top.opener.update) top.opener.updatePantalla();
		}
	}
	window.close();
}

function CambioTalla()
{
	var form = document.canvi;
	for (i=0;i<form.elements.length;i++)
	{
		if ((form.elements[i].checked) && (form.elements[i].type == "radio"))
		{
			var newtalla = form.elements[i].value;
		}else if(form.elements[i].type == 'select-one'){
      var indice = form.cambio.selectedIndex;
      var newtalla = form.cambio.options[indice].value;
    }
    if(newtalla!=null){
			mangoCookie.setVal(5,newtalla);
			if(top.opener.updateTalla)	top.opener.updateTallas();
    }
	}
	top.window.close();
}

function CambioImpuestos()
{
	var form = document.canvi_impuestos;
	for (i=0;i<form.elements.length;i++)
	{
		if ((form.elements[i].checked) && (form.elements[i].type == "radio")) 
		{
			var newpais = form.elements[i].value;
		}else if(form.elements[i].type == 'select-one'){
      var indice = form.cambio.selectedIndex;
      var newpais = form.cambio.options[indice].value;
    }
    if(newpais!=null){
      var is_oldpais_arancelario = esPaisArancelario();//Devuelve true si el pais de la cookie(ANTES de cambiarlo) es arancelario
			mangoCookie.setVal(1,newpais);//Introducimos en la cookie el id del nuevo pais escogido
      var is_newpais_arancelario = esPaisArancelario();//Devuelve true si el pais de la cookie(DESPU?S de cambiarlo) es arancelario
      if((is_oldpais_arancelario)||(is_newpais_arancelario)){
        top.opener.location.reload();//Recarga la p?gina shop1_*.jsp porque tiene que recargar los precios
      }else{
        if(top.opener.updatePais)	top.opener.updatePaises();//Actualiza las capas con los nuevos precios segun el nuevo iva
      }//end del if
    }//end del if(newpais!=null)
    

	}
	top.window.close();
}

function CambioTallas_Impuestos(){
  CambioTalla();
  CambioImpuestos();
}

function chequea_moneda()
{
	for (i=0;i<document.canvi.elements.length;i++)
	{
		if ((moneda == document.canvi.elements[i].value) && (document.canvi.elements[i].type == "radio"))
 		{
			document.canvi.elements[i].checked = true;
		}
	}
}

function chequea_talla()
{
	for (i=0;i<document.canvi.elements.length;i++)
	{
	 	if ((talla == document.canvi.elements[i].value) && (document.canvi.elements[i].type == "radio")){
			document.canvi.elements[i].checked = true;
    }else if(document.canvi.elements[i].type == 'select-one'){
      for(j=document.canvi.cambio.options.length-1;j>=0;j--){ 
        if(document.canvi.cambio.options[j].value == talla) { 
          document.canvi.cambio.options[j].selected = true; 
        } //end del if
      } //end del for  
    }//end del elseif(form.elements[i].type == 'select-one')
	}
}


// Fin funcion de monedas y tallas


//changeCookie(valor1, valor2, valor3)-> ID, Nombre, Fecha alta
function changeCookie(valor1, valor2, valor3)
{
	if ( mangoCookie.getVal(0) == -1  || mangoCookie.getVal(2) == -1)
	{
		mangoCookie.eat();
		mangoCookie = new cookieJar("mangoShopCookie");
	}
	mangoCookie.setVal(2,valor1);
	mangoCookie.setVal(3,valor2);
	mangoCookie.setVal(4,valor3);
}


//function ActivarIdioma(pIdioma,pMoneda) {
//	// ERROR Y2k
//	expDate = new Date();
//	expDate.setTime( expDate.getTime() + (365 * 24 * 60 * 60 * 1000) );
//	SetCookie("mangoShopCookie", pIdioma+'_'+pMoneda+'_'+'_', expDate);
//}

function getMoneda()
{
	var st = GetCookie("mangoShopCookie");
	if(st==null) return('');
	var index = st.indexOf('_');
	if(index==-1) return('');
	return st.substring(index+1,st.length);
}


//function talladesc(talla) {
//	switch (talla) {
//	case 'XS': return '19';
//	case 'S': return '20';
//	case 'M': return '21';
//	case 'L': return '22';
//	case 'XL': return '23';
//	case 'XXL': return '24';
//	case 'U': return '99';
//	default: return talla;
//	}
//}

function Logout()
{
	if(mangoCookie.exists() == true)
	{
		changeCookie('','','');
		window.location.reload( false );
		return;
	}
}

function Info()
{
	top.location.href = 'https://ssl.mangoshop.com/datosusuario1.jsp';
}

function Pedido()
 {
 	 top.location.href = 'https://ssl.mangoshop.com/pedidos1.jsp'; 	
 }
