function include( filename ) {  // The include() statement includes and evaluates the specified file.
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', filename);
    js.setAttribute('defer', 'defer');
    document.getElementsByTagName('HEAD')[0].appendChild(js);
}

function ping(){
	include('/js/ping.php');
	setTimeout(ping,600000);
}

setTimeout(ping,600000);

var divalert, divmodal, divalertback, divclosemodal;

function closealert(){
	divalertback.style.display='none';
	divclosemodal.style.display='none';
	divmodal.style.display='none';
}

function shadowback(){
	if(!divclosemodal){
		divclosemodal = document.createElement("div");
		divclosemodal.className='divclosemodal';
		divclosemodal.onclick=closealert;
		divclosemodal.innerHTML = '<img src=/images/close.png border=0>';
		divclosemodal.onclick=closealert;
       	document.body.appendChild(divclosemodal);
	}
	if(!divalertback){
		divalertback = document.createElement("div");
		divalertback.className='divalertback';
//		divalertback.onclick=closealert;
       	document.body.appendChild(divalertback);
	}
	divalertback.style.width = '100%';// Math.max(document.body.scrollWidth, document.body.clientWidth);
	divalertback.style.height = document.body.scrollHeight+'px';//Math.max(document.body.scrollHeight, document.body.clientHeight);
	divclosemodal.style.display='';
	divclosemodal.style.left = divmodal.offsetWidth + divmodal.offsetLeft - divclosemodal.offsetWidth;
	divclosemodal.style.top = divmodal.offsetTop-divclosemodal.offsetHeight;
	divalertback.style.display='';
}

function alertmessage(message){
	if(!divalert){
		divalert = document.createElement("div");
		divalert.className='divalert';
		divalert.onclick=closealert;
		divalert.style.width = Math.min(400, document.body.clientWidth-60);
       	document.body.appendChild(divalert);
	}
	if(divmodal) divmodal.style.display='none';
	divalert.style.display='';
	divalert.innerHTML = message;//+' '+document.body.clientHeight+' '+divalert.offsetHeight;
	divalert.style.left = Math.max(0, Math.floor((document.body.clientWidth-divalert.offsetWidth)/2));
	divalert.style.top = Math.max(30, Math.floor((document.body.clientHeight-divalert.offsetHeight)/2));
	divmodal = divalert;	
	shadowback();
}
 
function hidedivwshadow(){
	divalertback.style.display='none';
	divmodal.style.display='none';
}

function showelementwshadow(thediv){
	if(divmodal) divmodal.style.display='none';
	divmodal = thediv;
	divmodal.style.display = '';
	divmodal.style.left = Math.max(0, Math.floor((document.body.clientWidth-divmodal.offsetWidth)/2) + document.body.scrollLeft);
	divmodal.style.top = Math.max(30, Math.floor((document.body.clientHeight-divmodal.offsetHeight)/2)+20 + document.body.scrollTop);
	shadowback();
}

function showdivwshadow(divid){
	thediv = document.getElementById(divid);
	showelementwshadow(thediv);
} 

var SelectedRow='';
var SelectedTR='';

function setselectedrow(row,id,cl){
	SelectedRow = id;
	if(!SelectedTR) SelectedTR=document.getElementById('deftr');
	if(SelectedTR) SelectedTR.className = cl;
	SelectedTR = row;
	row.className=cl+'_selected';
}

function xContains (container, containee){
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    if(containee)
	    containee = containee.parentNode;

  }
  while (containee != null);
  return isParent;
}

function triggerMouseArea(e,el)
{
	var rel = (window.event) ? e.toElement : e.relatedTarget;
	return !(xContains(el,rel));
}

var OpenDiv='';
var DoClose=true;

function smartshow(a){
	if(OpenDiv)OpenDiv.style.display='none';
	var d=document.getElementById(a);
	d.style.display='';
	OpenDiv=d;
	DoClose=true;
}

function smarthide(a){
	if(!DoClose){
		DoClose=true;
	}else
	if(OpenDiv){
		OpenDiv.style.display='none';
		OpenDiv='';
	}
}

var divframe=false;
function autosizeframe(vframe){
	divframe.style.display='';
	for(var i=0; i<=1; i++){
		vframe.width = Math.min(vframe.contentWindow.document.body.scrollWidth,Math.max(800,document.body.clientWidth-20));
		vframe.height = Math.min(vframe.contentWindow.document.body.scrollHeight+10,Math.max(600,document.body.clientHeight-50));
	}
	showelementwshadow(divframe);
}

function loadinframe(URL,W,H){
	if(!divframe){
		divframe = document.createElement("div");
		divframe.className='blinkwindow';
		divframe.onclick=closealert;
       	document.body.appendChild(divframe);
	}
	if(URL[0]=='/'){
		var lang=document.location.pathname.substr(0,4);
		if(lang[3]!='/')lang=''; else lang=lang.substr(0,3);
		URL=lang+URL;
	}
	if(W!=0 && H!=0){
		divframe.innerHTML = '<iframe id=alertframe src="'+
			URL+'" width='+W+' height='+H+' frameborder="0" ALLOWTRANSPARENCY="true"></iframe>';
		showelementwshadow(divframe);
	}else{
		divframe.style.left = 0;
		divframe.style.top = 0;
		divframe.style.display = 'none';
		divframe.innerHTML = '<iframe id=alertframe onload="autosizeframe(this); " src="'+
			URL+'" width=400 height=10 frameborder="0" ALLOWTRANSPARENCY="true"></iframe>';
	}	
}

function loadinframehref(href,W,H){
	if(!W)W=0;
	if(!H)H=0;
	loadinframe(href.href,W,H);
}

function loadcontacts(){
	loadinframe('/Articles/contact-us.php',500,540);
}

function deactivateframe(){
	top.closealert();
//	alert('deactivate');
}

function refreshtop(URL){
	if(!URL) URL=window.parent.document.location.href; else
	if(URL[0]=='?'){
		if(window.parent.document.location.href.indexOf('?')>=0)URL='&'+URL.substr(1);
		URL=window.parent.document.location.href + URL;
	}
	window.parent.document.location.replace(URL);
}
