
var navegador = navigator.appName;


var iexplorer;
navigator.appName == "Microsoft Internet Explorer" ? iexplorer= true : iexplorer = false; 




//La variable url se usa como raiz del sistio en toda llamada donde se requiera
var url = "http://";
var urlCompleta = document.location.href.replace('http://',"");
var sitio = urlCompleta.split('/');
url+= sitio[0];

function getget(name) {  //Obtiene el parametro pasado por get con nombre name
  var q = document.location.search;
  var i = q.indexOf(name + '=');

  if (i == -1) {
	return false;
  }

  var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);

  i = r.indexOf('&');

  if (i != -1) {
	r = r.substr(0, i);
  }

  return r.replace(/\+/g, ' ');
}

function loadXMLDoc(fname) {  //Prepara el XML a transformar
    var xmlDoc;
    
    // code for IE
    if (window.ActiveXObject) {
        ver = navigator.appVersion;
				ver.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
				ver = RegExp.$3;

				if (ver == "6.0")
				  xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");  
				else
					xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");             
				xmlDoc.async = false;
        xmlDoc.validateOnParse = false;
        xmlDoc.loadXML(fname);
        return xmlDoc;
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        //xmlDoc = document.implementation.createDocument("", "", null);
        
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(fname, "text/xml");
        xmlDoc.async = false;
        xmlDoc.validateOnParse = false;
        //alert(xmlDoc.responseText);    
        
        return xmlDoc;
    }
    else {
        alert('Your browser cannot handle this script');
    }
    
    return (xmlDoc);
}



function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}


function loadXSLTDoc(fname) {
    var xmlDoc;
    // code for IE
    if (window.ActiveXObject) {
    		ver = navigator.appVersion;
			 	ver.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
				ver = RegExp.$3;

				if (ver == "6.0")
        	xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");  
				else
					xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");         }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        xmlDoc = document.implementation.createDocument("", "", null);
    }
    else {
        alert('Your browser cannot handle this script');
    }
    xmlDoc.async = false;
    xmlDoc.load(fname);
    return (xmlDoc);
}

function displayResult(xmlDoc, xsltPath, capa) {
    xml = loadXMLDoc(xmlDoc);
    xsl = loadXSLTDoc(xsltPath);
    // code for IE
    if (window.ActiveXObject) {
        if (xml.parseError.errorCode != 0)
            alert("XML Parse Error : " + xml.parseError.reason);

        if (xsl.parseError.errorCode != 0)
            alert("XSL Parse Error : " + xsl.parseError.reason);

        try {
            ex = xml.transformNode(xsl);
            $jq('#'+capa).html(ex.replace( /&lt;(([^&]|\&[^g]|&g[^t]|&gt[^;])+)&gt;/g, "<$1>" ));
        }
        catch (err) {
            alert("Transformation Error : " + err.number + "*" + err.description);
        }

    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl);
        resultDocument = xsltProcessor.transformToFragment(xml, document);
        document.getElementById(capa).appendChild(resultDocument);
        document.getElementById(capa).innerHTML = document.getElementById(capa).innerHTML.replace(/&lt;(([^&]|\&[^g]|&g[^t]|&gt[^;])+)&gt;/g, "<$1>");
    }
}

function getWSSxmlData(funcOk,funcFail,listName,viewName,query,viewFields,rowLimit,queryOptions) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=utf-8",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/getXmlData",
    data:"{'listName':'"+listName+"','viewName':'"+viewName+"','query':'"+query+"','viewFields':'"+viewFields+"','rowLimit':'"+rowLimit+"','queryOptions':'"+queryOptions+"'}",
    //data:"{'listName':'{AF5A69A9-9F56-46C8-AC1C-D4D6A0E5B283}','viewName':'{3E3F0F54-937E-4BFD-BE8E-6F544B0569F9}','query':'','viewFields':'','rowLimit':'0','queryOptions':''}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}


function getXSLTfromXML(funcOk,funcFail,xml,xsl) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/transform",
    data:"{'xmlstr':'"+escape(xml)+"','xslt':'" +xsl+ "'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}

function insertInList(funcOk,funcFail,xml,list) 
{
//alert(list);
//alert(xml);
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/AddXmlData",
    data:"{'xmlstr':'"+escape(xml)+"','list':'" +list+ "'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)" ); 	
		}
  });
}

function exec_updateAlto(){
return true;
	if ($jq("#altoBase").length == 1)
	{
		alto = $jq("#altoBase").height();
		if((alto+268)>860)
			$jq("#fondoPagina").height(alto+500);
		else{
			$jq("#fondoPagina").height(860);
			$jq("#altoBase").height(500);
		}
	}
}



function getDataFromBD(funcOk,funcFail,xml,procedure) 
{


  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/getXmlDataFromDB",
    data:"{'xml':'"+escape(xml)+"','procedure':'"+procedure+"'}",
    dataType:"json",
	timeout: 50000,
    success: function(msg) {
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}



function addDataToBD(funcOk,funcFail,xml,procedure) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/addXmlDataFromDB",
    data:"{'xml':'"+escape(xml)+"','procedure':'"+procedure+"'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}



function normalizar(funcOk,funcFail,xml,procedure,txOrigen) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/getDataNorm",
    data:"{'xml':'"+escape(xml)+"','procedure':'"+procedure+"','txOrigen':'"+escape(txOrigen)+"'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}



function SendMail(funcOk,funcFail,email,subject,body,adjunto,modelo) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/SendMail",
    data:"{'email':'"+escape(email)+"','subject':'"+escape(subject)+"','body':'"+escape(body)+"','adjunto':'"+escape(adjunto)+"','modelo':'"+escape(modelo)+"'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}

function convertToPdf(funcOk,funcFail,xml,xsl) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/convertToPdf",
    data:"{'xmlstr':'"+escape(xml)+"','xslt':'" +xsl+ "'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}

function SendSMS(funcOk,funcFail,num,Nombre,IdOferta) 
{
  $jq.ajax({ //async:true, 
    type: "POST",
    contentType: "application/json; charset=charset=iso-8859-1",  
    url:url+"/sharepointAnonimousWS/sharepointAnonimousWS.asmx/SendSMS",
    data:"{'num':'"+num+"','Nombre':'" +escape(Nombre)+ "','IdOferta':'" +escape(IdOferta)+ "'}",
    dataType:"json",
    success: function(msg) { 
		    eval(funcOk+"(msg)"); 
                    //AjaxSucceededXML(msg);  
               },  
             error: function(msg){
			eval(funcFail+"(msg)"); 	
		}
  });
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	document.cookie = name+"="+value+expires+"; path=/";

}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
