/* Optimized Javascript code from homepage.js starts here */
function TabHolidayByTheme(frmName) {
	if(document.forms[""+frmName].radioButtonSel[0].checked)
	{
	   document.getElementById('domestictab').style.display = '';
	   document.getElementById('internationaltab').style.display= 'none' ;
	   document.getElementById('domesticCont').style.display = '';
	   document.getElementById('internationalCont').style.display= 'none' ;
	   document.forms[""+frmName].radioButtonSel[0].checked=true;
	   document.forms[""+frmName].radioButtonSel[1].checked=false;
	  
 
	}
	if(document.forms[""+frmName].radioButtonSel[1].checked)
	{
	   document.getElementById('domestictab').style.display = 'none';
	   document.getElementById('internationaltab').style.display= '' ;
	    document.getElementById('domesticCont').style.display = 'none';
	   document.getElementById('internationalCont').style.display= '' ;
	   document.forms[""+frmName].radioButtonSel[1].checked=true;
	   document.forms[""+frmName].radioButtonSel[0].checked=false;
 	}

}

/* functionality for Holiday By Theme Domestic Panel Start here */
function HolidayThemeDOM(divName,tabdiv)
{
for(i=0; i<=3; i++)
	{
		document.getElementById('holidaythemeDOM'+i).style.display='none';
		document.getElementById(divName).style.display='';
		document.getElementById('hthemeDOMtab'+i).className='themeholidaymenuoff';
		document.getElementById(tabdiv).className='themeholidaymenuon';
	}
		
}
/* functionality for Holiday By Theme Domestic Panel End here */

/* functionality for Holiday By Theme International Panel Start here */
function HolidayThemeINT(divName,tabdiv)
{
for(i=0; i<=3; i++)
	{
		document.getElementById('holidaythemeINT'+i).style.display='none';
		document.getElementById(divName).style.display='';
		document.getElementById('hthemeINTtab'+i).className='themeholidaymenuoff';
		document.getElementById(tabdiv).className='themeholidaymenuon';
	}
		
}
/* functionality for Holiday By Theme International Panel End here */

// Fomr Js
function departf(){
document.getElementById('flightsonlybtnhotel').style.display='none';
document.getElementById('flightsonlybtnhotel_off').style.display='';
}
function returnf(){
document.getElementById('flightsonlybtnhotel').style.display='';
document.getElementById('flightsonlybtnhotel_off').style.display='none';
}

function shodcal(){
	document.getElementById('class').style.display='none';
}

// Raahi Js
function raahiCityGuideInd(val){
//alert(val);
if(document.raahiDestCityInd.raahiDestVal.value=='')return false;
else{
var gTrackCode ='utm_source=Yatra%2BDomestic%2BHome%2BPage%2B(home%2C%2Bflights%2C%2Bhotels%2C%2Bbuses%2C%2Bcars)&utm_medium=HTML%2Bunit%2B-%2BDiscover%2BIndia';
//unescape(gTrackCode);
//document.raahiDestCityInd.action='http://www.raahi.com/external/'+val+'?'+gTrackCode;
document.raahiDestCityInd.action='http://www.raahi.com/index.php?option=com_destinationfinder&Itemid=88889026&task=show&d='+val+'&'+gTrackCode;
document.raahiDestCityInd.submit();return true;
}
}


/* Optimized Javascript code from tabcontent.js starts here */
function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid; //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a"); //Get all tab links within container
	this.enabletabpersistence=true;
	this.hottabspositions=[]; //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0; //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[]; //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[]; //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link"; //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1]; //return its value
	return "";
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/"; //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun(); //stop auto cycling of tabs (if running)
		var tabref="";
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position];
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref); //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0;
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1;
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun(); //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]]);
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool;
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link";
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref;
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")); //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1); //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel"); //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : "";
		this.expandsubcontent(subcontentid);
		this.expandrevcontent(associatedrevids);
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : "";
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition);
		this.setcurrenttabindex(tabref.tabposition); //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]); //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none"; //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids;
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none";
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i;
				break;
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true);
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer);
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid); //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1; //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid); //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0;
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i; //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this;
				this.hottabspositions[this.hottabspositions.length]=i; //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel"); //store id of sub content ("rel" attr value)
				this.tabs[i].onmouseover=function(){
					tabinstance.expandtab(this);
					tabinstance.cancelautorun(); //stop auto cycling of tabs (if running)
					return false;
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/));
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i; //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]); //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]); //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod);
		}
	} //END int() function

} //END Prototype assignment
/* Optimized Javascript code from tabcontent.js Ends here */


/********** My Bookings Validation *********/

function isProper(string) {
		//alert(string)
   if (!string) return false;
   var iChars = "*|,\"<:>[]{}`\';()@&$#%1234567890";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
		  
   }
   return true;  
}                   

function MM_validateForm() 
{ 
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	j=0;
	//	/^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
	var regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var regBlank = /[^\s]/;
	var regAlphaNum = /^([a-zA-Z0-9-_]+)$/;
	var regAlpha = /^([a-zA-Z]+)$/;
	var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/;
	var regPhone = /^([0-9_]+-[0-9_]+-[0-9]_+-[0-9_]+)$/;
	
	for (i=1; i<(args.length-2); i+=3) 
	{	
		mesg=args[i+1];
		test=args[i+2]; 
		
		val=document.forms[""+args[0]].elements[""+args[i]];
		if(val.value.length>50 && ( val.name=='contact_first_name' || val.name=='contact_last_name' ||  val.name=='contact_email' || val.name=='contact_city'|| val.name=='contact_state' || val.name=='card_number' || val.name=='card_holder_name'))
		{
		errors += '- '+mesg+' length should no tbe greater than 50.\n'; 
		
		}
		
	    if (val) 
		{	nm=mesg; 
			
			val = val.value;

			if(regBlank.test(val))
			{
				if(test.indexOf('isEqual')!=-1)
				{
					//result = trim(val);
					result = val;
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}else{
					equal_obj_val = test.substring(8,test.indexOf(":"));
					mesg_string =test.substring((test.indexOf(":")+1));
					if(val != document.forms[""+args[0]].elements[""+equal_obj_val].value)
					{
						errors+='- '+nm+' must be same to '+mesg_string+'.\n';
					}
				}
				}else if(test.indexOf('isAlphaNum')!=-1){
					//result = trim(val);
					result = val;
					if(result.length==0){
						errors += '- '+nm+' is required.\n'; 
					}else{
						if(!regAlphaNum.test(val))
						{
							errors+='- '+nm+': Only Alpha Numeric and "_" or "-" Characters Allowed.\n';
						}
					}
				}
				else if(test.indexOf('isAlpha')!=-1){
					//result = trim(val);
					result = val;
					if(result.length==0){
						errors += '- '+nm+' is required.\n'; 
					}else{
						if(!regAlpha.test(val))
						{
							errors+='- '+nm+': Only Alphabets Characters Allowed.\n';
						}
					}
				}
				else if (test.indexOf('isDate')!=-1) 
				{ 
					p=val.indexOf('-');
			        
					if (p != 4 )
					{
						errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';
		
					}
					else if(!regDate.test(val))
					{
						errors+='- '+nm+' must contain Valid Date YYYY-MM-DD.\n';
					}
			     }
				else if (test.indexOf('isPhone')!=-1) 
				{ 
					p=val.indexOf('-');
			        
					if (p < 0)
					{
						errors+='- '+nm+' must contain Valid Phone Number.\n';
		
					}
					else if(!regDate.test(val))
					{
						errors+='- '+nm+' must contain Valid Phone Number.\n';
					}
			     }
				else if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
					s=val.indexOf('.');
					if (p<1 || p==(val.length-1))
					{
						errors+='- '+nm+' must contain a valid e-mail Address.\n';
		
					}
					else if(!regEmail.test(val))
					{
						errors+='- '+nm+' must contain a valid e-mail Address.\n';
					}
			     }
				else if (test.indexOf('isUrl')!=-1) 
				{ 
					p=val.indexOf('http://');
					s=val.indexOf('.');
			        	if (p<0 || p==(val.length-1))
					{
						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
		
					}
					else if(s<p || s==(val.length-1))
					{
						errors+='- '+nm+' must be valid URL e.g. http://www.abc.com\n';
					}
			     }else if (test.indexOf('isChar')!=-1) 
				 { 
					var first_char;
					first_char= val.charAt(0);
					if(first_char==0||first_char==1||first_char==2||first_char==3||first_char==4||first_char==5||first_char==6||first_char==7||first_char==8||first_char==9){
					 errors+='- '+nm+' must starts with  a char.\n';
					}
			     }
	   			 else if (test!='R') 
				 {
				 //result = trim(val);
					result = val;
					
					
					if(result.length==0){
					errors += '- '+nm+' is required.\n'; 
					}
				    if (isNaN(val)) errors+='- '+nm+'  must contain a  numbers only .\n';
					if (test.indexOf('inRange') != -1) 
					{ num = parseFloat(val);
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (num<min || max<num) 
						errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					} 
					if (val.indexOf('-') != -1) 
					{ 
						errors+='- '+nm+' must contain a number without dashes sign.\n';
					} 
					if (val.indexOf('+') != -1) 
					{ 
						errors+='- '+nm+' must contain a number without plus sign.\n';
					}
					
				}else if (test.charAt(0)=='R')
				{
				//result = trim(val);
				result = val;
				if(result.length==0){
				errors += '- '+nm+' is required.\n'; 
				}
				} 
			}
			else if (test.charAt(0) == 'R'){
				errors += '- '+nm+' is required.\n'; 
			}
		}
		if(errors !="")
		{	if(j<=0)
			{
				focusitem = document.forms[""+args[0]].elements[""+args[i]];
				j++;
			}	
			
		}
	} 
	
  if (errors)
  {
	
	alert('The following error(s) occurred: \n\n'+errors);
	
	focusitem.focus();
	return false;
   }
   else
	return true;
}

function login_frm(formname)
{
    	if(MM_validateForm(formname,'login','User Id','RisEmail','password','Password','R'))
	{
		return true;
	}else{
		return false;
	}
}

var nav4 = window.Event ? true : false;

function codes(e) {
  if (nav4) // Navigator 4.0x
    var whichCode = e.which
  else // Internet Explorer 4.0x
    if (e.type == "keypress") // the user entered a character
      var whichCode = e.keyCode
    else
      var whichCode = e.button;
	alert(whichCode);
	return false;
}
/*******************************************/

/***********************************************************************
 * Function Name :hideselect and showselect
 * Description   :When popup open hide all select box thats on page
 * Arguments     : 
 * Return values : 
 ***********************************************************************/
var IE = document.all?true:false;

function hideselect(){
	 document.body.className='hideselectbox';
	 //document.body.scroll = 'no';
	if (IE) {
	document.documentElement.style.overflow = "hidden";
	}
 }
function showselect(){
	 document.body.className='';
	 //document.body.scroll = '';
	 if (IE) {
	document.documentElement.style.overflow = "";
	 }
	if(document.getElementById('adzonediv')){
		document.getElementById('adzonediv').style.display='';
	}
 }

/***********************************************************************
 * Function name:closefindcity
 * Description: To close the poup up window for city list
 * Arguments: 
 * Return values:popup window
 ***********************************************************************/
function closefindcity()
{
	showselect();
	document.getElementById('overeffect').style.display='none';
	document.getElementById('findcitycontainer').style.display='none';
}

/***********************************************************************
 * Function name:findcity
 * Description: To open the poup up window for city list
 * Arguments: 
 * Return values:popup window
 ***********************************************************************/
function findcity()
{
	hideselect();
	document.documentElement.style.overflow = "";
	document.getElementById('overeffect').style.display='';
	cities_beginning_with('A');
	document.getElementById('findcitycontainer').style.display='';

}
/*******************************************/

/***********************************************************************
 * Function Name : set_city_name
 * Description   : To set city name in parent window when user selects 
 *                 any city in find city popup
 * Arguments     : City Name
 * Return values : None
 ***********************************************************************/
 function set_city_name(CityName) {
	 document.getElementById('city').value=CityName;
	 document.getElementById('city').focus();
         set_default_advanceparam();
}

/***********************************************************************
 * Function Name : set_default_advanceparam()
 * Description   : To set default advance parameter
 * Arguments     : 
 * Return values : 
 ***********************************************************************/
function set_default_advanceparam(){

	strDefaultHotelType=default_hotel_type();
}

/***********************************************************************
 * Function Name : default_hotel_type
 * Description   : To set the HTML string for hotel type
 * Arguments     : None
 * Return values : HTML string for hotel type
 ***********************************************************************/
function default_hotel_type(){
	var str='';
	str="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	str+="<tr><td><input type=\"checkbox\" name=\"business\" checked DISABLED/>Business Hotel</td>";
	str+="<td><input type=\"checkbox\" name=\"resort\" checked DISABLED/>Resort</td>";
	str+="</tr><tr><td><input type=\"checkbox\" name=\"BB\" checked DISABLED/>Family</td>";
	str+="<td><input type=\"checkbox\" name=\"luxury\" checked DISABLED/>Luxury</td></tr>";
	str+="</table>";
	return str;
}