var ventana
var cont=0
var titulopordefecto = "SERCOOP-PORTALVÍA" //texto por defecto a mostrar en la barra de título en caso de omitir el argumento titulo

function afoto(cual,titulo)
{
if(cont==1){ventana.close();ventana=null}
if(titulo==null){titulo=titulopordefecto}
ventana=window.open('','ventana','resizable=yes,scrollbars=no')
ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden;" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.cont=0"><img src="' + cual + '" onLoad="opener.redimensionar(this.width, this.height)">')
ventana.document.close()
cont++
}
function redimensionar(ancho,alto)
{
ventana.resizeTo(ancho+13,alto+53)
ventana.moveTo((screen.width-ancho)/2,(screen.height-alto)/2) //centra la ventana. Eliminar si no se quiere centrar el popup
}


function putdash() {
	var tempcode = document.forms["quick"].code.value;
	//var tempcode2 = parseInt(tempcode)+"";
	var regexp = /^[0-9]+$/
	if ((tempcode.length == 7) && regexp.test(tempcode) ) {//&& (tempcode2.length == 7)) {
		var firstpart = tempcode.substring(0,3);
		var secondpart = tempcode.substring(3,7);
		document.forms["quick"].code.value = firstpart + "-" + secondpart;
		document.forms["quick"].units.focus();
	}
	if (tempcode.length == 8) {
		document.forms["quick"].units.focus();
	}
}
function checkQuantity() { 
	
	putdash();
	check = "1";
	checkqOK = document.quick.units.value; 
	checkFrmOK = document.quick.code.value; 
	//alert("Longitud de codigo: " +checkFrmOK.length)
	if (checkFrmOK.length < 8) { alert('Por favor verifique el código de producto.'); check = "0"; document.quick.code.focus(); } 
	if (checkFrmOK.length == 8) { if (checkFrmOK.charAt(3) != "-") { alert('Por favor verifique el código de producto.'); check = "0"; document.quick.code.focus(); } 
		else { check = check } } 
	if (checkqOK == "" || checkqOK == " " || checkqOK == "0" ) { alert('Olvidó rellenar una cantidad.\nEste pedido no está procesado.'); check = "0"; document.quick.code.focus(); } 
	if (checkqOK+'' != Math.floor(parseInt(checkqOK))+'') { alert('Por favor rellene una cantidad válida.'); document.quick.units.focus(); check = "0"; }
	var czs = checkFrmOK.substring(0,3) + checkFrmOK.substring(4,8);

	if (parseInt(czs) != Math.floor(parseInt(czs))) { check = "0"; }
	if (check == "1") {
		document.quick.submit();
	}
} 
//---------------------------------------------------------------------//
//  Funcion RollOver
function show(imgDocID,imgObjName){
    document.images[imgDocID].src = eval(imgObjName + ".src");
}

//---------------------------------------------------------------------//
//  Abrir ventana
function openwindow(location, name, width, height, x, y) {
  window.open(location, name, 'height=' + height + ',width=' + width + ',screenX=' + x + ',screenY=' + y + ',scrollbars=yes,left=' + x + ',top=' + y );
}

//---------------------------------------------------------------------//
//  Dada una cadena comprobamos si es o no una fecha valida
function CorrectDate( vardate ) {
  var dayNr, monthNr, yearNr;
  var bDateOk;
  var bEncDate, bEncMonth,bEncYear;
  var indice, iStartDate,iEndDate,iStartMonth,iEndMonth,iStartYear,iEndYear;
     
  //Inicialización d las var locales
  bDateOk = false;
  bEncDate = false;
  bEncMonth = false;
  bEncYear = false;
  iIStartDate = 0;
  indice = 0;
  //Fin inicializacion var locales
     
  //Encontramos el dia, mes y año en la cadena d texto
  while (((! bEncDate) || (! bEncMonth)|| (! bEncYear)) && (vardate.length >= indice))
  {
	if (vardate.substring(indice,indice+1)=="/"){
		if (! bEncDate)
		   {
			   bEncDate = true;
			   iEndDate = indice;
			   iStartMonth = iEndDate+1;
			   dayNr = vardate.substring(iStartDate,iEndDate);
		   }
		else{
			   bEncMonth = true;
			   iEndMonth = indice;
			   iStartYear = iEndMonth+1;
			   monthNr = vardate.substring(iStartMonth,iEndMonth);
			}
		 }
   		 
		if ((vardate.substring(indice,indice+1)==" "  || indice == vardate.length) && (bEncDate) && (bEncMonth))
			{
				bEncYear = true;
			   iEndYear = indice;
			   yearNr = vardate.substring(iStartYear,iEndYear);
			 }
   	
	indice = indice + 1;
  }
  //Fin while: dia, mes y año obtenidos
     
  //Verificamos q dia, mes y año son validos  
  if (yearNr>=0) {
    if ( (monthNr>=1) && (monthNr<=12)) {    
      if (monthNr==2) {
      // Febrero
        if ( ( (yearNr % 4 == 0) && (yearNr % 100 != 0) ) || (yearNr % 400 == 0) ) { 
        // Es bisiesto
          if ( dayNr<=29 ) { bDateOk=true }
        } else {
          if ( dayNr<=28 ) { bDateOk=true }          
        }
      } else {
        if ( (monthNr==1) || (monthNr==3) || (monthNr==5) || (monthNr==7) || (monthNr==8) || (monthNr==10) || (monthNr==12) ) {
        // Meses de 31 días
          if ((dayNr>=1) && (dayNr<=31) ) { bDateOk=true }
        } else {
        // Meses de 30 días
          if ((dayNr>=1) && (dayNr<=30) ) { bDateOk=true }
        }
      }
    }
  } 
  //Fin verificacion

  return bDateOk;
}

	//  Funciones para entrar desde la Intro de Flash


function esp()
{
       window.location.href="/home.asp?lang=ES";
}
function eng()
{
       window.location.href="/home.asp?lang=EN";
}
	// Fin de la funcion


function popup(name) {
	miRuta= name + '.html';
	ventana=window.open(miRuta, name, 'left=100,top=100,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,height=400,width=440');
	ventana.focus();

}

