
/*  ######################################################################
	----------------------------------------------------------------------
								Function
    ----------------------------------------------------------------------
		display_submenu  'This funtion dynamically display sub menu'
		
	#######################################################################								
*/
function display_submenu(div_name, disp_flag)
	{
		for(i=1; i<=4; i++)
		{
			var id = "div"+i;
			
			if((disp_flag == 1) && (id == div_name))
			{
				//alert(disp_flag+id);
				document.getElementById(id).style.display = "none";
				document.getElementById(div_name).style.display = "";
			}
			else if((disp_flag ==  0) && (id == div_name))
			{
				//alert(disp_flag+id);
				document.getElementById(div_name).style.display = "none";
			}
			else if((disp_flag ==  2) && (id == div_name))
			{
				//alert(disp_flag+id);
				
				if(document.getElementById(div_name).style.display == "none")
				{
					document.getElementById(div_name).style.display = "";
				}
				else if(document.getElementById(div_name).style.display == "")
				{
					document.getElementById(div_name).style.display = "none";
				}
			}
			else if((disp_flag ==  2) && (id != div_name))
			{
				document.getElementById(id).style.display = "none";
			}
		}
	}



/*##################################################################################			
					LIST OF FUNCTIONS IN General.Js

	NOTE:	All the functin names follow java naming conventions

	----------------------------------------------------------------
					Validation Functions
	----------------------------------------------------------------
	1.  checkNumber(objTextBox, strField, AllowBlank)
	2.  validEmail(strEmailAddress)
	3. isAlphaNumeric(strText)

	----------------------------------------------------------------
					General Purpose functions
	----------------------------------------------------------------
	1. isChecked(objCheckBox)			'Check whether any check box is checked
	2. checkAll(objCheckBox, blnCheck)	'Check or Uncheck all check boxes
	
	1. trim(strTemp)
	2. trimAll()						'Function trims all the Textboxes and TextAreas on the Form
	3. lTrim(strTemp)
	4. rTrim(strTemp)
	5. trimTb(objTb)					'Trims the text box object
	
	6. replaceDoubleQuotes()			'replaces double quotes (") with 2 Single quotes ('') in all the text boxes and Text Areas
	7. replaceSingleQuotes()			'replaces 2 Single quotes ('') with One double quote (") in all the text boxes and Text Areas
	
	8. UrlEncode(srtUrl)				'returns the string with all space characters by '%20'
	9. getLeftPos(objElement)			'returns the absolute Left position of element
   10. getTopPos(objElement)			'returns the absolute Top position of element
   11. CalShowComboBoxes(name, Show)	'Hides all comboboxes under the area of given element
   
   ----------------------------------------------------------------
				Hint
   ----------------------------------------------------------------
	1. Call following function in onLoad event of BODY
		- replaceSingleQuotes()
   
	2. Call following Two functions before you Validate data in Save() function
		- trimAll()
		- replaceDoubleQuotes()
##################################################################################*/

/******************************************************************************************************************
					Validation Functions
******************************************************************************************************************/
/*-----------------------------------------------------------------------------------------------------------------
 Function:			checkNumber(objTextBox, strField, AllowBlank)
 Description:		Returns false, Gives message and Sets focus to text box if entered 
					text is not a number. Otherwise returns true.
 Arguments:
	objTextBox	->	Textbox object whose text is to be checked for number
	strField	->	The field description.
	AllowBlank	->  VALUE				DESCRIPTION
					----------------------------------
					false				Returns false if nothing is entered in text box
										or invalid number is typed
					true				Returns true if nothing is entered in text box
										Returns false if invalid number is typed
-----------------------------------------------------------------------------------------------------------------*/
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   var str = sText.value;
   for (i = 0; i < str.length && IsNumber == true; i++) 
   { 
      Char = str.charAt(i); 
	  //alert(Char);
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}
function isNumberKey(evt,enabledot)
{
	if(!enabledot) enabledot=0;
 var charCode = (evt.which) ? evt.which : event.keyCode
	//alert(charCode)
 if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46 && enabledot==1)
	return false;
 else if (charCode > 31 && (charCode < 48 || charCode > 57) && enabledot==0)
	return false;

 return true;
}

function IsInt(sText)
{
   var ValidChars = "0123456789";
   var IsInt=true;
   var Char;
   var sText = sText.value;
   for (i = 0; i < sText.length && IsInt == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsInt = false;
      }
   }
   return IsInt;
}
function IsString(sText)
{
   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   var IsStr=true;
   var Char;
   var str = sText.value;
   for (i = 0; i < str.length && IsStr == true; i++) 
   { 
      Char = str.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
	     IsStr = false;
      }
   }
   return IsStr;
}

function checkNumber(objTextBox, strField, AllowBlank)
{
	
	//objTextBox: Text Box whose value is to be checked
	//strField :  Pass Field Name for appropriate message
	var x=objTextBox.value;

	var anum=/(^\d+$)|(^\d+\.\d+$)/;
	
	if(arguments.length == 1)
	{
		strField = "";
	}
	
	if(arguments.length == 2)
	{
		AllowBlank=false;
	}
	
	if (x=="" && AllowBlank==true) 
	{
		return (true);
	}

	if (anum.test(x))
	{
		testresult=true;
	}
	else
	{
		var strMsg;
		
		if(strField=="")
		{
			strMsg="Please input a valid number!";
		}
		else
		{
			strMsg="Please input a valid number in " + strField + "!";
		}
		
		alert(strMsg);
		objTextBox.focus();
		testresult=false;
	}

	return (testresult);
}

/*-----------------------------------------------------------------------------------------------------------------
	Description: Returns true if the given address is valid email address otherwise returns false
-----------------------------------------------------------------------------------------------------------------*/
function validEmail(strEmail)
{	//var strExpression = /^[a-z][a-z_0-9\.]+@[a-z_0-9\.]+$/i;
	
	//return strExpression.test(strEmail);
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;

}

/*-----------------------------------------------------------------------------------------------------------------
	Description: Returns true if the given string is Alphanumeric.
		     String must be started with Alphabet and optionally follwed by
		     numbers or Underscore
-----------------------------------------------------------------------------------------------------------------*/
function isAlphaNumeric(strText) 
{ 
   var strExpression = /^[a-z][a-z_0-9]{0,}$/i; 
   return strExpression.test(strText); 
}

/******************************************************************************************************************
			General purpose functions
******************************************************************************************************************/
/*-----------------------------------------------------------------------------------------------------------------
	Function:		isChecked(objCheckBox)
	Description:	returns true if check box OR any of check box 
			from the array of check box is checked.
			Otherwise returns false
-----------------------------------------------------------------------------------------------------------------*/
function isChecked(objCheckBox)
{
	var iIndex;
	//If checkbox object does not exist
	if(typeof(objCheckBox) != 'object')
	{
		return false;
	}
	
	//If there is only one checkbox
	if(typeof(objCheckBox[0]) != 'object')
	{
		return objCheckBox.checked;
	}
	else
	{
		var iChecked=0;
		
		for(iIndex=0; iIndex<objCheckBox.length; iIndex++)
		{
			if(objCheckBox[iIndex].checked == true)
			{
				return true;
			}
		}
		
		return false;		
	}
}

/*-----------------------------------------------------------------------------------------------------------------
	Function:		checkAll(objCheckBox, blnCheck)
	Description:	Checks the check box OR all the checkboxes in array of checkboxes
			if blnCheck is true.
			
			Unchecks the check box OR all the checkboxes in array of checkboxes
			if blnCheck is false.
-----------------------------------------------------------------------------------------------------------------*/
function checkAll(objCheckBox, blnCheck)
{
	var iIndex;
	
	//If checkbox object does not exist
	if(typeof(objCheckBox) != 'object')
	{
		return false;
	}
	
	//If there is only one checkbox
	if(typeof(objCheckBox[0]) != 'object')
	{
		objCheckBox.checked = blnCheck;
	}
	else
	{
		var iChecked=0;
		
		for(iIndex=0; iIndex<objCheckBox.length; iIndex++)
		{
			objCheckBox[iIndex].checked = blnCheck;
		}
	}
}

/******************************************************************************************************************
						Trim Functions
******************************************************************************************************************/
function trim(strTemp)
{
	strTemp = lTrim(strTemp);
	strTemp = rTrim(strTemp);
	return strTemp;
}

function trimAll()
{
	var i;

	//Check for all input elements
	for(i=0; i<document.all.tags("INPUT").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTB  = document.all.tags("INPUT")(i);
		//If it is text box, then replace double quotes with 2 single quotes
		if(objTB.type == "text")
		{
			objTB.value = trim(objTB.value);
		}
	}

	//Check for all input elements
	for(i=0; i<document.all.tags("TEXTAREA").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTA  = document.all.tags("TEXTAREA")(i);
		
		objTA.value = trim(objTA.value);
	}
}

function lTrim(strTemp)
{
  var iIndex;
  var charTemp;

	for(iIndex=0; iIndex< strTemp.length;iIndex++)
	{
		charTemp = strTemp.substring(iIndex, iIndex+1);
		if(charTemp != ' ') break;
	}

	strTemp = strTemp.substring(iIndex, strTemp.length);
	return strTemp;
}

function rTrim(strTemp)
{
  var iIndex;
  var charTemp;

	for(iIndex=strTemp.length; iIndex>0;iIndex--)
	{
		charTemp = strTemp.substring(iIndex-1, iIndex);
		if(charTemp != ' ') break;
	}

	strTemp = strTemp.substring(0,iIndex);
	return strTemp;
}

function trimTb(objTb)
{
	objTb.value = Trim(objTb.value);
}


/******************************************************************************************************************
						Replace quote functions
******************************************************************************************************************/
/*-----------------------------------------------------------------------------------------------------------------
	function:		replaceDoubleQuotes()
	Description:	Replace  double quotes (") with 2 single quotes ('')
		Call this replaceDoubleQuotes() function before you submit the form.
		This function replaces Double quotes with 2 single quotes
		in all the text boxes and text areas 
-----------------------------------------------------------------------------------------------------------------*/

function replaceDoubleQuotes()
{
	var i;

	//Check for all input elements
	for(i=0; i<document.all.tags("INPUT").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTB  = document.all.tags("INPUT")(i);
		//If it is text box, then replace double quotes with 2 single quotes
		if(objTB.type == "text")
		{
			replaceDouble(objTB)
		}
	}

	//Check for all input elements
	for(i=0; i<document.all.tags("TEXTAREA").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTA  = document.all.tags("TEXTAREA")(i);
		replaceDouble(objTA)
	}
}					


//2. To replace the double quotes by " '' "
function replaceDouble(txtObj)
{

//Pass the text box object as argument to this function

 var strTmp1 = new String();
	
 strTmp1 = txtObj.value;
 //'RegExp
 txtObj.value = strTmp1.replace(/"/g,"''");
 return true;
}

/*-----------------------------------------------------------------------------------------------------------------
	function:		replaceSingleQuotes()
	Description:	Replace 2 single quotes ('') with double quotes (") 
		in all the text boxes. Call this replaceSingleQuotes() function in onLoad
		event of BODY.
-----------------------------------------------------------------------------------------------------------------*/
function replaceSingleQuotes()
{
	var i;
	//Check for all input elements
	for(i=0; i<document.all.tags("INPUT").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTB  = document.all.tags("INPUT")(i);
		//If it is text box, then replace double quotes with 2 single quotes
		if(objTB.type == "text")
		{
			replaceSingle(objTB)
		}
	}

	//Check for all input elements
	for(i=0; i<document.all.tags("TEXTAREA").length;i++)
	{
		//Get object of INPUT ELEMENT
		objTA  = document.all.tags("TEXTAREA")(i);
		replaceSingle(objTA)
	}
}					


//2. To replace the two single quotes by one double quote (")
function replaceSingle(txtObj)
{

//Pass the text box object as argument to this function

 var strTmp1 = new String();
	
 strTmp1 = txtObj.value;
 //'RegExp
 txtObj.value = strTmp1.replace(/''/g,"\"");
 return true;
}

/*-----------------------------------------------------------------------------------------------------------------
	Function:		UrlEncode(srtUrl)
	Description:	Returns the string with all space characteres replaced by '%20'
-----------------------------------------------------------------------------------------------------------------*/
function UrlEncode(strUrl)
{
	var re;
	
//	re = / /i;
//	strUrl = strUrl.replace(re,"%20");

	re = /&/i;
	strUrl = strUrl.replace(re,"%26");
	
	return strUrl;
}

/******************************************************************************************************************
						POSITIONING functions
******************************************************************************************************************/
function getLeftPos(objElement)
{
	var i;
	var objParent;
	var iLeft=0;
					
	if(typeof(objElement) != 'object')
	{
		alert("Invalid Object.");
		return 0;
	}
	
	//Find the element's offsetLeft relative to the BODY tag.
	
	iLeft = objElement.offsetLeft;
	objParent = objElement.offsetParent;

	while (objParent.tagName.toUpperCase() != "BODY")
	{
		iLeft += objParent.offsetLeft;
		objParent = objParent.offsetParent;
	}
	
	return iLeft;	
}

function getTopPos(objElement)
{
	var i;
	var objParent;
	var iTop=0;
					
	if(typeof(objElement) != 'object')
	{
		alert("Invalid Object.");
		return 0;
	}
	
	//Find the element's offsetLeft relative to the BODY tag.

	iTop = objElement.offsetTop;
	objParent = objElement.offsetParent;

	while (objParent.tagName.toUpperCase() != "BODY")
	{
		iTop += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}

	return iTop;	
}

function CalShowComboBoxes(name, Show)
{	
	var i;
	if(name!=null)
	{
		//If want to hide the comoboxes
		if(Show == false)
		{
			var objParent;
			var objSel, selLeft, selTop, selRight;
			var nameLeft, nameTop, nameHeight, nameWidth;
				
			//Get Left, Top, Height and Width of an object
			nameLeft   = name.offsetLeft;
			nameTop	   = name.offsetTop;
			nameHeight = name.offsetHeight;
			nameWidth  = name.offsetWidth;

			for(i=0; i<document.all.tags("SELECT").length;i++)
			{
				objSel  = document.all.tags("SELECT")(i);
				if (! objSel || ! objSel.offsetParent) 
					continue;

				//Find the element's offsetTop and offsetLeft relative to the BODY tag.
				selLeft   = objSel.offsetLeft;
				selTop    = objSel.offsetTop;
				objParent = objSel.offsetParent;
				while (objParent.tagName.toUpperCase() != "BODY")
				{
					selLeft  += objParent.offsetLeft;
					selTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}
				selRight=selLeft+objSel.offsetWidth;
					
				//If Combobox's Top is covered by the element
				if( selTop<(nameTop + nameHeight) )
				{
					//If Combobox's left is covered by Dropdown menu
					//OR Combobox's right is covered by Dropdown menu
					if( (selLeft>nameLeft  && selLeft<(nameLeft+nameWidth))
					    ||
					    (selRight>nameLeft && selRight<(nameLeft+nameWidth))
					  )
					{
						objSel.style.visibility="hidden";
					}  
				}
			}

			for(i=0; i<document.all.tags("OBJECT").length;i++)
			{
				objSel  = document.all.tags("OBJECT")(i);
				if (! objSel || ! objSel.offsetParent) 
					continue;

				//Find the element's offsetTop and offsetLeft relative to the BODY tag.
				selLeft   = objSel.offsetLeft;
				selTop    = objSel.offsetTop;
				objParent = objSel.offsetParent;
				while (objParent.tagName.toUpperCase() != "BODY")
				{
					selLeft  += objParent.offsetLeft;
					selTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}
				selRight=selLeft+objSel.offsetWidth;
					
				//If Combobox's Top is covered by Dropdown menu
				if( selTop<(nameTop + nameHeight) )
				{
					//If Combobox's left is covered by Dropdown menu
					//OR Combobox's right is covered by Dropdown menu
					if( (selLeft>nameLeft  && selLeft<(nameLeft+nameWidth))
					    ||
					    (selRight>nameLeft && selRight<(nameLeft+nameWidth))
					  )
					{
						objSel.style.visibility="hidden";
					}  
				}
			}
		}
		else
		{
			for(i=0; i<document.all.tags("SELECT").length;i++)
			{
				document.all.tags("SELECT")(i).style.visibility="visible";
			}

			for(i=0; i<document.all.tags("OBJECT").length;i++)
			{
				document.all.tags("OBJECT")(i).style.visibility="visible";
			}
		}
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////
function IsSpecialchar(sFieldValue){
var str='`~!@#$%^&*()_+={}[]:;<>\\,?/|""*'+ "'" ;
var checkStr = sFieldValue;
var i,j,ch,flag=0;
//alert(checkStr);
	for (i = 0; i < checkStr.length; i++){
		ch = checkStr.charAt(i);
			for (j = 0; j < str.length; j++){
				if (ch == str.charAt(j)){
					flag=1;
					break;
				}	
			}
	 }
return flag;  	
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}
	
// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}


//-------------------------------------------------------------------------------------------------------

function LuhnCheck(str){
  var result = true;

  var sum = 0; 
  var mul = 1; 
  var strLen = str.length;
  
  for (i = 0; i < strLen; i++){
    var digit = str.substring(strLen-i-1,strLen-i);
    var tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) != 0)
    result = false;
    
  return result;
}


function validateCCNumber(cardNum){
	var result = false;
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first2digs = cardNum.substring(0,2);
	var first3digs = cardNum.substring(0,3);
	var first4digs = cardNum.substring(0,4);
	var first5digs = cardNum.substring(0,5);
	var first6digs = cardNum.substring(0,6);
	
	//cascade validation
	//source: http://en.wikipedia.org/wiki/Credit_card_number
	for(i=0; i<11; i++){
		switch(i){
			case 0: //American Express 34 and 37 15 
				result = (cardLen == 15) && ((first2digs == "34") || (first2digs == "37"));
				break;
			case 1: //Bankcard 560–561 16 
				result = (cardLen == 16) && ((first3digs == "560") || (first3digs == "561"));
				break;
			case 2: //Diners Club International[1] 36 15 
				result = (cardLen == 15) && (first2digs == "36");
				break;
			case 3: //Diners Club US & Canada[1] 55 16 
				result = (cardLen == 16) && (first2digs == "55");
				break;
			
			//As of October 1st, 2005, Discover Bank will include a new BIN in the range of 650000–650999.
			case 4: //Discover Card 6011 and 650* 16 
				result = (cardLen == 16) && ((first3digs == "650") || (first4digs == "6011"));
				break;
			case 5: //JCB 3 16 
				result = (cardLen == 16) && (firstdig == "3");
				break;
			case 6: //JCB 1800 and 2131 15 
				result = (cardLen == 15) && ((first4digs == "1800") || (first4digs == "2131"));
				break;
				
			//As of November 8, 2004, MasterCard purchased the domestic (US) Diner's Club BIN range.
			//Diner's club international's website makes no reference to old 38 prefix numbers,
			//and they can be presumed reissued under the 55 or 36 BIN prefix
			case 7: //MasterCard* 51–55, 36 14 or 16 
				result = ((cardLen == 14) || (cardLen == 16)) && ((first2digs == "36") || (first2digs == "51") || (first2digs == "52") || (first2digs == "53") || (first2digs == "54") || (first2digs == "55") || (first2digs == "56") || (first2digs == "57")||(first2digs == "58") || (first2digs == "38"));
				break;
			case 8: //Visa 4 13 or 16 	
				result = ((cardLen == 13) || (cardLen == 16)) && (firstdig == "4");
				break;
			case 9: //Solo (debit card)
				result = ((cardLen == 16) || (cardLen == 18) || (cardLen == 19)) && (first4digs == "6334" || first4digs == "6767");
				break;
			case 10: //Switch (debit card)
				result = ((cardLen == 16) || (cardLen == 18) || (cardLen == 19)) && (first4digs == "4903" || first4digs == "4905" || first4digs == "4911" || first4digs == "4936" || first4digs == "6333" || first4digs == "6759" || first6digs == "564182" || first6digs == "633110");
				break;
		}
		if(result) return true;
	}
	return false;
}

function validateExpDate(expDate){
	//valid are  mmyy, mm/yy, mm20yy, mm/20yy
	var rex = /^(([0]\d{1})|([1]([012])))(\/?)(([2][0])?)(\d{2})$/;
	return rex.test(expDate);
}

function validateExpMonth(expDate){
	//valid are  01-12
	var rex = /^(([0]?\d{1})|([1]([012])))$/;
	return rex.test(expDate);
}

function validateExpYear(expDate){
	//valid are  mmyy, mm/yy, mm20yy, mm/20yy
	var rex = /^(([2][0])?)(\d{2})$/;
	return rex.test(expDate);
}

function validateCVC2(cvc2){
	//valid are ddd or dddd
	var rex = /^(\d{3,4})$/;
	return cvc2==""?true:rex.test(cvc2);
}

function validateName(name){
	var rex = /^[a-zA-Z \-\']+$/;
	return rex.test(name);
}




//----------------------------
function viewPhotoGallery(RentalId)
{
	var url="index.php?view=viewgallary&id="+RentalId;
	var win=window.open(url,"PhotoGallary","width=530,height=510,menubar=0,resizable=0,status=no,menubar=0,resizable=0,scrollbars =1");
}

function TellAFriend(RentalId)
{
	if(arguments.length==2)
		var2=arguments[1];
	else
		var2='';
	var url='index.php?view=tellafriend&id='+RentalId+"&from="+var2;
	MM_openBrWindow(url,'TellAFreind','scrollbars=yes,width=700,height=400');
}


function ContactOwner(RentalId)
{
	MM_openBrWindow('index.php?view=contactowner&id='+RentalId,'ContactOwnerWin','scrollbars=yes,width=750,height=600');
}

function ShowAvailibilityCalendar(RentalId)
{
	MM_openBrWindow('index.php?view=CalendarView&rental_id='+RentalId,'CalanderView','scrollbars=yes,width=400,height=300');
}

function ShowAvailibilityFullCalendar(RentalId,Year)
{
	MM_openBrWindow('index.php?view=CalendarView&foryear='+Year+'&rental_id='+RentalId,'FullCalanderView','scrollbars=yes,width=700,height=600');
}

function ViewMap(city,state,country,address,zip)
{
	// http://www.mapquest.com/maps/map.adp?country=US&address=&city=Panama+City+Beach&state=FL&zipcode=32401&zoom=5&dtype=s&cid=lfmaplink
//	http://maps.google.com/maps?f=q&source=s_q&hl=en&q=Florida+Ave,+Chambersburg,+Franklin,+Pennsylvania+17201
//	MapAddress="country="+country+"&address="+address+"&city="+city+"&state="+state+"&zipcode="+zip;
//	MM_openBrWindow('http://www.mapquest.com/maps/map.adp?'+MapAddress+'&zoom=5&dtype=s','ViewMap','scrollbars=yes,width=750,height=600');	


	MapAddress=address+","+city+","+state+","+country;
	MM_openBrWindow('http://maps.google.com/maps?f=q&source=s_q&hl=en&q='+MapAddress,'ViewMapGoogle','scrollbars=yes,width=750,height=600');
	
}

function ViewYahooMap(YApi,xmlUrl)
{
	var Url="http://api.maps.yahoo.com/Maps/V1/annotatedMaps?appid="+YApi+"&xmlsrc=" + xmlUrl;
	MM_openBrWindow(Url,'ViewMapYahoo','scrollbars=yes,width=750,height=600');
}

function GetWeather(MapAddress)
{
	//http://www.weather.com/weather/local/32401
	MM_openBrWindow('http://www.weather.com/weather/local/'+MapAddress,'GetWeather','scrollbars=yes,width=750,height=600');
}

function ViewFeedback(RentalId)
{
	MM_openBrWindow('index.php?view=viewfeedback&id='+RentalId,'ViewFeedback','scrollbars=yes,width=750,height=600');
}

function LeaveFeedback(RentalId)
{
	MM_openBrWindow('index.php?view=leaveFeedback&id='+RentalId,'LeaveFeedback','scrollbars=yes,width=750,height=600');
}

function ChangeCalenderMonth(rental_id,pageV,nextyear,nextmonth)
{
	retrieveURL("index.php?view="+pageV+"&tag=Listing_Feature&rental_id="+rental_id+"&year="+nextyear+"&mon="+nextmonth, 'frmForm');
}

//related to breadcrums
function BackStep(ID)
{
	if(ID==1)
	{
		document.frmForm.lstState.value="";
		document.frmForm.lstRegion.value="";
		document.frmForm.action="index.php?view=country_view";
	}
	else if(ID==2)
	{
		document.frmForm.lstRegion.value="";
		document.frmForm.action="index.php?view=state_view";
	}
	else if(ID==3)
	{
		document.frmForm.action="index.php?view=region_view";
	}
	
	document.frmForm.submit();
	
}


function CheckValidUrl(strUrl)
{

        var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/

        return RegexUrl.test(strUrl);

}

function ValidatePhone(strPhone)
{
	var strExpression = /^[0-9]{3}-[0-9]{3}-[0-9]{4}(-[0-9]{1,})?$/i;
	var strExpression1 = /^[0-9]{3}[0-9]{3}[0-9]{4}[0-9]{0,}$/i; 
	
	var kk= strExpression.test(strPhone); 
	var kk1= strExpression1.test(strPhone);
	
	if(!kk && !kk1)
	{
		return false;	
	}
	else
		return true;
}

function ViewVideo(VideoId)
{
	MM_openBrWindow('index.php?view=Display_Rental_Video&VideoId='+VideoId,'ViewMyVideo','scrollbars=yes,width=450,height=470');
}


function PopupPage(pageUrl, pageWidth, pageHeight,windowName,is_scroll)
{
	//Code to display in the center goes here
	var left = (screen.width - pageWidth)/2;
	var top = (screen.height - pageHeight)/2;
	if (isNaN(left))
	left = 0;
	if (isNaN(top))
	top = 0;
	if (null == windowName )
	windowName = "_blank";
	if(null == is_scroll)
	is_scroll = "no";
	var newPopup = window.open(pageUrl, windowName , "dependent=yes, directories=no, location=no, menubar=no, personalbar=no, resizable=no, scrollbars="+is_scroll+", status=yes, toolbar=no, height=" + pageHeight + ", width=" + pageWidth + ", left=" + left + ", top=" + top + ", dialog=yes");
	return newPopup;
} 
