/*xmlhttp functions*/
function loadXMLdoc(url,func, type){
    if(url){
	if (!type)
	    type = "GET";

	if(!func)
	    func = xmlhttp_default;
    
	if (window.XMLHttpRequest) {
	    xmlhttp = new XMLHttpRequest();
	    // branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = func;
	xmlhttp.open(type, url ,true);
	xmlhttp.send(null);
    }
}

//xmlhttp.onreadystatechange function
function xmlhttp_default(){
    if (xmlhttp.readyState==4) {
	//alert(xmlhttp.responseText);
    }
}

function xmlhttp_alert(){
    if (xmlhttp.readyState==4) {
	alert(xmlhttp.responseText);
    }
}

/*xmlhttp functions end*/

function browserTest(){
    var agt=navigator.userAgent.toLowerCase();

    is_DOM = (document.getElementById) ? true : false;
    var is_opera = (agt.indexOf("opera") != -1) ? true:false;
    var is_konq = agt.indexOf('konqueror') != -1 ? true:false;
    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);
    var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));

    //alert("Opera: " + is_opera + "\nKonqueror: " + is_konq + "\nSafari: " + is_safari + "\nKhtml: " + is_khtml + "\nMozilla: " + is_moz);
    if ( is_DOM && (is_konq || is_opera) ){
	if ( document.getElementById('theBanner') && document.getElementById('theBanner').getElementsByTagName("div")[0]){
	    document.getElementById('theBanner').getElementsByTagName("div")[0].style.backgroundColor = "transparent";
	}
    }
}

/* get mouse position */
var Mouse = {x:0, y:0};

document.onmousemove = function (evt) {
    var e = window.event || evt;
    //    Mouse.x = e.x || e.pageX || 0;
    //Mouse.y = e.y || e.pageY || 0;
    Mouse.x = e.pageX | e.clientX  || 0;
    Mouse.y = e.pageY || e.clientY + document.body.scrollTop || 0;
}
/* get mouse position end */


/*Hover Effect on Popup images */
function popupTitle(image, txt){
    var newDiv = document.createElement("div");
    newDiv.className = "mouseOverText";
    newDiv.innerHTML = txt;

    var newDivShadow = document.createElement("div");
    newDivShadow.className = "mouseOverTextShadow";
    
    document.body.appendChild(newDivShadow);
    document.body.appendChild(newDiv);

    image.mot = newDiv;
    image.motS = newDivShadow;

    
    image.onmouseover = function(){
	image.mot.style.visibility = "visible";
	image.motS.style.visibility = "visible";
    };

    image.onmousemove = function(){

	var left  = Mouse.x - 20;
	if ( (left + this.mot.offsetWidth) > (document.body.offsetWidth - 40 )){
	    left = document.body.offsetWidth - this.mot.offsetWidth - 40;
	}

	var top = Mouse.y + 20;
	if (( top + this.mot.offsetHeight) > (document.body.offsetHeight - 20 )){
	    top = Mouse.y - this.mot.offsetHeight - 20;
	}
	//this.mot.innerHTML =  (left + this.mot.offsetWidth) + " > " + (document.body.offsetWidth-50) + " = " + left;
	
	this.mot.style.left = left + "px";
	this.mot.style.top = top + "px";
	
	this.motS.style.left = this.mot.offsetLeft + 5 + "px";
	this.motS.style.top = this.mot.offsetTop + 5 + "px";
	
	this.motS.style.width = this.mot.offsetWidth + "px";
	this.motS.style.height = this.mot.offsetHeight + "px";
	
    }
    image.onmouseout = function(){
	image.mot.style.visibility = "hidden";
	image.motS.style.visibility = "hidden";
    };

    //to make it work the first time we hover the image
    image.mot.style.visibility = "visible";
    image.motS.style.visibility = "visible";
    if ( image.style.cursor ){
	image.style.cursor = "pointer";
    }
}



/*Hover Effect on Popup images */


function popUpImage(id, width, height, title){
    var content = "<html><head><title>" + title + "</title><style type=\"text/css\">body{margin: 0; padding: 0;}</style></head><body><img style=\"cursor: pointer\" onclick=\"window.close()\" src=\"/www/image.do?id=" + id + "\" width=\"" + width + "\" height=\"" + height + "\" border=\"0\"></body></html>";
    var popupimage = window.open("", "popupimage", "width=" + width + ",height=" + height + ",status=no,resizable=yes,scrollbars=0,top=200,left=400");
    popupimage.focus();
    popupimage.opener = self;
    var popupDoc = popupimage.document;
    popupDoc.innerHTML = "";
    popupDoc.write (content);
    popupimage.resizeTo(width,height+2);
    var pWidth = popupDoc.documentElement.offsetWidth;
    var pHeight = popupDoc.documentElement.offsetHeight;
    popupDoc.close();
    if ( width > pWidth || height > pHeight ){
	popupimage.resizeTo(2*width-pWidth+4,2*height-pHeight+5);
    }
}
   	
function showPrintPage(printPage,id){
    printPage = printPage ? printPage:41;
    var width = 800;
    var height = 600;
    var popupimage = window.open("/www/show.do?page=" + printPage + "&articleid=" + id, "printpage", "width=" + width + ",height=" + height + ",toolbar=1,menubar=1,status=no,resizable=yes,scrollbars=1,top=100,left=100");
    popupimage.focus();
}


function scramble(key, text, link) {
    var fromstring=text;
    var tostring="";
    var passwordstring=key;
    var alphabet="abcdefghijklmnopqrstuvwxyz!?@,.;:-+=£$%^&*() 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    var counter=0
	var pcounter=0

	while (counter<fromstring.length) {
	    fromchar=fromstring.charAt(counter);
	    pwchar=passwordstring.charAt(pcounter);
	    ascfrom=alphabet.indexOf(fromchar);
	    ascto=alphabet.indexOf(pwchar);
	    scrambled=ascfrom^ascto;
	    
	    if (ascfrom!=-1) {
		tostring=tostring+(alphabet.charAt(scrambled)); 
		pcounter++;
		if (pcounter==passwordstring.length) {pcounter=0}
	    }
	    counter++;
	}
    if (link){
	document.write("<" + "a hr" + "ef='mai" + "lto:" + tostring + "'>" + tostring + "</" + "a" + ">");
    }else{
	document.write(tostring);
    }
}
