// JavaScript Document
<!--
function callAjax(pageToCall,dataToSend,method,fName)
{
	//alert(pageToCall);
	var objAjax = false;
	
	if(window.ActiveXObject)
	{
		objAjax = new ActiveXObject("Microsoft.xmlHttp"); //alert('ie');
	}
	else if(window.XMLHttpRequest) 
	{
		objAjax = new XMLHttpRequest(); 	//alert('mozila');
	}		
	objAjax.open(method,pageToCall,true);
	objAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	if(method=="GET")
	{
		objAjax.send(null);
	}
	else if (method=="POST")
	{
		objAjax.send(dataToSend);
	}	 
	
	objAjax.onreadystatechange=function()
	{
		if(objAjax.readyState==4)
		{
			var strResponse="";
			strResponse = objAjax.responseText;
			eval(fName)(strResponse);
		}
	}	
}


function popup_window()
{
	//alert(document.window.offsetParent);
	document.getElementById('popup_window').style.display='block';
	document.getElementById('popup_window').style.visibility='visible';	
	
	/*var strPopup = "";	
	strPopup ="<table cellpadding='1' width='100%' align='center' bgcolor='#330000'><tr><td><table border='0' cellpadding='2' cellspacing='2' width='100%' align='center' bgcolor='#FFFFFF'><tr><td colspan='2' align='right' valign='top'><a href='#' title='Close' onClick='close_popup_window();'><img src='images/cross.jpg' border='0'></a></td></tr><tr><td colspan='2' align='center' class='sussess_message' style='font-size:16px'>Quick Contact</td>  	 </tr>	 <tr><td colspan='2' class='home_columns' style='font-size:12px'><strong>If you have any questions or would like someone from GOLF-AWAY to contact you to discuss golf tours or vacations, please fill in your contact details below and any thoughts you have.</strong></td>   	 </tr>	  <tr>		<td class='home_columns' align='right'>Your Name:&nbsp;</td>		<td ><input type='text' id='txt_name' name='txt_name' size='30' value='' maxlength='30'></td> 	 </tr>	 <tr> 		<td class='home_columns' align='right'>Telephone No:&nbsp;</td>		<td ><input type='text' id='txt_telephone' name='txt_telephone' size='30' value='' maxlength='20'></td> 	  </tr>	  <tr> 		<td class='home_columns' align='right'>Email Address:&nbsp;</td><td ><input type='text' id='txt_email' name='txt_email' size='30' value='' maxlength='100'></td> 	  </tr>		  <tr> 		<td class='home_columns' valign='top' align='right'>Comments / Questions:&nbsp;</td>		<td valign='top'><textarea id='txt_comments' name='txt_comments' rows='5' cols='25'></textarea></td> 	  </tr>	  <tr> 		<td >&nbsp;</td>		<td><input type='button' name='send_email' value='Send' onClick='chkQuickContact();'></td> 	  </tr>    </table> </td></tr></table>";*/
	
}

function close_popup_window()
{
	document.getElementById('popup_window').style.display='none';
	document.getElementById('popup_window').style.visibility='hidden';
}

function chkQuickContact()
{
    var empty_field_count=0;
	var form_data="";	
		
  	if(trim(document.getElementById('txt_name').value)=="")
	{
		empty_field_count = empty_field_count +1;		
	}
	else
	{
		form_data = 'txt_name='+escape(trim(document.getElementById('txt_name').value));		
	}
	/// code to check telephone
	if(trim(document.getElementById('txt_telephone').value)=="")
	{
		empty_field_count = empty_field_count +1;
	}
	else
	{
		form_data = form_data + '&txt_telephone='+escape(trim(document.getElementById('txt_telephone').value));		
	}
	/// code to check email address
	if(trim(document.getElementById('txt_email').value)=="")
	{
		empty_field_count = empty_field_count +1;
	}
	else
	{
		var email_add = "";
		email_add =trim(document.getElementById('txt_email').value);
		
		if(validateEmail(email_add))
		{
			form_data = form_data + '&txt_email='+escape(trim(document.getElementById('txt_email').value));	
		}
		else
		{
			document.getElementById('txt_email').focus();	
			return false;
		}
	}
	
	if(empty_field_count==3)
	{
		alert("Atleast one of field needs to be filled in.");
		document.getElementById('txt_name').focus();
		return false;
	}
	else
	{
		if(document.getElementById('txt_comments').value!="")
		{
			form_data = form_data + '&txt_comments='+escape(trim(document.getElementById('txt_comments').value));	
		}		
				
		var tmp_url = parent.document.URL;
		var new_url="";
	
		arr_url = tmp_url.split("/");
		
		for(i=0;i<arr_url.length-1;i++)
		{
			new_url = new_url + arr_url[i] + '/';
		}
		//alert(new_url);
		//callAjax(new_url+'send_quick_contact.php',form_data,'POST','email_response');
		callAjax(new_url+'asp_send_quick_contact.asp',form_data,'POST','email_response');
		return true;
	}   
}

function email_response(response_string)
{
	//alert(response_string);
	if(response_string=="susscess")
	{
	    //thank_u_msg = 'Thank you for your inquiry. We will get back to you within the next few days.';		
		document.getElementById('popup_window').style.display='none';
		document.getElementById('popup_window').style.visibility='hidden';
		document.getElementById('txt_name').value="";
		document.getElementById('txt_telephone').value="";
		document.getElementById('txt_email').value="";
		document.getElementById('txt_comments').value="";
		
		document.getElementById('display_message').style.display='block';
		document.getElementById('display_message').style.visibility='visible';		
		//document.getElementById('popup_window').innerHTML = thank_u_msg;	
	}
}
function close_display_message()
{
	document.getElementById('display_message').style.display='none';
	document.getElementById('display_message').style.visibility='hidden';
}

function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}

//rtrim function
function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }

  return argvalue;
}

//trim function
function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

function validateEmail(email) 
{	//passing controlas a argument
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email)) 
	{
		alert("Please enter valid email");
		return false;
	}
	return true;
}
//-->