 
function encode64(input) {
        var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
 
	while (i < input.length) {
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);
 
		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;
 
		if (isNaN(chr2)) {
			enc3 = enc4 = 64;
		} else if (isNaN(chr3)) {
			enc4 = 64;
		}
 
		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
   }
   
   return output;
}

function decode64(input) {
        var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
 
	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
	while (i < input.length) {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));
 
		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;
 
		output = output + String.fromCharCode(chr1);
 
		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}
	}
 
	return output;
}

function UpdateCart(Action, StoreUID, ProductID, BaseElement, Options) {
    if(typeof document.getElementById("CartCount") == "object") {
            var req = new XMLHttpRequest;
            if(!req)
                return null;
            
            if(typeof BaseElement == "object") {
                var confLoc=findPos(BaseElement);
                var theQty = BaseElement.value;
            }
            
            if(Action == "R") {
                req.open('GET', '/publications/?A=CRT&SA='+Action+'&SID='+StoreUID, false); // get page synchronously
            } else {
                //alert('/publications/?A=CRT&SA='+Action+'&SID='+StoreUID+'&PID='+ProductID+'&QTY='+theQty+'&OPT='+Options);
                req.open('GET', '/publications/?A=CRT&SA='+Action+'&SID='+StoreUID+'&PID='+ProductID+'&QTY='+theQty+'&OPT='+Options, false); // get page synchronously
            }
            req.send(null);
            //alert(req.responseText);
            if(parseInt(req.responseText) > 0) {
                document.getElementById("CartCount").firstChild.nodeValue = req.responseText;
                document.getElementById("Checkout").style.display="inline";
            }
            if(Action != "R") {
                document.getElementById("confirmation").style.display="inline";
                document.getElementById("confirmation").style.top=confLoc[1]-(parseInt(document.getElementById("confirmation").style.height)*2)+(parseInt(document.getElementById("confirmation").style.padding)*2);
                document.getElementById("confirmation").style.left=confLoc[0];            
                setTimeout("document.getElementById(\"confirmation\").style.display=\"none\";",2000);
            }
    }         
}

function ClassChange(theClass,element,value) {
    var theRules;
    if (document.all) {
        theRules = 'rules';
    }
    else if (document.getElementById) {
        theRules = 'cssRules';
    }
    for (var theStyle = 0; theStyle < document.styleSheets.length; theStyle++){
        for (var theRule = 0; theRule < document.styleSheets[theStyle][theRules].length; theRule++) {
            if (document.styleSheets[theStyle][theRules][theRule].selectorText.toUpperCase() == theClass.toUpperCase()) {
                document.styleSheets[theStyle][theRules][theRule].style[element] = value;
                //alert("Changing Value");
            }
        }
    }	
}

function IsNumeric(input){
  return /^-?(0|[1-9]\d*|(?=\.))(\.\d+)?$/.test(input);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      if (oldonload) { 
        oldonload(); 
      } 
      func(); 
    } 
  } 
} 



var posLatitude="";
var posLongitude="";

var googleAPI="ABQIAAAAQJXgN2yJozo7WMjXFtv7qxTu4bQZ0NR5_f8z7xhRpKfjbD6fLRRvn3C5XB_csk1RjeCpRwQmnjltIg";

var gl;


try {
  if(typeof(navigator.geolocation) == 'undefined'){
    gl = google.gears.factory.create('beta.geolocation');
  } else {
    gl = navigator.geolocation;
  }
}catch(e){}

/*
try {
    if(geo_position_js.init()){
       gl = geo_position_js;
    }
}catch(e){}
*/


function getPosition() {
    gl.getCurrentPosition(function(position) { 
                                                                    posLatitude = position.coords.latitude;
                                                                    posLongitude = position.coords.longitude;
                                                               },
                                             function(error) { 
                                                                    posLatitude = 0;
                                                                    posLongitude = 0;
                                                               },
                                             {maximumAge:600000});

}

// Cross Browser Ajax Implementation
if(typeof window.XMLHttpRequest !== 'function' &&
    typeof window.ActiveXObject === 'function') {
    window.XMLHttpRequest = function() {
        try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
        try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
        try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
        try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
        throw new Error('failed to create an ActiveX XMLHTTP object');
    };
}

function secureXMLHttpRequest(userID, password, url) {
            var req = new XMLHttpRequest;
            if(!req)
                return null;
            
            var tok = userID + ':' + password;
            var hash = encode64(tok);

            req.open('GET',url)
            req.setRequestHeader('Authorization', "Basic " + hash);
            req.send(null);

            return req.responseText;

} 


try {
    addLoadEvent(function(){ setTimeout(function(){window.scrollTo(0,1)},100); });
}catch(e){}	
