// JavaScript Document
var id_user = "0";
var str_email = "";
var str_pais = "MEX";

function msg_salida(pais)
{	
	var txt_msg = "Detectamos que tiene productos marcados en su lista de favoritos.\n\n";	
	txt_msg += "Si desea guardar su lista de favoritos seleccione la opci\u00F3n Cancelar.\n\n";
	txt_msg += "El permanecer en la p\u00E1gina actual le permitir\u00E1 realizar su registro y conservar su historial."
	
	if(pais == "USA"){	
		txt_msg = "You have products selected in your favorites list.\n\n";	
		txt_msg += "To save your favorites list select the Cancel option.\n\n";
		txt_msg += "Staying in the current page allows you to preserve your history."
	}	
	
	return txt_msg;
}

function AddFavorito(pais, iduser, idproducto)
{
	id_user = iduser;
	var url  = pais + "/Favoritos.aspx?tipo_mov=add&id_user=" + iduser + "&id_producto=" + idproducto + "&hash=" + Math.random();
	xmlHttp=GetXmlHttpObject(SendPage_handler)	
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

function DeleteFavorito(pais, iduser, idproducto)
{
	var url  = pais + "/Favoritos.aspx?tipo_mov=delete&id_user=" + iduser + "&id_producto=" + idproducto + "&hash=" + Math.random();
	xmlHttp=GetXmlHttpObject(SendPage_handler)	
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)	
}

function SendPage_handler() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(id_user != "0")
		{						
			if(document.getElementById("txt_id_user") != null)
			{
			   document.getElementById("txt_id_user").value = id_user;			
			}			
		}		
	} 
}

//Unload Eventos
//Marco A. 07/abr/10

	var browser = navigator.userAgent.toLowerCase();
	var IEVersion;
	var brVerId = browser.indexOf('msie');	
	if (brVerId > 0) {
		IEVersion = browser.substr( brVerId + 5 ,1);
	}
	//var AlertBox = "Detectamos que tiene productos marcados en su lista de favoritos.\n\n";	
	
	window.onbeforeunload = function(){			
		var b = true;
		
		if(tb_detectMSIE()){			
			var n = window.event.screenX - window.screenLeft;   
      		b = n > document.documentElement.scrollWidth-20; 
		}		
		
		if(b == true){		 
			if(document.getElementById("txt_id_user") != null){			
				var user_id = document.getElementById("txt_id_user").value;
				if(user_id != "0"){					
					if(user_id.indexOf("tmp") != -1){
						document.getElementById("txt_id_user").value = "0";						
						if(ReadCookie(user_id).length > 0)
							return ExitPop(isExit, user_id);						
					}					
				}				
			}
		}	
	}
	
	function tb_detectMSIE() { 		 		
  		if (browser.indexOf('msie')!=-1) { return true;	}
		else { return false; }
	}
	
	function tb_detectFF() {  		
  		if (browser.indexOf('firefox')!=-1) { return true; }
		else { return false; }
	}
	
	function ReadCookie(cookiename) {
    	var numOfCookies = document.cookie.length;
    	var nameOfCookie = cookiename + "=";
    	var cookieLen = nameOfCookie.length;
    	var x = 0 ;
    	while (x <= numOfCookies) {
        	var y = (x + cookieLen);
        	if (document.cookie.substring(x, y) == nameOfCookie)
            	return (extractCookieValue(y));
        	x = document.cookie.indexOf(" ", x) + 1;
        	if (x == 0)
            	break;
    	}
    	return "";
	}
	
	function extractCookieValue(val)
	{
    	if ((endOfCookie = document.cookie.indexOf(";", val)) == -1)
        	endOfCookie = document.cookie.length;
    	return unescape(document.cookie.substring(val, endOfCookie));
	}
	
	function AbrirCentrado(Url,NombreVentana,width,height,extras)
	{
		var largo = width;
		var altura = height;
		var adicionales= extras;
		var top = (screen.height-altura)/2;
		var izquierda = (screen.width-largo)/2;
		nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + ''); 
		nuevaVentana.focus();
	}
	
	function cambiar_password(pais, id_user)
	{		
		var NombreVentana = 'user_edit';
		var Url = "0";
		var id_user = id_user;
		var largo = 500;
		var altura = 250;
		var adicionales= '';
		var top = (screen.height-altura)/2;
		var izquierda = (screen.width-largo)/2;
		
		if(pais.toLowerCase() == "mex" || pais.toLowerCase() == "usa")
		{
			if(pais.toLowerCase() == "mex")
			{
				Url = './Util/user_edit.asp?pais=MEX&id=' + id_user;						
			}
			else
			{
				Url = './Util/user_edit_ing.asp?pais=USA&id=' + id_user;
			}			
			nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + ''); 
			nuevaVentana.focus();
		}
		else
		{
			alert('Parametro erroneo, pais = MEX o USA');
		}
			
	}
	
	function reporte_pdf()
	{
		var pais = 'MEX';		
		var url_origen = document.location.href;
		var pruebas = 0;
		url_origen = url_origen.toLowerCase();
		
		if(url_origen.indexOf('/usa/') > 0)
			pais = 'USA';
			
		if(url_origen.indexOf('/exa3/') > 0)
			pruebas = 1;	
			
		var NombreVentana = 'informe';
		var Url = 'http://interceramicgreen.softbox.com.mx/MEX/green/genera_pdf.aspx?opc=usuarios&pais=' + pais;
		
		if(pruebas == 1)
			Url = 'http://exa3/interceramicgreen/MEX/green/genera_pdf.aspx?opc=usuarios&pais=' + pais;	
		
		var largo = 900;
		var altura = 500;
		var adicionales= '';
		var top = (screen.height-altura)/2;
		var izquierda = (screen.width-largo)/2;					
		nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + ''); 
		nuevaVentana.focus();		
		return false;
	}
