function openWindow(parametros, ancho, alto) {
		derecha=(screen.width-ancho)/2;
		arriba=(screen.height-alto)/2;
		string="toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width="+ancho+",height="+alto+",left="+derecha+",top="+arriba+"";
			
		fin=window.open('popup.php?'+parametros,"ventana", string);
	}
	
function openWindow2(pgn, parametros, ancho, alto, scrollbars, resizable) {
	derecha=(screen.width-ancho)/2;
	arriba=(screen.height-alto)/2;
	
	if(resizable==true)
		resizable = 1;
	else
		resizable = 0;
		
	if(scrollbars==true)
		scrollbars = 1;
	else
		scrollbars = 0;
	
	string="toolbar=0,scrollbars="+scrollbars+",location=0,statusbar=0,menubar=0,resizable="+resizable+",width="+ancho+",height="+alto+",left="+derecha+",top="+arriba+"";
		
	fin=window.open(pgn+'?'+parametros,"ventana", string);
}

function dimensionar(ancho, alto, centro) {
	if(centro==true) {
		derecha=(screen.width-ancho)/2;
		arriba=(screen.height-alto)/2;
		window.moveTo(derecha,arriba);
	}
	
	window.resizeTo(ancho,alto);
}

function darFoco(id) {
	id = document.getElementById(id);
	if(id)  {
		id.focus();
	} else {
		self.focus();
	}
}

function doPost(frm, params) {
	var frm = document.getElementById(frm);
	if(frm) {
		frm.action = params;
		frm.submit();
	}
}

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) {
 var argv = setCookie.arguments;
 var argc = setCookie.arguments.length;
 var expires = (2 < argc) ? argv[2] : null;
 var path = (3 < argc) ? argv[3] : null;
 var domain = (4 < argc) ? argv[4] : null;
 var secure = (5 < argc) ? argv[5] : false;
 
 path="/";
 
 document.cookie = name + "=" + escape (value) +
 ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
 ((path == null) ? "" : ("; path=" + path)) +
 ((domain == null) ? "" : ("; domain=" + domain)) +
 ((secure == true) ? "; secure" : "");
}


var carro = document.getElementById("car");
function car(dom) {
 

  var objDom = document.getElementById(dom);
  if (confirm('Agregar este producto a su carrito de compras?') == true)
  { 
  addToCar(dom);
  }
  

}


function addToCar(dom) {
var tmp = getCookie("car");
if(tmp==null || tmp=='') {
tmp = dom;
}
else
tmp = getCookie("car") +  "@" + dom;
setCookie("car", tmp);
window.location.reload(true);
}


function deleteFromCar(dom) {
    var tmp;
    var arrTmp = Array();
    arrTmp = getCookie("car").split("@");
    tmp = "";
    var cc;
	cc=0;
	for(var i=0; i<arrTmp.length; i++) {
     
	 //si el item es distinto del q se elimina
	 if(dom!=arrTmp[i] && arrTmp[i]!='' && i!=arrTmp.length-1) {
       tmp += arrTmp[i] + "@";
	 }
	 
	 if(dom!=arrTmp[i] && arrTmp[i]!='' && i==arrTmp.length-1) {
       tmp += arrTmp[i];
	 }
	 
	 /// si el item esta repetido  y es el primero
	 if(dom==arrTmp[i] && arrTmp[i]!='' && cc==0 ) {
       cc=1;
	 }
	 
	 if(dom==arrTmp[i] && arrTmp[i]!='' &&  cc > 1 && i!=arrTmp.length-1) {
       tmp += arrTmp[i] + "@";
	 }
	 if(dom==arrTmp[i] && arrTmp[i]!='' &&  cc > 1 && i==arrTmp.length-1) {
       tmp += arrTmp[i];
	 }
	 
	 
	 if (cc==1) {
	   cc=2;
	 }
	  
    }

    setCookie("car", tmp);
    var objDomOriginal = document.getElementById(dom);

   
    //showCar();
   }
  
function val(formulario) {
	
	var error = false;
	var mensaje="";
	if (formulario.email.value=='')
	{
	mensaje=mensaje + " ==> No ha ingresado su Email.\n";
	alert(mensaje);
	formulario.email.focus();
	return false; 
	}
	else { 
	
	var filter=/^(\w+\.)*\w+\@([-!"&,;\w]+\.)+\w{2,3}$/;
	if (filter.test(formulario.email.value))
	error=false;
	
	else {
	mensaje=mensaje + " ==> Ingrese un email Valido.\n";
	error=true;
	}
	}
	if (error)
	{
	alert(mensaje);
	formulario.email.focus();
	return false;
	}

	}
	
function delteFromCar(dom) {
var tmp;
var arrTmp = Array();
arrTmp = getCookie("car").split("@");
tmp = "";
var cc;
cc=0;

for(var i=0; i<arrTmp.length; i++) {
// si el dominio no esta vacio 
 if (arrTmp[i]!='') { 

// si el dominio  no es el seleccionado

 // si el dominio es el seleccionado
 if (dom == arrTmp[i]) {
	
	if(cc==0 ) {
	cc=1;
	}

	if (i!=arrTmp.length-1 && cc > 1 ) {
		
		tmp += arrTmp[i] + "@";
	}
 	
	if (i==arrTmp.length-1 && cc > 1 ) {
		
		tmp += arrTmp[i];
	}
	
	if (cc==1) {
	cc=2;
	}
   }
   
   
 if (dom != arrTmp[i]) {
 	//si no es el ultimo
	if (i!=arrTmp.length-1) {
		
		// si no es el penultimo
		if (i!=arrTmp.length-2) {
		
			tmp += arrTmp[i] + "@";
		}
		
			
		if (i==arrTmp.length-2 && arrTmp[i+1]!=dom) {
			tmp += arrTmp[i] + "@";
		}
	
		if (i==arrTmp.length-2 && arrTmp[i+1]==dom) {
			tmp += arrTmp[i];
			
}
	
	}
 	//si es el ultimo
	if (i==arrTmp.length-1) {
		
		tmp += arrTmp[i];
	}
 
 }
 }

}

setCookie("car", tmp);
window.location = "carrito.php";
}
function validation(fm){
var msg = '';

msg += '==>Seleccione un tipo de Pago\n';
error= true; 

for(var i=0;i<fm.length;i++){   
	if (fm.elements[i].type == "radio" && fm.elements[i].checked == true)
	{
	msg = '';
	error= false; 
	}

}
if (fm.tot.value == "") {
msg += '==>No ha seleccionado ningun Producto';	
error= true; 	
}
if (error){

alert(msg);
return false
}
else return true;

 
}

function enviar(formulario,idp){
var idp = idp;
var error = true;
for(var i=0;i<formulario.length;i++){           
if (formulario.elements[i].type == "radio" && formulario.elements[i].checked == true)
{
document.form3.cadena.value = formulario.elements[i].value;
enviar2(form2,idp); 
error= false;   
break;
}
}
if (error){

alert('Seleccione un COLOR de la Prenda \npara seguir con el registro de la Compra');
}  	

}
function enviar2(formulario,idp){
err = true;
for(var i=0;i<formulario.length;i++){           
if (formulario.elements[i].type == "radio" && formulario.elements[i].checked == true)
{
document.form3.cadena.value = document.form3.cadena.value +'$'+ formulario.elements[i].value;
carrito(idp);
err = false;       
break; 
}


}
if (err){

alert('Seleccione una TALLA de la Prenda \npara seguir con el registro de la Compra');
}  	

}
function carrito(id) {
var prod;
var det;
det = document.form3.cadena.value;
prod = id + '#' + det;
// este alert es para imprimir la cookie del producto en pantalla
//alert(prod);
car(prod);
}

function validar(formulario) // usado contactenos.php
{
var error = false;
var mensaje="We have found the following errors:\n";
if (formulario.email.value=='')
{
mensaje=mensaje + " ==> You must enter your email.\n";
error=true; 
}
else { 

var filter=/^(\w+\.)*\w+\@([-!"&,;\w]+\.)+\w{2,3}$/;
if (filter.test(formulario.email.value))
error=false;
else {
mensaje=mensaje + " ==> Enter a valid email address!!.\n";
error=true;
}

}

if (formulario.nombre.value=='')
{
mensaje=mensaje + " ==> You must enter your First and Last name.\n";
error=true; 
}

if (formulario.pais.value==0)
{
mensaje=mensaje + " ==> You must select a country.\n";
error=true; 
}

if (formulario.ciudad.value=='')
{
mensaje=mensaje + " ==> You must enter your City.\n";
error=true; 
}

if (formulario.comentarios.value=='')
{
mensaje=mensaje + " ==> You must enter your comment.\n";
error=true; 
}

if (formulario.txtRandImage.value!=formulario.oculto.value)
{
mensaje=mensaje + " ==> The code entered does not match with that of the Image.\n";
error=true; 
}
if (error)
{
mensaje=mensaje+" Please correct the errors....";
alert(mensaje);
return false;
}
}

function env(id){
alert('Debe seleccionar la Talla y Color de su prenda \nEn la siguiente Pagina de Ver Producto','Aviso');
window.location = "ver_producto.php?id="+id;
}
function ver(id){
window.location='pago_google.php?idenv='+id;
}
function ver2(id){
window.location='pago_transferencia.php?idenv='+id;
}

function registrar(idenv){

window.location='procesarpago.php?idenv='+idenv;
	
}

