﻿// Archivo JScript
var xmlHttp;
var MSGSelect = 1;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function CreateXmlHttp()
{
    try
    {
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {   
            xmlHttp = null;
        }
    }

    if(!xmlHttp && typeof XMLHttpRequest != "undefined")
    {
        xmlHttp = new XMLHttpRequest();
        if (xmlHttp.overrideMimeType) 
        {
            xmlHttp.overrideMimeType('text/xml; charset=iso-8859-1');
        }

    }

    return xmlHttp;
}
var Elemento = null;

function envioInfo(pagina)
{	alert(pagina);
    CreateXmlHttp();
    var ajaxRequest = pagina;
    //Elemento = elemento;
    xmlHttp.onreadystatechange = recogeInfo;
    xmlHttp.open("GET", ajaxRequest, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.setRequestHeader('Content-Length', '0');
    xmlHttp.send(null);
}

function changePage(url)
{ 
if (totalmarks>0)
{
	for (i=1;i<=totalmarks;i++)
	{
	markers[i].setVisible(false);
	infowindow.close(map,markers[i]);		
	}
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=jumptopage;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function jumptopage() 
{ 
if (xmlHttp.readyState==4)
{ 
var valores = xmlHttp.responseText.split('*_*');	
document.getElementById("resultados").innerHTML=valores[0];
var myLatlng1 = new google.maps.LatLng(posx,posy);
map.setCenter(myLatlng1);
map.setZoom(parseInt(czoom));	
eval(valores[1]);
}
}


function changePageMob(url)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=jumptopageMob;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function jumptopageMob() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("resultados").innerHTML=xmlHttp.responseText;
}
}


function filterPage(url)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp.onreadystatechange=jumptofilterpage;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function jumptofilterpage() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("advcontent").innerHTML=xmlHttp.responseText;
}
}

function loadSectores(url)
{ 
xmlHttp2=GetXmlHttpObject();
if (xmlHttp2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
xmlHttp2.onreadystatechange=stateChanged;
xmlHttp2.open("GET",url,true);
xmlHttp2.send(null);
}



function stateChanged() 
{ 
if (xmlHttp2.readyState==4)
{ 
document.getElementById("sectores").innerHTML=xmlHttp2.responseText;
}
}

function recogeInfo()
{
    if(!(Elemento == null))
    {
        switch(MSGSelect)
        {
            case 1:
                document.getElementById(Elemento).innerHTML = MensajeLoading();
            break;
            case 2:
                document.getElementById(Elemento).innerHTML = MensajeLoadingAddToCart();
            break;
            case 3:
                document.getElementById(Elemento).innerHTML = MensajeUpdateCart();
            break;
            case 4:
                document.getElementById(Elemento).innerHTML = MensajeRemoveCart(); 
            break;
            default:
                document.getElementById(Elemento).innerHTML = MensajeLoading();                   
        }
    }
    if (xmlHttp.readyState == 4) {
    	if (xmlHttp.status == 200) {
    		if (xmlHttp.responseText.indexOf('invalid') == -1) {
    		results = xmlHttp.responseText;
    		setTimeout("document.getElementById('" + Elemento + "').innerHTML = results", 1000);
			}
		}
		else if(xmlHttp.status == 500)
		{
		    $(Elemento).innerHTML = "Internal Server Error ";
		}
		else
		{
		    $(Elemento).innerHTML = "Site optimized for Internet Explorer 6.0+ " + xmlHttp.status;
		} 
	}
}
function envioInfoPOST(pagina, elemento, valores)
{
    CreateXmlHttp();
    var ajaxRequest = pagina;
    Elemento = elemento;
    xmlHttp.onreadystatechange = recogeInfo;
    xmlHttp.open("POST", ajaxRequest, true);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp.send(valores);
}
function MensajeLoading(cuerpo)
{
    var msg = "<div><table align='center'><tr><td align='center'><img vspace=50 src='images/loading.gif'></td></tr></b>";
    msg = msg + "<tr><td align='center' class='txtLoader'><b>Loading...</b></td></tr></div>";
    return msg;
}
function MensajeLoadingAddToCart()
{
    var msg = "<div><table align='center'>";
    msg = msg + "<tr><td align='center' class='HMFText'><b>Adding...</b></td></tr></div>";
    return msg;
}
function MensajeUpdateCart()
{
    var msg = "<div><table align='center'>";
    msg = msg + "<tr><td align='center' class='HMFText'><b>Updating...</b></td></tr></div>";
    return msg;
}
function MensajeRemoveCart()
{
    var msg = "<div><table align='center'>";
    msg = msg + "<tr><td align='center' class='HMFText'><b>Removing...</b></td></tr></div>";
    return msg;
}



function showCustomer(str)
{
	//alert(str);
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  
  return;
  }  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  //alert();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	 }
  }
xmlhttp.open("GET","SANMFotos.asp?q="+str,true);
xmlhttp.send();
}

function showGallery(str)
{
	//alert(str);
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  
  return;
  }  
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  //alert();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	 }
  }
xmlhttp.open("GET","SANMFotos1.asp?q="+str,true);
xmlhttp.send();
}

function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}


function ValidateCaptcha(url,formname,responsediv)
{
		
		// we can use other domain to perform this task, 
		// for example, this page (index.asp) sit in domain www.encelabs.com
		// and captcha.asp sit in www.smartplanetcms.com
		// we can use url as below, this is because we are using cross domain ajax
		// $.getJSON("www.smartplanetcms.com/captcha.asp?validateCaptchaCode=" +  $("#captchacode").val() + "&format=json&jsoncallback=?", function(data){
		
		$.getJSON("captcha.asp?validateCaptchaCode=" +  $("#captchacode").val() + "&format=json&jsoncallback=?", function(data){
		if (data.status == "1")
			{
				//alert("verified and submit.");
				//if (formValidation() == true)
				//{
					xmlhttpPost(url, formname, responsediv, 'Procesando...', 'captchacode', '', 0);
					//$("#form").submit();
				//}
				
				
				result = true;
				
			}
		
			else
			{
				if (data.session == "0")
					RefreshImage("imgCaptcha");
				
				alert("El código de seguridad no es válido");
				$("#captchacode").focus();
				document.getElementById(responsediv).innerHTML = '';
		
				result = false;
				
			}
			
		});
																																					}
																																					
																																					function cuenta(yo, texto,mostrarboton) {
 x = yo.form[yo.name];
 t = "";
 nt= "";
 var leng=x.length;
 if (leng>=2)
 {
 //leng=1;
 }
 else
 {
 leng=1;
 }
 if (leng==1)
 {
	   if (x.checked==true)
	   {
	   t += "," + x.value;
	   }
	   yo.form[texto].value = (t == "") ? t : t.substring(1);
	   if (yo.form[texto].value=='')
	   {
			document.getElementById(mostrarboton).style.display='none';
	   }	
	   else
	   {	
			document.getElementById(mostrarboton).style.display='';
		}
 }
 else
 {
	 for (i = 0; i < leng; i ++)
	   if (x[i].checked==true)
	   {
	   t += "," + x[i].value;
	   }
	   yo.form[texto].value = (t == "") ? t : t.substring(1);
	   if (yo.form[texto].value=='')
	   {
			document.getElementById(mostrarboton).style.display='none';
	   }	
	   else
	   {	
			document.getElementById(mostrarboton).style.display='';
		}
 }
}

