
function fnCheckVal(intObjId)
{
 var found_it ;
 for (var i=1; i<document.forms(0).length; i++)   
 { if(document.forms(0).elements[i].id )
  { if(document.forms(0).elements[i].id.indexOf("radUserAccount")!=-1) 
   {if (document.forms(0).elements[i].checked)
    {// Set the flag if any radio button is checked
       found_it = true;
       break;
     }}}} 
 if(!found_it)
 {alert("Select an Account");
  return false;
 }
 else 
 {return true;
  } 
}

function validateCreditCardNo(e,ccnumber,lblcardno)
{
	var doc = document.forms[0];
	if (ccnumber.value != "")
	{
		var s = ccnumber.value ;
		
		if (!checkCC(s))
		{
			lblcardno.style.display = "inline";
			e.returnValue = false;
		}else
		{
			lblcardno.style.display = "none";
		}
	}
	else
	{
		lblcardno.style.display = "none";
	}
}

function ShowHideNode(tbl, id)
{
	var imgPath = id.src.split('/');
	var imgPathLength = imgPath.length;
	var source = imgPath[imgPathLength-1];
	
	if(source == "tv_plus.gif")
	{
		id.src="Images/TreeView/tv_minus.gif";
		tbl.style.display = 'inline';
	}
	else if(source == "tv_minus.gif")
	{
		id.src="Images/TreeView/tv_plus.gif";
		tbl.style.display = 'none';
	}
	
	
}

function fnTrapKD(btn, event){
	if (document.all){
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById){
		if (event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if(document.layers){
		if(event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
}
				
function OpenWindowCenter(path, width, height)
{

	var screen_width = window.screen.width;

	var screen_height = window.screen.height;

		

	var left = screen_width/2 - width/2;	

	var top = screen_height/2 - height/2;


	return window.open(path,null,'toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width='+width+',height='+height+',left='+left+',top='+top);
}

function ValidateExpiryMonth(evt, month, year)
{
	var gd=new Date(), gToday=[gd.getFullYear(),gd.getMonth()+1,gd.getDate()];
	var currentMonth = gd.getMonth()+1;
	var currentYear = gd.getFullYear();
	//alert(currentMonth );
	if(currentYear == year.value && month.value < currentMonth )
	{
		trFutureExpiry.style.display = "inline";
		evt.returnValue = false;
	}
	else
		trFutureExpiry.style.display = "none";
}


// Statring javascript code for date validation 

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strYear=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strDay=dtStr.substring(pos2+1);
	
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
	
return true
}

function ValidateForm(fromdate,evt){
	var dt;
	
	if (evt!=null)
		dt = fromdate;
	else
		dt= document.getElementById(fromdate);//document.frmSample.txtDate
	
	if(dt.value!="")
	{
		if (isDate(dt.value)==false){
			dt.focus();
			evt.returnValue = false;
			return false;
		}
	}
    return true
 }

// Ending date validation code




function validate(e,ccnumber,lblcardno)
{
	var doc = document.forms[0];
	if (ccnumber.value == "")
	{
		//alert('Enter Credit Card Number');
		lblcardno.style.display = "inline";
		e.returnValue = false;
		
	}else
	{
		var s = ccnumber.value ;
		
		if (!checkCC(s))
		{
			lblcardno.style.display = "inline";
			e.returnValue = false;
		}else
		{
			lblcardno.style.display = "none";
		}
	}
}	

function confirmYesNo(evt)
{
	var isConfirm = confirm('do you really want to cancel this booking?');
	
	if(!isConfirm)
	{
		evt.returnValue = false;
	}
}

function validateAdults(e,ccholder,ccnumber,adult,adult312,adult02,lblcardno,lblccholder,maxpersons,lblMaxPersons,chkCreditCard,ccvarification)
{
	// this method used in admin side Edit Booking page.
	var adlt=0;
	var adlt312=0;
	var adlt02=0;
	
	if(!isNaN(parseInt(adult.value)))
	{
		adlt =parseInt(adult.value);
	}
	if(!isNaN(parseInt(adult312.value)))
	{
		adlt312 =parseInt(adult312.value);
		if (adlt312==0)
			adlt312.value='';
	}
	if(!isNaN(parseInt(adult02.value)))
	{
		adlt02 =parseInt(adult02.value);
		if (adlt02==0)
			adlt312.value='';
	}
	if((adlt + adlt312) > eval(maxpersons))//(adlt + adlt312 + adlt02)
	{
		lblMaxPersons.style.display = "inline";
		e.returnValue = false;
	}
	else
	{
		lblMaxPersons.style.display = "none";
	}
	if (chkCreditCard.checked == true)
	{
		if (ccnumber.value == "")
		{
			//alert('Enter Credit Card Number');
			lblcardno.style.display = "inline";
			e.returnValue = false;
			
		}else
		{
			var s = ccnumber.value ;
			
			if (!checkCC(s))
			{
				lblcardno.style.display = "inline";
				e.returnValue = false;
			}else
			{
				lblcardno.style.display = "none";
			}
		}
		
		if (ccholder.value == "")
		{
			//alert('Enter Credit Card Holder Name');
			lblccholder.style.display = "inline";
			e.returnValue = false;
			
		}else
		{
			lblccholder.style.display = "none";
		}
	
	}
	else
	{
		ccnumber.value = '';
		ccholder.value = '';
		ccvarification.value = '';
		lblcardno.style.display = "none";
		lblccholder.style.display = "none";
	}
}



function valCheckBox( fieldName, evt,row) { 
    
	
    if (fieldName.checked)
    {
		//alert('true');
	}
    else
    {
		//alert('false');
		row.style.display  = "inline";
		//alert( row.style.display );
		evt.returnValue = false;
    }
    //selection  = null; 
    //thisButton = document.forms[0][fieldName]; 
    
   /* for( var i=0; i<thisButton.length; i++ ) { 
        if( thisButton[i].checked ) { 
           selection = thisButton[i].value; 
        } 
        
        if (thisButton.checked == false)
        {
			alert( "Please read and accept the booking conditions before you continue." ); 
			evt.returnValue = false;	
        }
        else
        {
			document.location = 'PersonalInfo.aspx' ;
        }
    } 
    if( selection == null ) { 
        alert( "Please read and accept the booking conditions before you continue." ); 
        evt.returnValue = false;
    } */
} 

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=5) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		index_04_over = newImage("images/index_04-over.jpg");
		index_07_over = newImage("images/index_07-over.jpg");
		index_08_over = newImage("images/index_08-over.jpg");
		index_09_over = newImage("images/index_09-over.jpg");
		index_10_over = newImage("images/index_10-over.jpg");
		index_15_over = newImage("images/index_15-over.jpg");
		index_18_over = newImage("images/index_18-over.jpg");
		index_22_index_21_over = newImage("images/index_22-index_21_over.jpg");
		preloadFlag = true;
	}
}
function popUp(URL) {day = new Date();id = day.getTime();eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=799,height=600,left = 0,top = 0');");}

function openPopUp(url, width, height, scrollbar, toolbar, menubar, statusbar, resize) 
{
	if(document.all) {
		Left = (screen.availWidth - width) / 2;
		Top = (screen.availHeight - height) / 2;
	} else {
		Left = (self.outerWidth - width) / 2;
		Top = (self.outerHeight - height) / 2;
	}
	child = window.open(url, self.name + 'ROCAPP_571child', "toolbar=" + toolbar + ",location=0,directories=0,menubar=" + menubar + ",scrollbars=" + scrollbar + ",status=" + statusbar + ",resizable=" + resize + ",width=" + width + ",height=" + height + ",top=" + Top + ",left=" + Left);
}
function openBookedDayPopUp(url,ddlprop,ddltype,txtstart,txtend,e, width, height, scrollbar, toolbar, menubar, statusbar, resize) 
{
	var pid = document.getElementById(ddlprop).options[document.getElementById(ddlprop).selectedIndex].value;
	var type = document.getElementById(ddltype).options[document.getElementById(ddltype).selectedIndex].value;
	var start = document.getElementById(txtstart).value;
	var end = document.getElementById(txtend).value;
	
	if (start!='' && end != '' && start>end)
	{
		alert('Start Date cannot greater than End Date');
		e.returnValue = false;
		return false;
	}
	if(document.all) {
		Left = (screen.availWidth - width) / 2;
		Top = (screen.availHeight - height) / 2;
	} else {
		Left = (self.outerWidth - width) / 2;
		Top = (self.outerHeight - height) / 2;
	}
	
	url = url + '?pid='+pid+'&type='+type+'&sdate='+start+'&edate='+end;
	child = window.open(url, self.name + 'ROCAPP_571child', "toolbar=" + toolbar + ",location=0,directories=0,menubar=" + menubar + ",scrollbars=" + scrollbar + ",status=" + statusbar + ",resizable=" + resize + ",width=" + width + ",height=" + height + ",top=" + Top + ",left=" + Left);
}

function openAvailableDayPopUp(url,ddlprop,ddltype,txtstart,txtend,e, width, height, scrollbar, toolbar, menubar, statusbar, resize) 
{
	var pid = document.getElementById(ddlprop).options[document.getElementById(ddlprop).selectedIndex].value;
	var type = document.getElementById(ddltype).options[document.getElementById(ddltype).selectedIndex].value;
	var start = document.getElementById(txtstart).value;
	var end = document.getElementById(txtend).value;
	
	if (start!='' && end != '' && start>end)
	{
		alert('Start Date cannot greater than End Date');
		e.returnValue = false;
		return false;
	}
	if(document.all) {
		Left = (screen.availWidth - width) / 2;
		Top = (screen.availHeight - height) / 2;
	} else {
		Left = (self.outerWidth - width) / 2;
		Top = (self.outerHeight - height) / 2;
	}
	
	url = url + '?pid='+pid+'&type='+type+'&sdate='+start+'&edate='+end;
	//alert(url);
	child = window.open(url, self.name + 'ROCAPP_571child', "toolbar=" + toolbar + ",location=0,directories=0,menubar=" + menubar + ",scrollbars=" + scrollbar + ",status=" + statusbar + ",resizable=" + resize + ",width=" + width + ",height=" + height + ",top=" + Top + ",left=" + Left);
}


function checkCC(s) {

  var i, n, c, r, t;

  // First, reverse the string and remove any non-numeric characters.

  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }

  // Check for a bad string.

  if (r.length <= 1)
    return false;

  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.

  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }

  // Finally, add up all the single digits in this string.

  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }

  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.

  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}








