function addEvent(obj, evType, fn, useCapture)
{
    if (obj.addEventListener) 
	{
        obj.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (obj.attachEvent) 
	{
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
    else {
       obj["on"+evType] = fn;
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function prepareThumbs ()
{
	if (!document.getElementsByTagName)
		return false;
	var links = document.getElementsByTagName("a");

	if (links)
	{
		for (var i=0; i < links.length; i++)
		{
			var anchor = links[i];
			if (anchor.className.match("pop-img"))
			{
				anchor.onclick = function()
				{
					imgPop (this.href, this.title);
					return false;
				}
			}
		} // end loop

	} else return false;
	return null;
}

function imgPop (imageURL,imageTitle)
{	
	var page_url = "/scripts/pop_img.html?"+imageURL+"?"+imageTitle;
	var newWin = window.open( page_url, "popImg",  'status=yes,scrollbars=no,resizable=yes,width=700,height=650');
	newWin.focus();
}

function obfuscate (text)
{
    var obfuscated = '';

    for (i = 0; i < text.length; i++) {
		obfuscated += "&#" + text.charCodeAt(i);
	}
	return (obfuscated);
}

function show_address (mailbox, link_text)
{
	if (mailbox == '') {
		return false;
	}

	var domain_name	= 'filorian.com';
	var email	 	= mailbox + '@' + domain_name;
	var email_obf 	= obfuscate (email);

	// use the link_text provided or the address if it's not.
	if (link_text != '') 
	{
		var link_text_obf = obfuscate (link_text);
	}
	else 
	{
		var link_text_obf = email_obf;
	}
	document.write('<a href="mailto:' + email_obf + '">' + link_text_obf + '</a>');
}

function resLoad ()
{
	var body_id = window.document.body.id;
	switch(body_id)
	{
		case 'rez_av':
		parent.pushDate();
		break
		
		case 'rez_bf':
		parent.populate('Book');
		showTwoBedAptTxt ();
		break
		
		case 'rez_cf':
		parent.populate('Change');
		showTwoBedAptTxt ();
		break
		
		case 'rez_nr':
		parent.pushDate(); 
		break
		
		case 'rez_checkout':
		parent.pushAddress();
		break			
		
		case 'rez_send':
		parent.postData(); 
		/*alert('post data');*/
		break
		
		case 'rez_thankyou':
		parent.clearAll();
		break			
	}
}

function showTwoBedAptTxt ()
{
	var form = document.forms[0];
	var elm = form.RoomType;
	var elm_value = form.RoomType.selectedIndex;
	check (elm_value);
	
	if (elm.onchange == null) 
	{
		elm.onchange = function () {
			showTwoBedAptTxt();
		}	
	}
	
	function check (elm_value) 
	{
		var p = document.getElementById('two-bed-text');	
		if (elm_value == 3) {
			p.style.display = 'block';
		}
		else {
			if(p != null)
				p.style.display = 'none';	
		}
	}
}

function fixRoomTypeMenu ()
{
	var elms = document.getElementsByTagName('SELECT');
	
	if (!elms) { return false; }
	
	var elmsLen = elms.length;
	var elm = false;
	
	var min_width = '160px';
	var max_width = '200px';
	
	function adjastStyleWidth (elm) 
	{ 
		//alert(elm.style.width);
		
		if (elm.style.width == min_width) 
		{
			elm.style.width = max_width;
		}
		else if (elm.style.width == max_width) 
		{
			elm.style.width = min_width;
		}
	}
	
	for (var i=0; i < elmsLen; i++) 
	{
		var anchor = elms[i];
		if (anchor.name == 'RoomType') 
		{
			//anchor.className = 'type-dropdown';
			anchor.setAttribute("className", 'type-dropdown');
			anchor.setAttribute("class", 'type-dropdown');
			//alert(anchor.className);
			anchor.style.width = max_width;
			//anchor.onclick = function () { adjastStyleWidth (this); };
			
		}
	}
}
// -- addEvent Statements -- //
addEvent(window,"load",prepareThumbs);
addEvent(window,"load",resLoad);
addEvent(window,"load",fixRoomTypeMenu); 

