

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	curleft = curleft - 100;
	curtop = curtop - 100;
	return [curleft,curtop];
}


function putInCentre(lyr, h, w) { 

var d = document; 
var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 


var top = (d.body.scrollTop > rootElm.scrollTop) ? d.body.scrollTop : rootElm.scrollTop;

var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width 
var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height 

var dleft = (vpw - w) / 2;
dleft = dleft - 60;
dleft = (dleft > 10) ? dleft : 10;

lyr.style.left = dleft + 'px';  

var dtop = top + (vph - h)/2;
dtop = (dtop > 50) ? dtop : 50;
lyr.style.top = dtop +'px'; 


lyr.style.visibility = "visible";
} 

function setLyr(obj,lyr)
{
	var coors = findPos(obj);
	
	lyr.style.top = coors[1] + 'px';
	lyr.style.left = coors[0] + 'px';
	lyr.style.visibility = "visible";
}

function newsContent(htmltext, target){

	var x = htmltext.indexOf("<!-- NEWSSTART");
	x = htmltext.indexOf(">", x);    
	var y = htmltext.lastIndexOf("<!-- NEWSSEND"); 
	var response = htmltext.slice(x + 1, y);

	if (typeof target == "string") target = document.getElementById(target);
	target.innerHTML =  response;
}


function newsPop(link){
	lyr = document.getElementById('NewsPop');
	var dh = Math.floor(500) + 80;
	var dw = Math.floor(600);
//	lyr.style.height = dh + 'px';
	lyr.style.width = dw + 'px';		

	putInCentre(lyr, dh, dw - 300);
	target = document.getElementById('NewsContent');
	target.innerHTML = "<div class=\"Loading\"><img src=\"Images/loading.gif\">Loading</div>";

	url =  link.href;
	var request = HTTP.newRequest();
	request.onreadystatechange = function() {
		if (request.readyState==4) { 
			if (request.status == 200){
				newsContent(request.responseText, target);
			}
		}
	}
	request.open("GET", url, true);
	request.setRequestHeader("User-Agent", "XMLHttpRequest");
	request.send(null);



return(false);


}
function hidePop(){

	document.getElementById('NewsPop').style.visibility = "hidden";

return(false);


}

function hideNews(){
	document.getElementById('NewsPanelClose').style.color = "#ff0000";

	document.getElementById('NewsPanelContent').style.visibility = "hidden";
	document.getElementById('NewsPanelContent').style.position = "absolute";
	document.getElementById('NewsPanelOpen').style.position = "relative";
	document.getElementById('NewsPanelOpen').style.visibility = "visible";

	document.getElementById('NewsPanelClose').style.visibility = "hidden";
	document.getElementById('NewsPanelClose').style.position = "absolute";
	document.getElementById('NewsPanelClose').style.color = "#ffffff";
return(false);


}

function openNews(){


	document.getElementById('NewsPanelContent').style.visibility = "visible";
	document.getElementById('NewsPanelContent').style.position = "relative";
	
	document.getElementById('NewsPanelOpen').style.visibility = "hidden";
	document.getElementById('NewsPanelOpen').style.position = "absolute";
	
	document.getElementById('NewsPanelClose').style.visibility = "visible";
	document.getElementById('NewsPanelClose').style.position = "relative";


return(false);

}
function ChangeMsgPop(htmltext){
	var x = htmltext.indexOf("<body");
	x = htmltext.indexOf(">", x);    
	var y = htmltext.lastIndexOf("body>"); 
	var response = htmltext.slice(x + 1, y);

	var target = 'MsgContent';
	if (typeof target == "string") target = document.getElementById(target);
	target.innerHTML =  response;

}

function processForm(f){
	var msg = "Form Values\n";
	var values = [];
	var regexp = /%20/g;
	for (var j=0; j < f.elements.length; j++){
		var e = f.elements[j];
		if (e.value && e.type == "radio" && !e.checked) continue;
		msg = msg + e.name + ": " + e.value;
		msg = msg + "\n";
		values[e.name] = e.value;
	}
	HTTP.post("xcontact_form.php", values, ChangeMsgPop, alert);
	
	return(false);
}



function OpenMsgPop(id){

	lyr = document.getElementById(id);
	var dh = Math.floor(800);
	var dw = Math.floor(400);
//	lyr.style.height = dh + 'px';
	lyr.style.width = dw + 'px';		

	putInCentre(lyr, dh, dw);
	document.getElementById(id).style.visibility = "visible";

var d = document; 
var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 


var top = (d.body.scrollTop > rootElm.scrollTop) ? d.body.scrollTop : rootElm.scrollTop;

var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width 
var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height 
lyr.style.visibility = "visible";

	document.getElementById('iShim').style.width = "1" + vpw + "px";
	document.getElementById('iShim').style.height = "1" + vph + "px";
	document.getElementById('iShim').style.display = "block";

	rootElm.style.overflowX = 'hidden';

return(false);


}
function HideMsgPop(id){
	var d = document;
	d.getElementById(id).style.visibility = "hidden";
	d.getElementById('iShim').style.display = "none";
 
	var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 
	rootElm.style.overflowX = 'auto';

return(false);


}

function OpenVidPop(id){

	lyr = document.getElementById(id);
	var dh = Math.floor(800);
	var dw = Math.floor(720);
//	lyr.style.height = dh + 'px';
	lyr.style.width = dw + 'px';		

	putInCentre(lyr, dh, dw);
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(id).style.width = "722px";
	document.getElementById(id).style.height = "460px";
	document.getElementById(id).style.padding = "0";

var d = document; 
var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 


var top = (d.body.scrollTop > rootElm.scrollTop) ? d.body.scrollTop : rootElm.scrollTop;

var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width 
var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height 
lyr.style.visibility = "visible";

	document.getElementById('iShim').style.width = "1" + vpw + "px";
	document.getElementById('iShim').style.height = "1" + vph + "px";
	document.getElementById('iShim').style.display = "block";

	rootElm.style.overflowX = 'hidden';
	d.getElementById('VidContent').innerHTML = '<embed SRC="PHC_2011_30sec_tvc.mp4" AUTOPLAY="true" WIDTH="720" HEIGHT="420" style="margin: 0"></embed>';
return(false);


}

function HideVidPop(id){
	var d = document;
	d.getElementById('VidContent').innerHTML = '';

	d.getElementById(id).style.visibility = "hidden";
	d.getElementById('iShim').style.display = "none";
 
	var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 
	rootElm.style.overflowX = 'auto';

return(false);


}

function SwapMsgPop(id, id2){
	var d = document;
	d.getElementById('MsgContent').innerHTML = d.getElementById(id2).innerHTML;
	OpenMsgPop(id);
	return(false);
}


function afclearfield (field){
if (field.value == 'username' || field.value == 'password'){
	field.value = '';
	field.style.color = '#333333';
}
return(false);

}

function toggleNews(nid){
var st = "NS" + nid;
var ft = "NF" + nid;
	sel = document.getElementById(st);
	fel = document.getElementById(ft);
	if (sel.style.display == 'none'){
		fel.style.display = 'none';		
		sel.style.display = 'block';	
	} else {
		sel.style.display = 'none';
		fel.style.display = 'block';		
	}
	return(false);
}


