function showForm()
{
	var objBody = document.getElementsByTagName("body")[0];
		
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	var ObjForm = document.createElement('div');
	ObjForm.setAttribute('id','overlay');
	ObjForm.style.position = 'absolute';
	ObjForm.style.top = '0';
	ObjForm.style.left = '0';
	ObjForm.style.zIndex = '90';
 	ObjForm.style.width = '100%';

	// set height of Overlay to take up whole page and show
	ObjForm.style.height = (arrayPageSize[1] + 'px');
	//ObjForm.style.display = 'block';
	
	objBody.appendChild(ObjForm);	
	
	var lightboxTop = arrayPageScroll[1] + 100;
	
	// create keyboard message
	var objKeyboardMsg = document.createElement("div");
	objKeyboardMsg.setAttribute('id','keyboardMsg');
	objKeyboardMsg.style.height = (arrayPageSize[1] + 'px');
	objKeyboardMsg.style.position = 'absolute';
	objKeyboardMsg.style.top = '0';
	objKeyboardMsg.style.left = '0';
	objKeyboardMsg.style.zIndex = '100';
 	objKeyboardMsg.style.width = '100%';
	
	MarginTopTable =  (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	
	//objKeyboardMsg.innerHTML = 'press <kbd>x</kbd> to close gffff';
	//objKeyboardMsg.innerHTML = '<br /><div style=padding-left: 11px; padding-right: 25px; text-align: justify;><strong>All rates are :</strong><ul style=margin-top: 0px; margin-left: 18px;><li>Rates above are exclusive of 21% tax and service and per room per night</li><li>High season surcharge<br /><table cellpadding=0 cellspacing=0 border=0 style=width: 100%;><tr><td>01 – 31 August 2008 </td><td>US$ 15.00/room/night</td></tr><tr><td>27 December 2008 – 05 January 2008</td><td>US$ 25.00/room/night</td></tr></table></li></ul></div>';
	objKeyboardMsg.innerHTML = '<form name="form_contact" action="" method="post"><table style="margin-top:'+MarginTopTable+';" id="contact_form" cellspacing="0" cellpadding="0" border="0" align="center"><tr><td>Send to:</td><td>Other</td></tr><tr><td><select name="sendto" onChange="checkDepartment()"><option value="">Select Department</option><option value="IT Department">IT Department</option><option value="Marketing Department">Marketing Department</option><option value="Other">Other</option></select></td><td><input type="text" name="other" disabled="disabled" /></td></tr><tr><td colspan="2"><b>Message</b></td></tr><tr><td colspan="2"><textarea name="message" rows="5" cols="35"></textarea></td></tr><tr><td colspan="2"><table cellspacing="0" align="center" id="identification" cellpadding="0" border="0" width="100%"><tr><td colspan="2"><b>Tell us how to get in touch with you</b></td></tr><tr><td>Name</td><td><input type="text" name="name" size="30" /></td></tr><tr><td>Company</td><td><input type="text" name="company" size="30" /></td></tr><tr><td>Email</td><td><input type="text" name="email" size="30" /></td></tr><tr><td>Phone</td><td><input type="text" name="phone" size="30" /></td></tr><tr><td>&nbsp;</td><td><input type="button" name="button" value="Submit Comments"  onClick="return validateForm()" />&nbsp;<input type="button" name="button" value="Cancel" onClick="hideLightbox()" /></td></tr></table><br /><br /></td></tr></table></form>';
	objBody.appendChild(objKeyboardMsg);
	
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function hideLightbox()
{
	// get objects
	ObjForm = document.getElementById('overlay');
	objKeyboardMsg = document.getElementById('keyboardMsg');

	// hide lightbox and overlay
	ObjForm.style.display = 'none';
	objKeyboardMsg.style.display = 'none';
	
	var objBody = document.getElementsByTagName("body")[0];
	
	objBody.removeChild(ObjForm);
	objBody.removeChild(objKeyboardMsg);
	
	// disable keypress listener
	document.onkeypress = '';
}

function checkDepartment()
{
	if(document.form_contact.sendto.value == 'Other')
	{
		document.form_contact.other.disabled = false;
	}
	else
	{
		document.form_contact.other.disabled = true;
	}
}

function validateForm()
{
	if(document.form_contact.sendto.value == '')
	{
		alert('Please select Department');
		return false;
	}
	else if(document.form_contact.sendto.value == 'Other')
	{
		if(document.form_contact.other.value=='')
		{
			alert('Please input other Department name');
			return false;
		}
	}
	if(document.form_contact.message.value=='')
	{
		alert('Please input your message');
		return false;
	}
	if(document.form_contact.name.value=='')
	{
		alert('Please input your name');
		return false;
	}
	if(document.form_contact.name.value=='')
	{
		alert('Please input your name');
		return false;
	}
	if(document.form_contact.email.value=='')
	{
		alert('Please input your email address');
		return false;
	}
	else if(document.form_contact.email.value!='')
	{
		flag = true;
		akeong = document.form_contact.email.value.indexOf('@');
		titik = document.form_contact.email.value.indexOf('.');
		for(i=0;i<document.form_contact.email.value.length;i++)
		{
			if(document.form_contact.email.value.charAt(i) == '.')
				titik = i;
		}
		if(akeong == -1 || titik == -1 || akeong > titik || akeong + 1 == titik || titik + 1 > document.form_contact.email.value.length)
		{
			alert('Please input a valid email address \n(eg. example@indovickers.com)');
			return false;
		}
	}
	var department;
	if(document.form_contact.sendto.value == 'Other')
		department = document.form_contact.other.value;
	else
		department = document.form_contact.sendto.value;
	var message = document.form_contact.message.value;
	var name = document.form_contact.name.value;
	var company = document.form_contact.company.value;
	var email = document.form_contact.email.value;
	var phone = document.form_contact.phone.value;
	
	sendMail(department,message,name,company,email,phone);
}

function sendMail(department,message,name,company,email,phone)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + 100;
	var lightboxLeft = 100;
	
	MarginTopTable =  (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	MarginLeftTable =  (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
	
	document.getElementById("keyboardMsg").innerHTML = '<table width="50%" style="background: #FFFFFF; margin-top:'+MarginTopTable+'; padding-left: '+MarginLeftTable+'; text-align: left;" cellspacing="0" cellpadding="0" border="0" align="center"><tr><td align="center"><img src="images/spin.gif" border="0" height="15" />&nbsp;Please wait....</td></tr></table>';
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var elements = xmlHttp.responseText;
	
			//alert(elements);
			document.getElementById("keyboardMsg").innerHTML = '<table width="50%" style="background: #FFFFFF; margin-top:'+MarginTopTable+'; padding-left: 10px; text-align: left; height: 100px;" cellspacing="0" cellpadding="0" border="0" align="center"><tr><td>&nbsp;</td></tr><tr><td>'+elements+'</td></tr><tr><td>&nbsp;</td></tr><tr><td align="center"><input type="button" name="button" value="Close" onClick="hideLightbox()" /></td></tr><tr><td>&nbsp;</td></tr></table>';
			//document.getElementById('test').innerHTML = "<select name='type'><option value=''>1</option></select>";
			
			
		}
	}
	var url = "sendMail.php";
	var params = "d=" + department + "&m=" + message + "&n=" + name + "&c=" + company + "&e=" + email + "&p=" + phone;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}