var PLEASE_ENTER="Please enter ";
var WSPATH="http://www.kellysportrush.co.uk/tickets";
var HTTPS_WSPATH="http://www.kellysportrush.co.uk/tickets";

function changeRoomDeail(id)
{
	document.getElementById("charge_"+id).style.display="block";
	var slctroom=document.getElementById("selectroom").value;
	document.getElementById("charge_"+slctroom).style.display="none";
	document.getElementById("selectroom").value=id;
}
function checkValidDate(bookDate)
{
	var dtAry=bookDate.split("-");
	
	today = new Date();
	var crMon=eval(today.getMonth()+1);
 	var crYer=today.getFullYear();
 	var crDay=today.getDate();
 	var vld=1;
 	
	if(dtAry[0]<crYer){
		vld=0;
	}else if(dtAry[0]==crYer && dtAry[1]<crMon){
		vld=0;
	}else if(dtAry[0]==crYer && dtAry[1]==crMon && dtAry[2]<crDay){
		vld=0;
	}
	return vld;
}
function sethtVal(bookDt)
{
	var curtd_id="dtcalid_"+bookDt;
	
	var selectarray='';
	var alrdySelectArray=document.getElementById('bookDArray').value;
	
	if(checkValidDate(bookDt))	
	{
		if(alrdySelectArray==''){
			document.getElementById('bookDArray').value=bookDt;
			document.getElementById(curtd_id).className="dpDayHighlightTD";
		}
		else
		{
			var tableEveArray=alrdySelectArray.split(",");
			if(in_array(bookDt,tableEveArray))
			{
				for(var c=0;c<tableEveArray.length;c++){
					if(bookDt==tableEveArray[c]){
						document.getElementById(curtd_id).className="dpTD";
					}else{
						if(selectarray!='') selectarray+=",";
						selectarray+=tableEveArray[c];
					}	
				}
				document.getElementById('bookDArray').value=selectarray;
			}else{
				document.getElementById('bookDArray').value=alrdySelectArray+","+bookDt;
				document.getElementById(curtd_id).className="dpDayHighlightTD";
			}
		}
	}
	else
	{
		alert("You can't place booking for expired dates.");
	}
}

function shcalHotBookload()
{
	if(document.getElementById("hbkdatePickerDivID")){
	  	setTimeout('htBkrefreshDatePicker("hbkdtpick","hbkdatePickerDivID");',1000);
	}
	else{
	  	setTimeout("shcalHotBookload();",200);
	}
}
function nextHotBook(){
	var bookDArray=document.getElementById('bookDArray').value;
	if(bookDArray!=''){
		window.location.href=HTTPS_WSPATH+'/hotel-booking-details.php?bookDArray='+encodeURI(bookDArray);
	}else{
		alert("Please select the date(s) you want to book for hotel.");
		return false;
	}	
}
function hotbookValid(hot_book_id)
{
	var dt=document.frm_hot_cc_detail;
	var hot_room_type=trim(dt.hot_room_type.value);
	var hot_no_heads=trim(dt.hot_no_heads.value);
	var hot_no_rooms=trim(dt.hot_no_rooms.value);
	var hot_book_dates=trim(dt.hot_book_dates.value);
	
	if(hot_room_type==''){
		alert("Please select room type.");
		return false;
	}	
	if(hot_no_heads==''){
		alert("Please enter number of guest(s).");
		dt.hot_no_heads.focus();
		return false;
	}
	else if(!isInt(hot_no_heads)){
		alert("Please enter a numeric value for number of guest(s).");
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}
	else if(hot_no_heads==0){
		alert("Please enter a non zero numeric value for number of guest(s).");
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}
	if(hot_no_rooms==''){
		alert("Please enter number of rooms.");
		dt.hot_no_rooms.focus();
		return false;
	}
	else if(!isInt(hot_no_rooms)){
		alert("Please enter a numeric value for number of rooms.");
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}
	else if(hot_no_rooms==0){
		alert("Please enter a non zero numeric value for number of rooms.");
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}

	var headallows=getAJAXcontent(HTTPS_WSPATH + "/hotel-booking-availability.php?hrt="+hot_room_type+"&hnh="+hot_no_heads+"&hnr="+hot_no_rooms);
	if(headallows==0){
		alert("You are not allowed to book "+hot_no_heads+" guest(s) in "+hot_no_rooms+" rooms");
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}	

	hot_book_dates=str_replace("\r\n",",",hot_book_dates);
	hot_book_dates=str_replace("\n",",",hot_book_dates);
	
	var room_available=getAJAXcontent(HTTPS_WSPATH + "/hotel-booking-availability1.php?hrt="+hot_room_type+"&hnr="+hot_no_rooms+"&bdate="+hot_book_dates);
	var raArray=room_available.split(":;");
	if(raArray[0]=="0"){
		alert(raArray[2]+" rooms available for the date "+raArray[1]);
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}
	if(trim(dt.user_first_name.value)==''){
		alert(PLEASE_ENTER+"first name.");
		dt.user_first_name.focus();
		return false;
	}
	if(trim(dt.user_last_name.value)==''){
		alert(PLEASE_ENTER+"last name.");
		dt.user_last_name.focus();
		return false;
	}
	if(trim(dt.user_email_address.value)==''){
		alert(PLEASE_ENTER+"email.");
		dt.user_email_address.focus();
		return false;
	}else{
		if(!validString(trim(dt.user_email_address.value),'email')){
			alert("Please enter valid email.");
			dt.user_email_address.focus();
			dt.user_email_address.select();
			return false;
		}
	}
	if(trim(dt.user_mobile.value)==''){
		alert(PLEASE_ENTER+"mobile.");
		dt.user_mobile.focus();
		return false;
	}
	if(trim(dt.hot_home_address.value)==''){
		alert(PLEASE_ENTER+"home address.");
		dt.hot_home_address.focus();
		return false;
	}
	if(trim(dt.hot_postcode.value)==''){
		alert(PLEASE_ENTER+"post code.");
		dt.hot_postcode.focus();
		return false;
	}
	if(trim(dt.hot_holder_name.value)==''){
		alert(PLEASE_ENTER+"name printed on card.");
		dt.hot_holder_name.focus();
		return false;
	}
	if(trim(dt.hot_card_type.value)==2){
		if(trim(dt.hot_issue_number.value)==''){
			alert(PLEASE_ENTER+"issue number.");
			dt.hot_issue_number.focus();
			return false;
		}	
	}
	if(trim(dt.hot_card_number.value)==''){
		alert(PLEASE_ENTER+"card number.");
		dt.hot_card_number.focus();
		return false;
	}
	else if(isNaN(trim(dt.hot_card_number.value))){
		alert(PLEASE_ENTER+"a numeric value for card number.");
		dt.hot_card_number.focus();
		dt.hot_card_number.select();
		return false;
	}
	else if((dt.hot_card_number.value).length<16){
		alert(PLEASE_ENTER+"a 16 digit numeric value for card number.");
		dt.hot_card_number.focus();
		dt.hot_card_number.select();
		return false;
	}
	today = new Date();
	var crMon=eval(today.getMonth()+1);
 	var crYer=today.getFullYear();
 	var crDay=today.getDate();

	if(crYer==trim(dt.hot_srt_year.value) && trim(dt.hot_srt_mon.value)>=crMon){	
		alert("Your card is not valid, select valid start date.");
		return false;
	}
	if(crYer==trim(dt.hot_exp_year.value) && trim(dt.hot_exp_mon.value)<=crMon){	
		alert("Your card is not valid, select valid expiration date.");
		return false;
	}
	if(trim(dt.hot_sec_code.value)==''){
		alert(PLEASE_ENTER+"card security code.");
		dt.hot_sec_code.focus();
		return false;
	}
	else if(isNaN(trim(dt.hot_sec_code.value))){
		alert(PLEASE_ENTER+"a numeric value for card security code.");
		dt.hot_sec_code.focus();
		dt.hot_sec_code.select();
		return false;
	}
	submitStr="submitAction=ResBook"+"&user_first_name="+trim(dt.user_first_name.value)+"&user_last_name="+trim(dt.user_last_name.value)+"&user_email_address="+trim(dt.user_email_address.value)+"&user_mobile="+trim(dt.user_mobile.value)+"&hot_home_address="+trim(dt.hot_home_address.value)+"&hot_postcode="+trim(dt.hot_postcode.value)+"&hot_book_dates="+hot_book_dates+"&hot_room_type="+hot_room_type+"&hot_no_heads="+hot_no_heads+"&hot_no_rooms="+hot_no_rooms+"&hot_book_summery="+trim(dt.hot_book_summery.value)+"&hot_arrive_time1="+trim(dt.hot_arrive_time1.value)+"&hot_arrive_time2="+trim(dt.hot_arrive_time2.value)+"&hot_arrive_time3="+trim(dt.hot_arrive_time3.value)+"&hot_detart_time1="+trim(dt.hot_detart_time1.value)+"&hot_detart_time2="+trim(dt.hot_detart_time2.value)+"&hot_detart_time3="+trim(dt.hot_detart_time3.value)+"&hot_holder_name="+trim(dt.hot_holder_name.value)+"&hot_card_type="+trim(dt.hot_card_type.value)+"&hot_issue_number="+trim(dt.hot_issue_number.value)+"&hot_card_number="+trim(dt.hot_card_number.value)+"&hot_srt_mon="+trim(dt.hot_srt_mon.value)+"&hot_srt_year="+trim(dt.hot_srt_year.value)+"&hot_exp_mon="+trim(dt.hot_exp_mon.value)+"&hot_exp_year="+trim(dt.hot_exp_year.value)+"&hot_sec_code="+trim(dt.hot_sec_code.value)+"&hot_book_id="+hot_book_id;
	var editVal=postAjaxContent(HTTPS_WSPATH + "/hot_book_details_post.php",submitStr,"frm_hot_input","frm_hot_input");
	alert("You want to book hotel for "+hot_no_heads+" guest(s)");
	window.location.href='hotel-booking-confirm.php?hot_book_id='+hot_book_id;
	return false;
}
function hotbookConfirmValid(hot_book_id,grTot)
{
	insertVal=getAJAXcontent(HTTPS_WSPATH + "/hotel_booking_confirm_post.php?hot_book_id="+hot_book_id+"&grTot="+grTot);
	alert("Your total booking charge is : "+grTot);
	window.location.href='hotel-booking-final.php?hot_book_id='+hot_book_id;
}

function nextTermTikBook(){
	if(document.frm_ticket_booking_term.accept_terms_ticket.checked)
		window.location.href='ticket-booking.php';
	else{
		alert("You have to accept ticket terms and conditions.");
		return false;
	}	
}
function gethomeImage(id)
{
	alert(id);
}
function showdetailBooking(tabname,tabid)
{
	var max_tbl=document.getElementById("max_tbl").value;	
	for(k=1;k<=max_tbl;k++){
		if(document.getElementById(tabname+"_"+k))
			document.getElementById(tabname+"_"+k).style.display=(k==tabid?'block':'none');
	}			
}
function tikbookValid(tik_book_id)
{
	var dt=document.frm_tbk_cc_detail;
	if(trim(dt.user_first_name.value)==''){
		alert(PLEASE_ENTER+"first name.");
		dt.user_first_name.focus();
		return false;
	}
	if(trim(dt.user_last_name.value)==''){
		alert(PLEASE_ENTER+"last name.");
		dt.user_last_name.focus();
		return false;
	}
	if(trim(dt.user_email_address.value)==''){
		alert(PLEASE_ENTER+"email.");
		dt.user_email_address.focus();
		return false;
	}else{
		if(!validString(trim(dt.user_email_address.value),'email')){
			alert("Invalid email.");
			dt.user_email_address.focus();
			dt.user_email_address.select();
			return false;
		}
	}
	if(trim(dt.user_mobile.value)==''){
		alert(PLEASE_ENTER+"mobile.");
		dt.user_mobile.focus();
		return false;
	}
	if(trim(dt.tik_home_address.value)==''){
		alert(PLEASE_ENTER+"home address.");
		dt.tik_home_address.focus();
		return false;
	}
	if(trim(dt.tik_postcode.value)==''){
		alert(PLEASE_ENTER+"post code.");
		dt.tik_postcode.focus();
		return false;
	}
	var tik_no_heads=dt.tik_no_heads.value
	if(trim(tik_no_heads)==''){
		alert(PLEASE_ENTER+"number of heads.");
		dt.tik_no_heads.focus();
		return false;
	}
	else if(!isInt(tik_no_heads)){
		alert(PLEASE_ENTER+"a numeric value for number of heads.");
		dt.tik_no_heads.focus();
		dt.tik_no_heads.select();
		return false;
	}
	else if(trim(tik_no_heads)==0){
		alert(PLEASE_ENTER+"a non zero numeric value for number of heads.");
		dt.tik_no_heads.focus();
		dt.tik_no_heads.select();
		return false;
	}

	var limit_val=eval(dt.limit_val.value);
	var remain_booking=eval(dt.remain_booking.value);
	if(tik_no_heads > remain_booking){
		alert("Booking remains for "+remain_booking+" guest(s).");
		dt.tik_no_heads.focus();
		dt.tik_no_heads.select();
		return false;
	}
	/*submitStr="submitAction=TikBook"+"&user_first_name="+trim(dt.user_first_name.value)+"&user_last_name="+trim(dt.user_last_name.value)+"&user_email_address="+trim(dt.user_email_address.value)+"&user_mobile="+trim(dt.user_mobile.value)+"&tik_home_address="+trim(dt.tik_home_address.value)+"&tik_postcode="+trim(dt.tik_postcode.value)+"&tik_no_heads="+trim(dt.tik_no_heads.value)+"&tik_book_id="+tik_book_id;
	var editVal=postAjaxContent( "tik_book_details_post.php",submitStr,"frm_tik_input","frm_tik_input");
	alert("You want to book ticket for "+tik_no_heads+" guest(s).");
	window.location.href="ticket-booking-confirm.php?tik_book_id="+tik_book_id;
	return editVal;*/

	if(!confirm("You want to book ticket for "+tik_no_heads+" guest(s)."))
		return false;
	else	
		return true;
	
}
function tikbookConfirmValid(tik_book_id,grandtotal)
{
	alert("Your total booking charge is : "+grandtotal);
	window.location.href='ticket-booking-confirm-post.php?v='+tik_book_id;
}
function validCaptch(ccode,pccode)
{
	var captchacode=getAJAXcontent("captcha_validate.php?ccode="+ccode+"&pccode="+pccode);
	return (captchacode=="1"?true:false);
}
function uniqueNwlUser(email)
{
	unique_email=getAJAXcontent("unique_email.php?email="+email);
	return (unique_email=="1"?true:false);
}
function newsLetterValid()
{
	var dt=document.frm_news_letter;
	if(trim(dt.nwl_uname.value)==''){
		alert(PLEASE_ENTER+"name.");
		dt.nwl_uname.focus();
		return false;
	}
	if(trim(dt.nwl_uemail.value)==''){
		alert(PLEASE_ENTER+"email.");
		dt.nwl_uemail.focus();
		return false;
	}else{
		if(!validString(trim(dt.nwl_uemail.value),'email')){
			alert("Please enter valid email.");
			dt.nwl_uemail.focus();
			dt.nwl_uemail.select();
			return false;
		}
	}
	if(trim(dt.nwl_uphone.value)==''){
		alert(PLEASE_ENTER+"town.");
		dt.nwl_uphone.focus();
		return false;
	}
	if(trim(dt.nwl_umobile.value)==''){
		alert(PLEASE_ENTER+"mobile number.");
		dt.nwl_umobile.focus();
		return false;
	}
	if(trim(dt.generated_code.value)==''){
		alert(PLEASE_ENTER+"code.");
		dt.generated_code.focus();
		return false;
	}
	else if(!validCaptch(trim(dt.generated_code.value),trim(dt.pre_generated_code.value)))
	{
		alert("Please enter the characters correctly.");
		dt.generated_code.focus();
		dt.generated_code.select();
		return false;
	}
	if(uniqueNwlUser(trim(dt.nwl_uemail.value)))
	{
		alert("Email already exists.");
		return false;
	}
	submitStr="submitAction=Newsletter"+"&nwl_uname="+trim(dt.nwl_uname.value)+"&nwl_uemail="+trim(dt.nwl_uemail.value)+"&nwl_uphone="+trim(dt.nwl_uphone.value)+"&nwl_umobile="+trim(dt.nwl_umobile.value);
	var insVal=postAjaxContent("newsletter_post.php",submitStr,"frm_nwl_success","frm_nwl_input");
	window.location.href="news-signap.php";
	return false;
}

function callDetails()
{
	 setTimeout("showDetailcalendarafterload()",200);
}
function showDetailcalendarafterload(){
	if(document.getElementById("dtEvedatePickerDivID"))
	{
		setTimeout('eventrefreshDatePicker("dtEvedtpick","dtEvedatePickerDivID")',100);
	}
	else
	{
		setTimeout("showDetailcalendarafterload()",200);
	}
}
function showEve(shTab,tbId)
{
	var maxEve=document.getElementById("maxEve").value;
	for(var j=1;j<=maxEve;j++){
		if(document.getElementById(shTab+"_"+j))
			document.getElementById(shTab+"_"+j).style.display=(j==tbId?'block':'none');	
	}	
	crNav("eveNav","showEve",shTab,tbId);
}
function showEveDtl(shTab,prFixName,idsName)
{
	var eveIds=document.getElementById(idsName).value;
	var idArray=eveIds.split(",");
	for(var j=0;j<idArray.length;j++){
		if(document.getElementById(prFixName+idArray[j]))
			document.getElementById(prFixName+idArray[j]).style.display=(idArray[j]==shTab?'block':'none');	
	}	
}

function showEveMon(shTab)
{
	var allEveDiv=document.getElementById("allEveDiv").value;
	var events=allEveDiv.split(",");
	for(var k=0;k<events.length;k++){
		if(document.getElementById(events[k])){
			if(events[k]==shTab){
				document.getElementById(events[k]).style.display='block';
				showEve(events[k],1);
			}else{
				document.getElementById(events[k]).style.display='none';
			}	
		}	
	}
}

function crNav(fldName,funName,shTab,tbId)
{
	var naval='';
	var pre=tbId-1;
	var nex=tbId+1;	
	naval='<table width="20%" border="0" cellspacing="0" cellpadding="0">';
        naval+='    <tr>';
        naval+='        <td class="navLink">';
        if(pre>0){
        naval+='	  <a onclick="'+funName+'(\''+shTab+'\','+pre+')" href="javascript:void(0)" title="Previous Month">Previous</a>'; }else{
	naval+='          &nbsp;';}
	naval+='        </td>';
        naval+='        <td class="navLink">';
        if(document.getElementById(shTab+"_"+nex)){
        naval+='          <a onclick="'+funName+'(\''+shTab+'\','+nex+')" href="javascript:void(0)" title="Next Month">Next</a>'; }else{ 
        naval+='          &nbsp;';}
	naval+='        </td>';
        naval+='    </tr>';
        naval+='</table>';
        document.getElementById(fldName).innerHTML=naval;
}

function nextTermHotBook(){
	if(document.frm_hotel_booking_term.accept_terms_hotel.checked)
		window.location.href='hotel-booking.php';
	else{
		alert("You have to accept hotel terms and conditions.");
		return false;
	}	
}
