// JavaScript Document

// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
window.onload = function() {
	externalLinks();
}



// Background Styler
/*
var menu1='url(images/lounge-bar-bg-tc.jpg) no-repeat top center'

function setStyle()
{
document.body.style.background="#FFCC80 url(bgdesert.jpg)
repeat-y";
}
*/
var main='url(images/lounge-bar-bg-tc.jpg) no-repeat top center'
var main2='url(images/hotel-bg-bc.jpg) no-repeat bottom center'

function setStyle(what){
//document.getElementById('menu_text').innerHTML=''+what+'';
document.body.style.background=''+what+'';


//document.getElementById('ttt').style.background=""''+what+''" no-repeat top center";

}

//-->


function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

{



        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {

			div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
			div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
			div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
			div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };

            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

this.scrollDown = function() {
if (this.div_obj) {
this.scrollCursor += this.speed;
this.div_obj.scrollTop = this.scrollCursor;
if (this.div_obj.scrollTop == this.scrollCursor) {
this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
} else {
this.scrollCursor = this.div_obj.scrollTop;
}
}
}

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
/*
this.hideScroll = function() {
	if (this.div_obj.clientHeight > (this.div_obj.scrollHeight-this.div_obj.clientHeight)) {
		document.getElementById('scroll_up').style.display="none";
		document.getElementById('scroll_down').style.display="none";
	}
}

this.hideScroll();	
	*/	
}



function show_error(id)
{
	document.getElementById(id).style.border="solid 2px #1dbfd7";
}

function clear_errors(which)
{
	for (i=0;i<document.forms[which].elements.length;i++)
	{
		if ( (document.forms[which].elements[i].type != "button") && (document.forms[which].elements[i].type != "reset") && (document.forms[which].elements[i].id!="fieldset") )
			document.forms[which].elements[i].style.border="solid 0px #000000";
	}
}


function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
		return false;

   if(field.value.match(emailExp))
		   return true;
   else 
		   return false;
   
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailid)
{
	clear_errors(whichform);
	
	//check mandatory fields
	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if (document.getElementById(man[i]).value == "")
		{
			show_error(man[i]);
			alert ("You must fill all the mandatory fields (*)");
			return false;
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			return false;
		}
	}
	
	//check numeric fields
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
			
			if (isNaN (document.getElementById(numeric[i]).value))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}
