/*FUNCTIONS for eclipseweb
By Totok Maryanto*/

var nReload = 6;
//var URLsite = "http://localhost/eclipseweb/";
//var URLsite 	= "http://splendedsaber-dc02r.gteinterlink.com/~eclipsew/";
var URLsite 	= "http://www.eclipsehospitality.com.au/";

function trim(str) {
  if(str) {
    str = str.replace(/^\s+/, "");
    str = str.replace(/\s+$/, "");
  }
  return str;
}

function checkEvents(showalert,inckeyword,basepage){
	var location = document.getElementById('location').value;
	var categories = document.getElementById('Etype').value;
	var month = document.getElementById('Emonth').value;
	if (inckeyword) var keyword = document.getElementById('keyword').value;
	var year,status;
	
	if (inckeyword){
		if (trim(month)!=0)	status = true;
		else status = false;
	}
	else {
		if (trim(location)!=0 && trim(categories)!=0 && trim(month)!=0) status = true;
		else status = false;
	}

		if (status) {
			spliter = month.split("-");
			month = trim(spliter[0]);
			year = trim(spliter[1]);
	
			if (typeof(keyword)=="undefined") keyword = '';
			window.location = basepage + '?page=eventscalendar&event_cat='+ categories +'&event_loc='+ location +'&keyword='+ keyword +'&month=' + month + '&year=' + year;
		}
		else {
			message = '';
			if (!inckeyword){
				if (location==0 && showalert==true) message += 'Please Choose Location !\n';
				if (categories==0 && showalert==true) message += 'Please Choose Categories !\n';
			}
			if (month==0 && showalert==true) message += 'Please Choose Month !\n';
			if (showalert) alert(message);
			return false;
		}

}

function openProgram(name,title,width,height){
	window.open(name,title,'resizable=no,scrollbars=no,left=' + (screen.width-width)/2 +  ',top=' + (screen.height-height)/2 + ',width=' + width + ',height=' + height + ',toolbar=no,status=no');
}

function closeMe(){
	window.open('','_parent','');
	window.close();
}

function NewVerifyImage()
{
    if (nReload <= 2)
        if (nReload <= 0)
        {
            alert("Sorry, too many reloads.");
            return;
        }
        else
            alert("Only " + nReload + " more reloads are allowed");
    nReload--;
    date = new Date();
    document.vimg.src = URLsite + "lib/jhfcaptcha.php?function=captchaimage&t="+date;

}

function openvideo(video,width,height){ 
	ajaxwin=dhtmlwindow.open("newsbox", "iframe", "eclipse_video.php?video="+video+"&width="+width+"&height="+height, "News Video", "width="+ (width + 20) + "px,height=" + (height+20) + "px,left="+ (screen.width-width)/2 + "px,top=" + (screen.height-height)/2 + "px,resize=1,scrolling=1")
	//ajaxwin=dhtmlwindow.open("newsbox", "ajax", "eclipse_video.php?video="+video+"&width="+width+"&height="+height, "News Video", "width="+ width + "px,height=" + height + "px,left="+ (screen.width-width)/2 + "px,top=" + (screen.height-height)/2 + "px,resize=1,scrolling=1")
	ajaxwin.onclose=function(){return window.confirm("Close Video Window ?")}
}

function createRightBox(){
	var eDiv=document.createElement("div");
	var htmlBox=document.getElementById('RightContents').innerHTML;
	//var bodyit=document.body;
	var bodyit=document.getElementById('PrintContent');
	
	eDiv.innerHTML = htmlBox;
	eDiv.setAttribute('class','RightContents');
	eDiv.setAttribute('id','RightBox');
	//eDiv.style.display="none";
	eDiv.style.position="absolute";
	eDiv.style.top="-1000px";
	eDiv.style.left="-1000px";
	eDiv.style.visibility="hidden";
	bodyit.appendChild(eDiv);
}

function removeRightBox(){
	var obj=document.getElementById('RightBox');
	//var bodyit=document.body;
	var bodyit=document.getElementById('PrintContent');
	try {
		bodyit.removeChild(obj);
	}
	catch(err){
		//alert(err.description);
	}
}

function arrangeLayout(loopVar,ajaxTimer){	
	var browser = navigator.userAgent;
	var theight = document.getElementById('LeftContentsHomePage').offsetHeight;	
	//var oriheight = document.getElementById('RightContents').offsetHeight;
	var oriwidth = document.getElementById('RightContents').offsetWidth;
	var leftheight = document.getElementById('SideBar').offsetHeight;
	var myTimer = ajaxTimer/1000;
	
	//browser is Opera, Firefox, Safari, SeaMonkey, etc (not IE) 
	if(browser.indexOf("MSIE")==-1){
		if(loopVar==0 || loopVar>myTimer){
			removeRightBox();
			createRightBox();
			if(loopVar>myTimer) loopVar=0;
		}
		
		//document.getElementById('RightBox').style.height = oriheight + "px";
		//alert(document.getElementById('RightBox').innerHTML);
		var htmlBox=document.getElementById('RightContents').innerHTML;
		var obj = document.getElementById('RightBox');
		var curheight = obj.offsetHeight;
		obj.style.width = oriwidth + "px";
		obj.innerHTML = htmlBox; 
		//var curheight = document.getElementById('RightBox').style.height;
		//alert(curheight);alert(theight);alert(leftheight);				
		if(parseInt(theight)>=parseInt(curheight) && parseInt(theight)>=parseInt(leftheight))
			document.getElementById('RightContents').style.height=theight + "px";
		else if(parseInt(leftheight)>=parseInt(curheight) && parseInt(leftheight)>=parseInt(theight))
			document.getElementById('RightContents').style.height=leftheight + "px";
		else 
			document.getElementById('RightContents').style.height=curheight + "px";
			
		var t=setTimeout("arrangeLayout("+(loopVar+1)+","+ajaxTimer+")",1000);
	}	
}