


var greybox_title = "RentMyVacationHome.com";
var myShowForm=false;
var myContentForm = false;
var form_element_prefix = "ctl00_Main_";
var GB_ROOT_DIR = "http"+(("https:" == document.location.protocol) ? "s" : "")+"://"+greyboxPath(document.location.href)+"/admin/code/JavaScript/greybox/";

function greyboxPath(url_)
{
	url_ = (url_.indexOf('http://') > -1) ? url_.substring(7,url_.length) : url_.substring(8,url_.length);
	url_ = url_.substring(0,url_.indexOf('/'))
	return url_;
}



function ManageContent(Action,thisIDname,thisIDvalue,PartNumber,FileName,K_){
			
	if (myContentForm){
		myContentForm.close();
	}
	
	if(Action=="D"){
		if(document.getElementById('current_content_container')){
			document.getElementById('current_content_container').value="|"+thisIDname+","+thisIDvalue+","+PartNumber+","+K_+"|";
			return false;
		}else{
			return false;
		}
	}
	
	K_ = K_ ? K_ : 0;

//	myContentForm = window.open('/admin/code/Content/ContentForm/ContentForm_'+FileName+'_'+PartNumber+'.aspx?A='+Action+'&B='+thisIDname+'&C='+thisIDvalue+'&D='+PartNumber+'&E='+K_,'ContentManage','toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');
	GB_showCenter( greybox_title,'/admin/code/Content/ContentForm/ContentForm_'+FileName+'_'+PartNumber+'.aspx?A='+Action+'&B='+thisIDname+'&C='+thisIDvalue+'&D='+PartNumber+'&E='+K_,700,900);


}


function ShowAddUpdate(FileName,Action,Args,PopUp){

	var isMac = navigator.userAgent.indexOf('Mac') != -1 
		
	if (isMac){
		if (Args){
			if(Args.substring(1,1) != "&"){
				Args = '&'+Args
			}
		}else{
			Args = ''
		}	
	}else{
		if ((Args != undefined) && (Args != '')){
			if(Args.substring(1,1) != "&"){
			Args = '&'+Args
			}
		}else{
			Args = ''
		}
	}
	
	var formName = 'formName'

	var xtraArgs = document.location.href;
	if(xtraArgs.indexOf('?')>0){
		xtraArgs = xtraArgs.substring(xtraArgs.indexOf('?')+1,xtraArgs.length);
		if(Action=="U" || Action=="S" &&Args.indexOf('PK=')>-1){
			xtraArgs=xtraArgs.replace(/PK=[\S]*?&/gi,"");
		}
	}else{
		xtraArgs = "";
	}

	if(Args!=""&&xtraArgs!=""){xtraArgs='&'+xtraArgs;}
	Args += xtraArgs; 
	if(Args!=""&&Args.substring(0,1)!='&'){
		Args='&'+Args;
	}
	if(myShowForm){
		myShowForm.close();
	}
	


	var prefixPath = "/admin/code/AddUpdatePages/";	
	if(PopUp){
		prefixPath = "/admin/code/PopUp/";
	}

//	myShowForm = window.open(prefixPath+FileName+'?A='+Action+Args,formName,'toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');
//	myShowForm.focus();
	
	GB_showCenter( greybox_title, prefixPath+FileName+'?A='+Action+Args,700,900);

}


function ShowPopUp(FileName,useGreyBox,width,height){
	var formName = 'formName'+FileName.replace(/[^a-zA-Z]/gi,"");
	var prefixPath = "/admin/code/PopUp/";

	if (useGreyBox){
		//alert(width);
		GB_showCenter( greybox_title,prefixPath+FileName,!height ? height : 700 ,!width ? width : 900);
	}else{
		var myPopUpForm = window.open(prefixPath+FileName,formName,'toolbars=no,scrollbars=yes,status=yes,location=no,width=900,height=625,resizable=yes,left=10,top=10,postionx=10,positiony=10');
		myPopUpForm.focus();
	}
}




function closeForm(){
	try{
		parent.parent.GB_hide();
	} catch(err){
		opener.document.location.href=opener.document.location.href;
		window.close();
	}
}

function RunOrderByColumnName(ColumnName){

	if(document.getElementById('ctl00_Main_OrderByColumnName')){
		var currOrderByColumnName = document.getElementById('ctl00_Main_OrderByColumnName')
		if(currOrderByColumnName.value==ColumnName+' ASC'){
			currOrderByColumnName.value=ColumnName+' DESC';
		}else{
			currOrderByColumnName.value=ColumnName+' ASC';
		}
			
	}
	document.forms[0].submit();
}



function showPrint(PrintKey){
	var myPrint = window.open('/admin/code/Print/ManagePrint.aspx?A='+PrintKey,PrintKey,'toolbars=yes,scrollbars=yes,status=yes,location=no,width=650,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');
	myPrint.focus();

}

function showPrintPage(Page){
	var URL = "/Admin/Code/PopUp/PopUp_Print.aspx?page="+Page;
	GB_showCenter('Print Page',URL,null,778);

}




function ChangePage(Action,To,Step){
	var regRetVal = new RegExp(/retVal=[\S|\s]*/gi);
	var regURL = new RegExp(/https*:\/\/[\S]*?\.[\S]*?\//i);
	var retVal = regRetVal.exec(document.location.href); 
	retVal = retVal ? retVal[0] : "";

	var baseURL = regURL.exec(document.location.href);
	baseURL = baseURL[0];
	var currPage = document.location.href;
	currPage = currPage.substring(baseURL.length-1,currPage.length);
	Step = Step ? Step : 0;


	if(Action=="BACK"){
		var itemName="";itemValue="";itemArray = new Array();
		retVal = retVal.replace(/\%3a/gi,":");
		retVal = retVal.replace(/\%7C/gi,"|");
		if(retVal.substring(0,7)=='retVal='){
			retVal = retVal.substring(7,retVal.length);
		}
		var retHistory = retVal.split(/\|/gi);
		for(k=0;k<retHistory.length;k++){
			itemName = retHistory[k].substring(0,retHistory[k].indexOf(':'))
			itemValue = retHistory[k].substring(retHistory[k].indexOf(':')+1,retHistory[k].length);
			itemArray[itemName] = URLDecode(itemValue);
		}
		

		if(itemArray.length>=Step){
			if(itemArray[Step].indexOf('&retVal=')>0){
				retVal = itemArray[Step];
				retVal = retVal.substring(retVal.indexOf('&retVal=')+8,retVal.length)
				itemArray[Step] = itemArray[Step].substring(0,itemArray[Step].indexOf('&retVal=')+7)+"="+URLEncode(retVal)+'|';
			} 
			document.location.href = itemArray[Step];
		}else{
			alert('Could not find Step in the retVal of the previous querystring');
			return false;
		}
	
	}else if(Action=="NEXT"){
		// append to retVal if applicable		
		if(retVal){
			currPage = (currPage.substring(currPage.length-1,currPage.length)!='|') ? currPage+'|' : currPage;
			retVal+=Step+":"+URLEncode(currPage)
			if (To.indexOf("?")==-1){
				To+='?'+retVal;
			}else{
				To+="&"+retVal;
			}
			document.location.href = To;
		}else{
			retVal = "&retVal="+Step+":"+URLEncode(currPage)+'|'
			To+=retVal;
			document.location.href = To;
		}	
		
	}else{
		alert('No Action Specified: BACK OR NEXT');
		return false;
	}

}


function CommentChange(textarea,counter) {
	var len = document.getElementById(textarea).value
	if (1000 - len.length <= 0){
		document.getElementById(texarea).value = len.substring(0, 1000);
		alert('You have entered the max characters!');
	}
	else
	{
	document.getElementById(counter).value = 1000 - len.length;
	}
	
}



function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie( name, value, expires, path, domain, secure ){
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 





function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}




//Drop-Down Menu Start

var DDSPEED = 2;
var DDTIMER = 2;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

//Drop-Down Menu Stop


function theRotator(id) {
	//Set the opacity of all images to 0
	$('div#'+id+' ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#'+id+' ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate(\''+id+'\')',3000);
	
}

function rotate(id) {	
	//Get the first image
	var current = ($('div#'+id+' ul li.show')?  $('div#'+id+' ul li.show') : $('div#'+id+' ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#'+id+' ul li:first') :current.next()) : $('div#'+id+' ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
}



function startPlayer(obj){
	$f(obj).show();
	$f(obj).play();
	if(document.all){$f(obj).play();}
}

var tabdropdown={
	disappeardelay: 200, //set delay in miliseconds before menu disappears onmouseout
	disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
	enableiframeshim: 0, //1 or 0, for true or false

	//No need to edit beyond here////////////////////////
	dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, previousmenuitem:null,
	currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/)

	getposOffset:function(what, offsettype){
		var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
		var parentEl=what.offsetParent;
			while (parentEl!=null){
				totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
				parentEl=parentEl.offsetParent;
			}
		return totaloffset;
	},

	showhide:function(obj, e, obj2){ //obj refers to drop down menu, obj2 refers to tab menu item mouse is currently over
		if (this.ie || this.firefox)
			this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
		if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
			if (obj2.parentNode.className.indexOf("default")==-1) //if tab isn't a default selected one
				obj2.parentNode.className="selected"  ///"selected"
				obj.visibility="visible"
			}
		else if (e.type=="click")
			obj.visibility="hidden"
	},

	iecompattest:function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

	clearbrowseredge:function(obj, whichedge){
		var edgeoffset=0
		if (whichedge=="rightedge"){
			var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
			edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
		}
		else{
			var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
			var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
			this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
			if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
				edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
				if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
					edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
			}
			this.dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
		}
		return edgeoffset
	},

	dropit:function(obj, e, dropmenuID){
		if (this.dropmenuobj!=null){ //hide previous menu
			this.dropmenuobj.style.visibility="hidden" //hide menu
			if (this.previousmenuitem!=null && this.previousmenuitem!=obj){
				if (this.previousmenuitem.parentNode.className.indexOf("default")==-1) //If the tab isn't a default selected one
					this.previousmenuitem.parentNode.className=""
			}
		}
		this.clearhidemenu()
		if (this.ie||this.firefox){
			obj.onmouseout=function(){tabdropdown.delayhidemenu(obj)}
			obj.onclick=function(){return !tabdropdown.disablemenuclick} //disable main menu item link onclick?
			this.dropmenuobj=document.getElementById(dropmenuID)
			this.dropmenuobj.onmouseover=function(){tabdropdown.clearhidemenu()}
			this.dropmenuobj.onmouseout=function(e){tabdropdown.dynamichide(e, obj)}
			this.dropmenuobj.onclick=function(){tabdropdown.delayhidemenu(obj)}
			this.showhide(this.dropmenuobj.style, e, obj)
			this.dropmenuobj.x=this.getposOffset(obj, "left")
			this.dropmenuobj.y=this.getposOffset(obj, "top")
			var newLeft = parseInt((getWindowWidth() - 1016)/2) - (this.ie ? 0 : 7); // added 4/21/11 the relative container caused the offset to be incorrect, it got 0
			// we had to determine the window width - the container size / 2, because right/left. We subtracted a room for padding.
			this.dropmenuobj.style.left= this.dropmenuobj.x  - newLeft +'px' ;///-this.clearbrowseredge(obj, "rightedge")+"px"
			this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
			this.previousmenuitem=obj //remember main menu item mouse moved out from (and into current menu item)
			this.positionshim() //call iframe shim function
		}
	},

	contains_firefox:function(a, b) {
		while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
		return false;
	},

	dynamichide:function(e, obj2){ //obj2 refers to tab menu item mouse is currently over
		var evtobj=window.event? window.event : e
		if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
			this.delayhidemenu(obj2)
		else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.delayhidemenu(obj2)
	},

	delayhidemenu:function(obj2){
		this.delayhide=setTimeout(function(){tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) //hide menu
	},

	clearhidemenu:function(){
		if (this.delayhide!="undefined")
			clearTimeout(this.delayhide)
	},

	positionshim:function(){ //display iframe shim function
		if (this.enableiframeshim && typeof this.shimobject!="undefined"){
			if (this.dropmenuobj.style.visibility=="visible"){
				this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
				this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
				this.shimobject.style.left=this.dropmenuobj.style.left
				this.shimobject.style.top=this.dropmenuobj.style.top
			}
		this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
		}
	},

	hideshim:function(){
		if (this.enableiframeshim && typeof this.shimobject!="undefined")
			this.shimobject.style.display='none'
	},

isSelected:function(menuurl){
	var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
	return (tabdropdown.currentpageurl==menuurl)
},

	init:function(menuid, dselected){
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
		var menuitems=document.getElementById(menuid).getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")
				document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
				menuitems[i].onmouseover=function(e){
					var event=typeof e!="undefined"? e : window.event
					tabdropdown.dropit(this, event, this.getAttribute("rel"))
				}
			}
			if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
				menuitems[i].parentNode.className+=" selected default"
				var setalready=true
			}
			else if (parseInt(dselected)==i)
				menuitems[i].parentNode.className+=" selected default"
		}
	}

}


function foo(on,id){
	if(on){
		document.getElementById('main_nav_'+id).style.backgroundColor='#000';
	}else{
		document.getElementById('main_nav_'+id).style.backgroundColor='';
	}
}


function getWindowWidth() {
		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	}


function showmore(id){
     $('#'+id).toggle(400);
}

function getID(obj){
	var x = obj.id;
	if(!x) return false;
	
	if(x.indexOf('_')>-1){
		return x.substring(0,x.lastIndexOf('_')+1);
	}else{
		return x
	}
}


function showBanner(wrapperid,id){
    $('#'+id).toggle(400, function() {
        var imgSrc = $('#'+wrapperid+' .bannerbar img').attr('src');
        if (imgSrc.indexOf('/pub/design/banneruparrow.jpg') >= 0)
        {
            $('#'+wrapperid+' img').attr('src', '/pub/design/bannerdownarrow.jpg');
        }
        else
        {
            $('#'+wrapperid+' img').attr('src', '/pub/design/banneruparrow.jpg');
        }
    });
    
}


function showBanner2(wrapperid,id,imgid){
    $('#'+id).toggle(400, function() {
        var imgSrc = $('#'+imgid).attr('src');
        if (imgSrc.indexOf('/pub/design/banneruparrow.jpg') >= 0)
        {
            $('#'+imgid).attr('src', '/pub/design/bannerdownarrow.jpg');
        }
        else
        {
            $('#'+imgid).attr('src', '/pub/design/banneruparrow.jpg');
        }
    });
    
}


function copyBilling(x)
{
    var prefix = x ? x : 'ctl00_Main_UserControl_CreditCard_1_';
     document.getElementById(prefix+'sFName').value = document.getElementById(prefix+'bFName').value;
     document.getElementById(prefix+'sLName').value = document.getElementById(prefix+'bLName').value;
	 if(document.getElementById(prefix+'sCompany')) document.getElementById(prefix+'sCompany').value = document.getElementById(prefix+'bCompany').value;
	 document.getElementById(prefix+'sAddress1').value = document.getElementById(prefix+'bAddress1').value;
     document.getElementById(prefix+'sAddress2').value = document.getElementById(prefix+'bAddress2').value;
     document.getElementById(prefix+'sCity').value = document.getElementById(prefix+'bCity').value;
     document.getElementById(prefix+'sPostalCode').value = document.getElementById(prefix+'bPostalCode').value;
     document.getElementById(prefix+'sState').value = document.getElementById(prefix+'bState').value;
     document.getElementById(prefix+'sEmail').value = document.getElementById(prefix+'bEmail').value
     document.getElementById(prefix+'sPhoneNumber').value = document.getElementById(prefix+'bPhoneNumber').value;
	 document.getElementById(prefix+'sCountry').value = document.getElementById(prefix+'bCountry').value;
	 var c = document.getElementById(prefix+'bCountry').value;
	 document.getElementById(prefix+'sState').disabled = !(c == 'US' || c == 'CA');

}
	//End Javascript 
function disablestate(obj,t){
	var prefix = 'ctl00_Main_UserControl_CreditCard_1_';
	if(obj.value=='US'||obj.value=='CA'){
		document.getElementById(prefix+t+'State').disabled = false;
	}else{
		document.getElementById(prefix+t+'State').disabled = true;		
	}
}
	

function showmore(id){
     $('#'+id).toggle(400);
}


function sliderRedirect(link,qs,sliderqs)
{
	if (qs === '')
	{
	    //alert(link+'?'+sliderqs);
		window.location = link+'?'+sliderqs + '#sliderRedirect';
	}
	else
	{
		//alert(link+qs+'&'+sliderqs);
		window.location = link+qs+'&'+sliderqs + '#sliderRedirect';
	}	
}

function dateRedirect()
{
	
	alert('Please enter a city/state in the Quick Search field and click click on the option provided');
	return false;
	
    var link = '/FindARental.htm';
    var sDate = document.getElementById('startdate1').value;
    var eDate = document.getElementById('enddate1').value;
    
    if (sDate === '' && eDate === '')
    {
        window.location = link;
    }
    else if(sDate === '') 
    {
        window.location = link+'?enddate='+eDate;
    }
    else if(eDate === '') 
    {
        window.location = link+'?startdate='+sDate;
    }
    else
    {
        window.location = link+'?startdate='+sDate+'&enddate='+eDate;
    }
}

function setAvailDate(link,qs)
{
    var sDate = document.getElementById('ctl00_Main_UserControl_FindRental_1_startdate1').value;
    var eDate = document.getElementById('ctl00_Main_UserControl_FindRental_1_enddate1').value;
    
    if (sDate === '' && eDate === '')
    {
        window.location = link+qs;
    }
    else if(sDate === '') 
    {
        if (qs === '')
        {
            window.location = link+'?enddate='+eDate;
        }
        else
        {
            window.location = link+qs+'&enddate='+eDate;
        }
    }
    else if(eDate === '') 
    {
        if (qs === '')
        {
            window.location = link+'?startdate='+sDate;
        }
        else
        {
            window.location = link+qs+'&startdate='+sDate;
        }
    }
    else
    {
        if (qs === '')
        {
            window.location = link+'?startdate='+sDate+'&enddate='+eDate;
        }
        else
        {
            window.location = link+qs+'&startdate='+sDate+'&enddate='+eDate;
        }
    }
}

function calPicked(start,end)
{
    //alert('Check-in: '+start+'  Check-out: '+end);
    
    
    //Fill In Values
    //startendtext1
    document.getElementById('ctl00_Main_UserControl_BookNow_1_startendtext1').value = start+' - '+end;
    document.getElementById('ctl00_Main_UserControl_BookNow_1_startdate1').value = start;
    document.getElementById('ctl00_Main_UserControl_BookNow_1_enddate1').value = end;
    
    //Now show the rest of the form....
    showmore('bookingstep1');
    showmore('bookingstep2');
}

function changeDate()
{
    showmore('bookingstep1');
    showmore('bookingstep2');
}

function changeMonth(id,increment){
	var obj = document.getElementById(id);
	
	// update index
	obj.value = parseInt(obj.value) + increment
	
	if(obj.value>12){
		obj.value = 1;	
	}else if(obj.value<1){
		obj.value=12;
	}
	
	for(j=1;j<=12;j++){
		document.getElementById('cal-month-'+j).style.display = parseInt(obj.value) == j ? 'block' : 'none';	
	}
	return false;
}


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function setRate(obj){
	var day = obj.attr('id');
	if(!day) return false;
	
	// get rate
	day = day.substring(4).replace(/_/gi,"/");
	var NA = "N/A";
	var button = $('#isBk').val() == '1' ? '<input type="submit" name="cmdAction" value="Book Now" class="formButton" />' : '<input type="button" name="cmdAction" value="Book Now" class="formButton" onclick="alert(\'The owner has not yet enabled online payments, please contact the property owner by phone or email\');" />';

	try{
		var rate = eval('('+rates[day]+')');
	}catch(e){
		$('#Rental_Season').attr('innerHTML',NA);
		$('#Rental_RentalTermName').attr('innerHTML',NA);
		$('#Group_Day_Rate').attr('innerHTML',NA);
		$('#Week_Rate').attr('innerHTML',NA);
		$('#Monthly_Rate').attr('innerHTML',NA);
//		$('#Saturday_To_Saturday').attr('innerHTML',NA);
//		$('#Minimum_Days').attr('innerHTML',NA);
		$('#Check_In_Date').attr('innerHTML',NA);
		$('#Check_Out_Date').attr('innerHTML',NA);
		$('#Button_Data').attr('innerHTML',NA);

		changeSelectedDates($('#Check_In_Date').attr('innerHTML'),$('#Check_Out_Date').attr('innerHTML'),false);
		return false;
	}
	
	
	if(!isValidRate(day,rate.item[0])){
		return false;
	}
	
	// set the fields 
	$('#Rental_Season').attr('innerHTML',rate.item[0].PeriodName);
	$('#Rental_RentalTermName').attr('innerHTML',rate.item[0].RentalTermName);	
	$('#Group_Day_Rate').attr('innerHTML',formatCurrency(rate.item[0].GroupDayRate));
	$('#Week_Rate').attr('innerHTML',formatCurrency(rate.item[0].WeekRate));
	$('#Monthly_Rate').attr('innerHTML',formatCurrency(rate.item[0].MonthlyRate));

	changeSelectedDates($('#Check_In_Date').attr('innerHTML'),$('#Check_Out_Date').attr('innerHTML'),false);
	
	var prev_sat = getWhichDay(day,'prev',rate.item[0].RentalTerm,rate.item[0].MinDays);
	var next_sat = getWhichDay(day,'next',rate.item[0].RentalTerm,rate.item[0].MinDays);

	
	changeSelectedDates(formatDate(prev_sat),formatDate(next_sat),true);
	

	$('#Check_In_Date').attr('innerHTML',formatDate(prev_sat));
	$('#Check_Out_Date').attr('innerHTML',formatDate(next_sat));	
	$('#Button_Data').attr('innerHTML',button);
//	$('#Saturday_To_Saturday').attr('innerHTML',formatCurrency(rate.item[0].SaturdayToSaturday));
//	$('#Minimum_Days').attr('innerHTML',rate.item[0].MinDays);

	$('#ctl00_Main_UserControl_BookNow_1_bTerm').val(rate.item[0].RentalTerm);
	$('#ctl00_Main_UserControl_BookNow_1_s1').val(formatDate(prev_sat));
	$('#ctl00_Main_UserControl_BookNow_1_s2').val(formatDate(next_sat));
	$('#ctl00_Main_UserControl_BookNow_1_r1').val(rate.item[0].ID);
	$('#ctl00_Main_UserControl_BookNow_1_ra1').val(getWhichRate(rate.item[0].RentalTerm,rate.item[0]));

}


function getWhichRate(term,obj){
	if(term=="S"){
		return obj.WeekRate;
	}else if(term=="M"){
		return obj.MonthlyRate;
	}else if(term=="D"){
		return obj.GroupDayRate;
	}
		

}


function getRateTerm(dt){
	

		try{
			dt =  formatDate(dt,"_").replace(/_/gi,'/');
			var rate = eval('('+rates[dt]+')');
			return rate.item[0].RentalTerm;
		}catch(e){
			return dt;
		}
		
		
}

function isValidRate(day,obj){

	// check the day range and if it is not valid then return false
	var prev_sat = getWhichDay(day,'prev',obj.RentalTerm,obj.MinDays);
	var next_sat = getWhichDay(day,'next',obj.RentalTerm,obj.MinDays);

	if(!isDate(prev_sat) || !isDate(next_sat)){
		return false;
	}
	
	var s1 = new Date(prev_sat);
	var s2 = new Date(next_sat);
		
	var index = 0;
	var offset = daydiff(s2,s1);

	while(s1<=s2){
		
		if(obj.RentalTerm!=getRateTerm(s1)){
			return false;
		}
		
		t = formatDate(s1,"_");
		if(!document.getElementById('day_'+t)){
			if(!(index==0 || index == offset)){
				return false;
			}
		}
		s1 = addDays(s1,1);		
		index += 1;
	}
	
	return true;
}


function setBookForm(){
	if($('#ctl00_Main_UserControl_BookNow_1_s1').val()!=""){
		var id = '#day_' + $('#ctl00_Main_UserControl_BookNow_1_s1').val().replace(/\//gi,'_')
		setRate($(id));	
	}
}

function changeSelectedDates(startDate,endDate,isOn){
	// first clear the old dates
	var on = 'background-color:red;color:#000;width:30px;display:block;text-align:center;'
	var off = 'color:#083A6B;';
	
	if(!isDate(startDate) || !isDate(endDate)){
		return false;
	}
	
	var s1 = new Date(startDate);
	var s2 = new Date(endDate);

	
	
	var index = 0;
	var daysApart = daydiff(s2,s1);

	while(s1<=s2){
		
		if(index == 0){
			styleOn = whichSat(s1,s2,on,index);
		}else if(index==daysApart){
			styleOn = whichSat(s1,s2,on,index);			
		}else{
			styleOn = on;
		}
		
		t = formatDate(s1,"_");
		if(document.getElementById('day_'+t)){
			$('#day_'+t).attr("style",isOn ? styleOn : off);	
		}else{
			$('#booked_'+t).attr("style",isOn ? styleOn : off);	
		}
		
	
		s1 = addDays(s1,1);
		index += 1;
	}

}

function daydiff(dt1,dt2){
	return new Date(Date.parse(dt1) - Date.parse(dt2)).getDate();		
}


function whichSat(s1,s2,on,index){
	
	var startDate = s1;
	var endDate = s2;
	
	var top = "background-image:url(/pub/calendar/sat_top.png);background-position:top left;background-repeat:no-repeat;";
	var btm = "background-image:url(/pub/calendar/sat_btm.png);background-position:top left;background-repeat:no-repeat;";
	
	if(index == 0){
		// return btm
		return on.replace(/background-color:[\S|\s]*?;/gi,btm);
	}else{
		// top
		return on.replace(/background-color:[\S|\s]*?;/gi,top);
	}
	
}

function formatDate(dt,delimiter){
	
	var tag = "/";
	if(delimiter) tag = delimiter;
	
	return formatTwoDigit(parseInt(dt.getMonth()+1)) + tag + formatTwoDigit(dt.getDate()) + tag + dt.getFullYear();	
}

function formatTwoDigit(x){
	return 	Right("0" + x,2);
}


function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function getWhichDay(dt,which,term,minDays){
		
		if(term=="S"){
			// sat 2 sat
			return getSaturday(dt,which);
		}else if(term=="M"){
			// monthly
			return getMonthDay(dt,which);
		}else if(term=="D"){
			// daily
			return getDailyDay(dt,which,minDays);
		}
}
				
function getDailyDay(dt,which,minDays){

	var today = new Date(dt);
	if(which=='prev'){
		return today;
	}else{
		return addDays(today,parseInt(minDays-1));	
	}
	
}
				
function getMonthDay(dt,which){
	
	var today = new Date(dt);
	var increment = 0;
	
	if(which=='prev'){
		// bring back to one
		return new Date(today.getYear()+1900,today.getMonth(),1);
	}else{
		// increment to last day
		return new Date(today.getYear()+1900,today.getMonth(),(new Date((new Date(today.getYear(), today.getMonth()+1,1))-1)).getDate());
	}
}
					 
					 // getSaturday(day,'next');

function getSaturday(dt,which){

	var today = new Date(dt);
	var increment = 0;
	if(which=="prev"){
		increment = today.getDay() == 6 ? 0 : parseInt(-1 * Math.abs(1 + today.getDay()));
		return addDays(today,increment);
	}else{
		increment = today.getDay() == 6 ? 7 : parseInt(Math.abs(6 - today.getDay()));
		return addDays(today,increment);
	}
}

function addDays(today,increment){
	today.setDate(today.getDate() + increment);
	return today
}

function showpics(action,i){
	
	switch(action){
		
		case "set":
			// hides the nav
			$('#less-pics').css('visibility','hidden');
			if(images.length<=6){
				$('#more-pics').css('visibility','hidden');
			}
			
			// set the hieght of the main div based on the max image height
			for(j=0;j<images.length;j++){
				preImages[j] = new Image();
				var g = eval('('+images[j]+')');
				preImages[j].src = g.image[0].path;
			}
		
			break;
		case "more":
			
			$('#picture-ul').animate({
				left:  -640
				},800,function(){
				$('#less-pics').css('visibility','visible');				
				$('#more-pics').css('visibility','hidden');
			});			
			return false;
			break;
		case "less":
			$('#picture-ul').animate({
				left:  0
				},800,function(){
				$('#less-pics').css('visibility','hidden');				
				$('#more-pics').css('visibility','visible');
			});	
			return false;
			break;
		case "index":
			var img = eval('('+images[i]+')');
			$('#MainImage').attr('src',img.image[0].path);
			return false;			
			break;
	}
	
}


function setMaxHeight(){
	var maxheight = 0;
	for(j=0;j<preImages.length;j++){
		if(preImages[j].height>maxheight){
			maxheight = preImages[j].height;
		}else if(preImages[j].height==0){
			setMaxHeight(preImages);	
		}
	}
	if(maxheight!=0){
	$('div.main-image-box').attr('style','height:'+(maxheight+15)+'px');
	$('div.main-image-box #imgList').attr('style','height:'+(maxheight)+'px');
	$('div.main-image-box #imgList ul li').attr('style','height:'+(maxheight)+'px');
	}
	
	$('#imgList').css('visibility','visible');
}


function setupIframe(){
	
	Set_Cookie('_isiframe','1');	

	if(window.top==window.self){
		Set_Cookie('_isiframe',null);
		var redirectTo = document.location.href;
		document.location.href = redirectTo.indexOf('?') > 0 ? redirectTo.substring(0,redirectTo.indexOf('?')) : redirectTo;
		return false;
	}
	
	$(document).ready(function() {
		$('a,area').click(function () {
		 var href = $(this).attr('href');
		 if(href!='#'){
			href = href.indexOf('?') > 0 ? href + '&iframe=true' : href + '?iframe=true';
			$(this).attr('href',href + '#top');
		 }
		});
	});


	
	var c = document.getElementById('test12345')
	if (c){
		c.focus();
		//c.style.display = 'none';
	}




}

function showItemFocus(id)
{
    document.getElementById(id).focus();
}

function changeRateTerm(val)
{
    if(val==='S')
    {
        //Sat to Sat...
        //'table-row'
        document.getElementById('ctl00_Main_ROW_GroupDayRate').style.display = 'none';
        document.getElementById('ctl00_Main_ROW_WeekRate').style.display = 'table-row';
        document.getElementById('ctl00_Main_ROW_MonthlyRate').style.display = 'none';
    }
    else if(val==='M') 
    {
        document.getElementById('ctl00_Main_ROW_GroupDayRate').style.display = 'none';
        document.getElementById('ctl00_Main_ROW_WeekRate').style.display = 'none';
        document.getElementById('ctl00_Main_ROW_MonthlyRate').style.display = 'table-row';
    }
    else
    {
        document.getElementById('ctl00_Main_ROW_GroupDayRate').style.display = 'table-row';
        document.getElementById('ctl00_Main_ROW_WeekRate').style.display = 'none';
        document.getElementById('ctl00_Main_ROW_MonthlyRate').style.display = 'none';
    }
    
    document.getElementById('ctl00_Main_MinDays').disabled=val=='D'||val=='X' ? false : true;
}

//ctl00_Main_RentalTerm
function setLoadRateTerm()
{
    changeRateTerm(document.getElementById('ctl00_Main_RentalTerm').value)  
}

function getprefix(){
	var a = document.getElementsByTagName('input');
	for(j=0;j<a.length;j++){
		var i = a[j];
		if(i.id.indexOf('ctl00_')>-1){
			var p = i.id.substring(0,i.id.lastIndexOf('_')+1); 
			return p;
			break;
		}
	}
}


function PostChange(textarea,counter,maxLength) {
	var t = document.getElementById(textarea);
	var p = getprefix();
	var c = document.getElementById(counter) ? document.getElementById(counter) : document.getElementById(p+counter);

	if(!c){
		alert('Could not find count ' +  counter + ' == ' + p+counter);	
	}
	
	if(t){
		var len = t.value
		if (maxLength - len.length <= 0){
			//t.value = len.substring(0, maxLength);
			//alert('You have entered the max characters!');
			c.value = maxLength - t.value.length;
			c.style.backgroundColor = 'red';
		}else{
			c.value = maxLength - len.length;
			c.style.backgroundColor = 'white';
		}
	}else{
		
	}
}

function manageLabel(obj,id,onfocus){


	if(onfocus){
		$('#'+id).fadeOut(0);
	}else{
		if(obj.value==''){
			$('#'+id).fadeIn(0);
		}
	}

}

function scaleBrowser(){

	try{
		window.moveTo(0,0);
		var aH = screen.availHeight;
		var aW = screen.availWidth;
		window.resizeTo(aW,aH);
	}catch(e){}

}



function killFlash(){
	document.getElementById('flash_content').style.display='none';
	document.getElementById('close_flash').style.display='none';
	
}

function showmorecity(id){

	if ($('#'+id).css('display')=='block'){
		$('#'+id).fadeOut(700);
		$('#'+id+'-link').attr('innerHTML','&raquo;&raquo;&nbsp;show more cities');
	}else{
		$('#'+id).fadeIn(700);	
		$('#'+id+'-link').attr('innerHTML','&laquo;&laquo;&nbsp;show less cities');
	}

}

function newSearch(xlink){
	var ls = xlink;
	
	var del = (xlink.indexOf('?') == -1 ? '?' : '&');
	var v = '';	
	
	var types = new Array('ptype','plocation','ptheme');
	for(var a in types){
		var comma = '';

		v = '';
		var c = document.getElementsByName(types[a]);
	
		for(i=0;i<c.length;i++){
			if(c[i].checked){
				v += comma + c[i].value;
				comma = ',';			
			}
		}
	
		if (v!=''){
			ls += del + types[a].substring(1) + '='+ v;	
			del = '&';
		}
	}
	
	document.location.href=ls;
}

function checkSearchBox(name,obj){
	var c = document.getElementsByName(name);	
	for(j=0;j<c.length;j++){
		c[j].checked = obj.checked;
	}
}
