var rootPath = "http://www.pulgarsitio.com/ajax/";
var enproceso=false;
var arrSelecionado1 = new Array();
var arrSelecionado2 = new Array();
var arrSelecionado3 = new Array();
var debug=false;
var popupStatus = 0;



var arrEncuesta = new Array();




function sortByNumericValue(A) {//using objects
	
	B=[];
        for (i in A) B.push({clave:i,valor:A[i]})
	B.sort(function(x,y){return y.valor-x.valor})
	return B;
}


function porcentaje(a1,b1)
{
   a =  parseFloat(clearComas(a1));
   b =  parseFloat(clearComas(b1));
    if(!b)
    {
      b=1;
    }

    result=Math.round((a*100/b)*10)/10 +" %";

  

    return result;
}

function mensaje(m)
{
 if(debug)
     {
      document.getElementById("mensaje").innerHTML+=m+"<br>";
     }
}

function format_number(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function clearComas(nStr)
{
    nStr=""+nStr;

    arr= nStr.split(",");
    nu="";
    for(i=0;i<arr.length;i++)
     {
       nu=nu+arr[i];
     }

   
    return nu;
}

//loading popup with jQuery magic!
function loadPopup(){
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow");
popupStatus = 1;
}
}


//disabling popup with jQuery magic!
function disablePopup(){
//disables popup only if it is enabled
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
}
}


function loadPopupSeguridad(){
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupSeguridad").fadeIn("slow");
popupStatus = 1;
}
}


//disabling popup with jQuery magic!
function disablePopupSeguridad(){
//disables popup only if it is enabled
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupSeguridad").fadeOut("slow");




popupStatus = 0;
}
}

function ubicarPopup()
{
    var windowHeight =document.documentElement.clientHeight;

$("#popupSeguridad").css({
"position": "absolute",
"top":60,
"left":450
});
//only need force for IE6

$("#backgroundPopup").css({
"height": windowHeight
});
}
//centering popup
function centerPopup(element){
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight =document.documentElement.clientHeight;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
$("#popupContact").css({
"position": "absolute",
"top": findPos(element)[1],
"left": windowWidth/2-popupWidth/2
});
//only need force for IE6

$("#backgroundPopup").css({
"height": windowHeight
});

}


function findPos(obj)
{
	var curleft = curtop = 0;


	if (obj.offsetParent) {


	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;


           } while(obj==obj.offsetParent);
        }

	return [curleft,curtop];
}
