/////////////////////////// Javascript for booking flow changes /////////////////////////////////////////

// Javascript for customer accounts

function registrationForm()
{
    $('div#register_div').html('');
	$("div#register_div").load("/registrationForm.do?strAffiliateCode=00000080&strGroupId=TGU",function(data){
	    setValue('firstName','First Name');
	    setValue('lastName','Last Name');
	    setValue('userMobileNum','Mobile Number');
	    setValue('stdCode','std code');
	    setValue('userLandLineNum','Landline Number');
	    setValue('landLineExt','Extn');

		document.getElementById('hidepage1').style.display='block';
		document.getElementById('hidepage1').style.width=(screen.width)+"px";
	    document.getElementById('hidepage1').style.height =(screen.height)+"px";
	    $('div#register_div').show('slow');
	});

}

function resetPasswdForm()
{
	$('div#register_div').hide('slow');
    $('div#register_div').html('');
	$("div#register_div").load("/resetPasswdForm.do?strAffiliateCode=00000080&strGroupId=TGU", function(data){
	  document.getElementById('hidepage1').style.display='block';
	  document.getElementById('hidepage1').style.width=(screen.width)+"px";
      document.getElementById('hidepage1').style.height =(screen.height)+"px";
	  $('div#register_div').show('slow');
	});
	//showDiv('register_div');
}

function loginForm(){
    $('div#register_div').html('');
	$("div#register_div").load("/loginForm.do?strAffiliateCode=00000080&strGroupId=TGU",function(data){
	    setValue('userEmail',getCookie('cusId'));
		document.getElementById('hidepage1').style.display='block';
		document.getElementById('hidepage1').style.width=(screen.width)+"px";
	    document.getElementById('hidepage1').style.height =(screen.height)+"px";
		$('div#register_div').show('slow');
	});
	//showDiv('register_div');
}

function hideRegisterPopUpAndRefresh(){
	hideRegisterPopUp();
	if(top.location.href.indexOf('BookingFinalGuestConsumer.do') != -1){
		refreshLoginStatus();
	}else{
		window.location = (top.location.href).replace('#','');
	}
}

function hideRegisterPopUp(){
//hideDiv('register_div');
$('div#register_div').hide('slow');
$('div#register_div').html('');
hideDiv('hidepage1');
}

function showDiv(divId)
{
	document.getElementById(divId).style.display = "block" ;
}

function hideDiv(divId)
{
	document.getElementById(divId).style.display = "none" ;
}

function setFocus( field, msg )
{
	var value = $('#'+field).val();
	value = jQuery.trim(value);
	if( value == msg ){
		$('#'+field).val("");
	}else{
		$('#'+field).val(value);	
	}
}

function setValue( field, msg )
{
	var value = $('#'+field).val();
	value = jQuery.trim(value);
	if( value == "" ){
		$('#'+field).val(msg);
	}
}

function getCookie(c_name){
	if (document.cookie.length>0){
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
	}

	function checkLoginStatus(){
		var cusName = getCookie("cusName");
		var cusLoggedIn = getCookie("cusLoggedin");
		var	rememKey = getCookie("rememberKey");
		if(cusName == "" || cusName.length == 0 ){
			$("span#register").html('<a href="javascript:registrationForm()">Register</a>');
		}else{
			$("span#register").html("Welcome "+cusName.replace('"','').replace('"',''));
		}
		if((cusLoggedIn != "" && cusLoggedIn.length != 0) 
			||(rememKey != "" && rememKey.length  != 0)){
			$("span#login").html('<a href="/logoutCust.do?strAffiliateCode=00000080&strGroupId=TGU">Logout</a>');
		} else {
			$("span#login").html('<a href="javascript:loginForm()">Login</a>');
		}
	}
	
	function refreshLoginStatus(){
		var cusName = getCookie("cusName");		
		var cusLoggedIn = getCookie("cusLoggedin");
		if(cusLoggedIn != "" && cusLoggedIn.length != 0){
			$('span#register').html("Welcome "+cusName).fadeIn();
			$('span#login').html('<a href="/logoutCust.do?strAffiliateCode=00000080&strGroupId=TGU" class="tahoma-11">Logout</a>').fadeIn();
		}else{
			$('span#register').html('<a href="javascript:registrationForm()" class="tahoma-11">Register</a>').fadeIn();
			$('span#login').html('<a href="javascript:loginForm()" class="tahoma-11">Login</a>').fadeIn();
		}
	}

	function logout(){
		if(top.location.href.indexOf('BookingFinalGuestConsumer.do') != -1){
			$.get('/logoutCust.do?strAffiliateCode=00000080&strGroupId=TGU&redirect=success',function(data){
				refreshLoginStatus();
			});
		} else{
			window.location = '/logoutCust.do?strAffiliateCode=00000080&strGroupId=TGU';
		}
	}
