//-----------------------------------------------------------------------------------------------------//
//    Page Name 		: commonFunctions.js		
//    Page Description	: java script file for using common functions
//    Creation Date		: 04 Apr 2005
//    Creator			: Tavinder Singh
//    Modification Date	:	
//    Modifier			:		 
//-----------------------------------------------------------------------------------------------------//
function removeWhiteSpace(str)
{//NOT YET WORKING
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	var stmp="";
	var icount=0;
	for(icount=0; icount<s.length; icount++)
	{
		if (whitespace.indexOf(s.charAt(icount)) != -1)
		{
		// We have a string with leading blank(s)...
		var j=icount, i = s.length;

		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;

		// Get the substring from the first non-whitespace
		// character to the end of the string...
		stmp = stmp + s.substring(j, i);
		}
		else
		{
			stmp += s.substring(icount,1);
		}
	}
   return s;
}

function Replace(str,strOld,strNew)
{//NOT YET WORKING
	var whitespace = new String(strOld);
	var s = new String(str);
	var stmp="";
	var icount=0;
	for(icount=0; icount<s.length; icount++)
	{
		if (whitespace.indexOf(s.charAt(icount)) != -1)
		{
		// We have a string with leading blank(s)...
		var j=icount, i = s.length;

		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;

		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = stmp + strNew + s.substring(j, i);
		}
		else
		{
			stmp += s.substring(icount,1);
		}
	}
   return s;
}

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

//===================added by IRABANTA on 19-dec-2005
function ValidateINdates(txtInDate,txtNoOfNights,txtOutDate)
{
	//-----------for serviceSearchType
	if(txtNoOfNights==null)
	{
		if(txtInDate.value=="") return;
		if(isValidDateOnly_ddmmyyyy(txtInDate.value)==false) 
		{
			txtInDate.focus();
			return false;
		}
		return true;
	}
	//--------------for accom search type
	if(txtInDate.value.length>0)
	{
		if(isValidDateOnly_ddmmyyyy(txtInDate.value)==false) 
		{
			txtNoOfNights.value='';
			txtOutDate.value='';
			txtInDate.focus();
			return false;
		}
	}
	else
	{
		txtNoOfNights.value='';
		txtOutDate.value='';
	}
	txtNoOfNights.focus();
	return true;
}
function ValidateOUTdates(txtOUTDate,txtNoOfNights,txtInDate)
{
	//alert(txtInDate.value.length);
	if(txtOUTDate.value.length>0)
	{
		if(isValidDateOnly_ddmmyyyy(txtOUTDate.value)==false)
		{
			txtOUTDate.focus();
			return false;
		}
		else
		{
			calcNoOfNights_Common(txtOUTDate,txtNoOfNights,txtInDate);
		}
	}
}
function calcNoOfNights_Common(txtOUTDate,txtNoOfNights,txtInDate)
{
	startDate=txtInDate.value.split("/")
	startDateDay = startDate[0];
	startDateMon = startDate[1];
	startDateYear = startDate[2];
	startDateFinal=new Date(startDateMon + "/" + startDateDay  + "/" + startDateYear)
	
	endDate=txtOUTDate.value.split("/");
	endDateDay = endDate[0];
	endDateMon = endDate[1];
	endDateYear = endDate[2];
	endDateFinal=new Date(endDateMon + "/" + endDateDay + "/" + endDateYear)
	txtNoOfNights.value=  Math.ceil((( endDateFinal - startDateFinal ) / (  24 * 60 * 60 * 1000 )));
}
//====================end add by IRABANTA

//============================added by Ashish=============
function isValidDate(dateValue,i)
 {
	var dateStr = dateValue;
	//alert(dateStr)
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null)
		 {
			 alert("Date is not in a valid format.")
			 return false;
		 }
	if (i=='1') //dd/mm/yyy
	{
		
		month = matchArray[3]; // parse date into variables
		day = matchArray[1];	
	}
	else
	{
		month = matchArray[1]; // parse date into variables
		alert(month);		
		day = matchArray[3];
	}
	year = matchArray[4];

	var monthname
	switch (month) 
	{
	case "02" :	{
				monthname="February";
				break;
				}
				
	case "04" :	{
				monthname="April";
				break;					
				}
	
	case "06" :	{
				monthname="June";
				break;	
				}
	
	case "09" :	{
				monthname="September";
				break;	
				}
				
	case "11":	{
				monthname="November";
				break;							
				}
	}
	
	if (month < 1 || month > 12)
        
	 { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	 }
	if (day < 1 || day > 31) 
	 {
		alert("Day must be between 1 and 31.");
		return false;
	 }
	
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month " + monthname +" doesn't have 31 days!")
		return false
	}
	if(month == 2 )
	{
		var leap ;
		leap = year % 4 
		if ( leap == 0 && day > 29 ) 
		{
		alert("Month " + monthname +" doesn't have more than 29 days!");
			return(false) ;	
		}
		else if ( leap != 0 && day > 28 )
		{
		alert("Month " + monthname +" doesn't have more than 28 days!");
			return(false) ;	
		}	
			  
	}
    return(true)
  }
  
  //format is mm/dd/yyyy
 function isValidDateOnly(dateValue)
 {
	var dateStr = dateValue;
	//alert(dateStr)
	var datePat = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null)
		 {
			 alert("Date is not in a valid format. Valid format is dd/mm/yyyy")
			 return false;
		 }

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];

	var monthname
	switch (month) 
	{
	case "02" :	{
				monthname="February";
				break;
				}
				
	case "04" :	{
				monthname="April";
				break;					
				}
	
	case "06" :	{
				monthname="June";
				break;	
				}
	
	case "09" :	{
				monthname="September";
				break;	
				}
				
	case "11":	{
				monthname="November";
				break;							
				}
	}
	
	if (month < 1 || month > 12)
        
	 { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	 }
	if (day < 1 || day > 31) 
	 {
		alert("Day must be between 1 and 31.");
		return false;
	 }
	
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month " + monthname +" doesn't have 31 days!")
		return false
	}
	if(month == 2 )
	{
		var leap ;
		leap = year % 4 
		if ( leap == 0 && day > 29 ) 
		{
		alert("Month " + monthname +" doesn't have more than 29 days!");
			return(false) ;	
		}
		else if ( leap != 0 && day > 28 )
		{
		alert("Month " + monthname +" doesn't have more than 28 days!");
			return(false) ;	
		}	
			  
	}
    return(true)
  }
  //===================end add by ashish=================================
  
  //===================start Addition by Irabanta===================
  function ValidateDate(txt)
  {
	var sdate=txt.value;
	if(sdate.length==0) return;
	if(isValidDateOnly_ddmmyyyy(sdate)==false)
	{
		txt.focus();
	}
  }
  
  //format is dd/mm/yyyy
 function isValidDateOnly_ddmmyyyy(dateValue)
 {
	var dateStr = dateValue;
	//alert(dateStr)
	//var datePat = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{2}|\d{4})$/;
	var datePat = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null)
		 {
			 alert("Date is not in a valid format. Valid format is dd/mm/yyyy")
			 return false;
		 }

	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];

	var monthname
	switch (month) 
	{
	case "02" :	{
				monthname="February";
				break;
				}
				
	case "04" :	{
				monthname="April";
				break;					
				}
	
	case "06" :	{
				monthname="June";
				break;	
				}
	
	case "09" :	{
				monthname="September";
				break;	
				}
				
	case "11":	{
				monthname="November";
				break;							
				}
	}
	
	if (month < 1 || month > 12)
        
	 { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	 }
	if (day < 1 || day > 31) 
	 {
		alert("Day must be between 1 and 31.");
		return false;
	 }
	
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month " + monthname +" doesn't have 31 days!")
		return false
	}
	if(month == 2 )
	{
		var leap ;
		leap = year % 4 
		if ( leap == 0 && day > 29 ) 
		{
		alert("Month " + monthname +" doesn't have more than 29 days!");
			return(false) ;	
		}
		else if ( leap != 0 && day > 28 )
		{
		alert("Month " + monthname +" doesn't have more than 28 days!");
			return(false) ;	
		}	
			  
	}
    return(true)
  }

function openPopupWindow(paraURL)
	{
	//alert(paraURL)
	window.open(paraURL,'ab','resizable=yes,menubar=no,scrollbars=yes,left=0,top=0,width=700,height=400');
	}
  //===================end addition by irabanta======================
 function Message()
	{//added by Mintu
		alert('Sorry Unavailable Online,Please call 1300-362-844 to book');
}
function ShowHotelClose()
{
	alert('Hotel is Closed');
}
function ShowServiceNotAvailable(paraDayName)
{
	alert("Service is not available on Selected Date : "+paraDayName);
}

function InvisibleAnimation()
{
	document.all('divProcessing').style.display='none';
}
function VisibleAnimation()
{
	document.all('divProcessing').style.display='block';
}
function validate()
{//used from flight search
	//================
	//document.all('UcSearch1_Panel1').style.display='none';
	VisibleAnimation();
	//================
}

//pass id of div as parameter
function CallPrint(strid, strCssPath)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
 WinPrint.document.write("<LINK href='" + strCssPath + "' type='text/css' rel='stylesheet'>");
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 //prtContent.innerHTML=strOldOne;
}

function refreshParentPage()
{
	if(window.opener==null) return;
	var theForm = window.opener.document.forms['frmDefault'];	
	window.opener.document.all('hidAllowRefresh').value="Y";
	theForm.action
	theForm.submit();
	window.close();
}
