rowfix=0;

$(document).ready(function(){
 jQuery(".lightList tr:even").addClass("greyLine");
 
  //
//  alert("hihdi");

     jQuery('#topImg').cycle({ 
        fx:      'fade',
        continuous:true,
        timeout: 6000,
        speed: 2000
    });
  //  alert("hihdfi");
    myURL = "/?cv=12&amp;do=catcont&amp;category="+rentCat +"&amp;dochildren=1&amp;use_layout=layout_blank.html&amp;template_file=categories_booking_utne.html&amp;defaultItem=0";
	//$("#dialog").html("");

	//	alert("hihi");
	jQuery.ajax({ url: myURL, 
					 context: document.body, 
					 success: function(html){
					 //	alert("hihi");
        		$("#dialog").append(html);
						
						//setVal(myId);
        		//$("#letObj option[value='"+myId+"']").attr("selected", "selected");
        		
        		valMe();
        		
        	//	startDialog();	
      }});
  // 	alert("hihi3");
 
	//			$("#dialog").dialog("destroy");
//$("#bookButtonC").ho
//("fast");
$("#bookButtonC").show("fast");
//startDialog();	

});

function startDialog(){
	//alert("startdialog");
 		
}
		
	dialogUp=0;

function setVal(mId){

//alert(mId);	
	if(jQuery("#og_"+mId).length>0){
//		alert(jQuery("#og_"+mId));
	//	alert(jQuery("#og_"+mId)[0]);
		
		if(jQuery("#og_"+mId)[0].tagName == "OPTGROUP"){
			//alert("ISOPTGRUOP");
				myObjects = jQuery("#og_"+mId+" > option");
				mId = myObjects[0].value
			}
	}
	
		$("#letObj option[value='"+mId+"']").attr("selected", "selected");
}

function upDialog(myTitle,myId){
//	alert(myTitle + " "+myId);
//				$("#dialog").dialog("destroy");
		//		dialogUp=0;
//if(dialogUp==0){
	
 // dialogUp=1;  
//}else{
	
//}   

	//setVal(myId);

	jQuery("#dialog").dialog({
					height: 590,					
					width: 775,
					hide:'slide',
					show: 'slide',
					resizable:false,
					title:"Booking",
					modal: true,
					closeOnEscape:true,
					autoOpen:false
				 	});

	jQuery("#dialog").dialog('open');
	setVal(myId);
	//if(dialogUp==1){
		
		//	jQuery("#dialog").dialog('open');
			
		//}else{

		//	jQuery("#dialog").dialog('open');
		//};
		//	dialogUp=1;
			//document.getElementById('dialog').src=myURL;
}
		

	function valMe(){
	//	alert("valme");
 var validator = $("#bookingform").validate({
 //	debug:true,

 rules: {
     
     str_firstname: "required",
     str_lastname: "required",
     from_email: {
				required: true,
				email: true
			},
     dtm_start: {
     		dateDE : true,
     		required: true
     	},
		 dtm_end:  {
     		dateDE : true,
     		required: true
     	},
     	int_persons:  {
     			digits:true
     		}
},
messages:{
	letObj: 'Velg &oslash;nsket leieobjekt',
	str_firstname: 'Oppgi fornavn',
	str_lastname: 'Oppgi etternavn',
 from_email: {
				required: "Vennligst oppgi en korrekt e-post adresse",
			  minlength: "Vennligst oppgi en korrekt e-post adresse",
			  email: "Vennligst oppgi en korrekt e-post adresse"
			},
			
	dtm_start: "Oppgi en korrekt dato i formatet dd.mm.yyyy",
	dtm_end: "Oppgi en korrekt dato i formatet dd.mm.yyyy",
		int_persons:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_cabins:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_caravans:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_apartments:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_mobile_homes:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_standplass:  {
     			digits:"Feltet aksepterer kun tall"
     		}
     	
	},
	wrapper: "div class='error'", 
	//debug:true,


  	errorPlacement: function(error, element) {
  	  
  	  //alert(element.is("#txtMessage")+ element.attr("id"));
  	  //alert(error);
			if ( element.is(":radio") ){
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ){
				error.appendTo ( element.next() );
			}else if ( element.is("#txtMessage") ){
			  error.insertBefore(element );
			  alert("textarea");
			}else{
			   error.insertBefore(element );
					error.insertAfter(element );
				}
		}
  });
}


function getElementbyClass(classname){
	ccollect=new Array()
	var inc=0
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	for (i=0; i < alltags.length; i++){
		if (alltags[i].className==classname)
		ccollect[inc++]=alltags[i]
	}
}

function contractcontent(omit){
var inc=0
//message="hhh";
while (ccollect[inc]){
	//message = message + "\n" +inc ;
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
//alert(message);
}
function expandcontent(cid){
	
	//alert(cid);
	if (typeof ccollect!="undefined"){
		//alert(cid);
		contractcontent(cid)
		theElement = findDOM(cid);
		
		if(typeof theElement!="undefined"){
			
		//document.getElementById(cid).style.display = "block" ;
		theElement.style.display = "block";
		//(document.getElementById(cid).style.display!="block")? "block" : "none"

		selectedItem = cid + "|" +document.getElementById(cid).style.display;
	}
		}

}


function revivecontent(){
	
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
alert(selectedComponents[0]);
if(selectedComponents[0] ){
	contractcontent(selectedComponents[0])
}else{

}
document.getElementById(selectedComponents[0]).style.display=selectedComponents[1]
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}
function saveswitchstate(){
if (typeof selectedItem!="undefined")
document.cookie=window.location.pathname+"="+selectedItem
}

													
//could be put in "ccms_default.js"
//maybe a "ccms_dates.js" ??

function calcToDate(fromField, numD){
		/*adding "addDays" to value in "fromField"
			an returns them in "toField"
		*/
		//milliseconds passed during a 24 hour periode..
		var one_day = 1000*60*60*24;
		
//		toField 	= findDOM(toField);
		fromField = findDOM(fromField);
		
		fDate = fromField.value; 
		tDate	= toField.value;

		var numD = parseInt(dayField.value);
 		
 		if (isNaN(numD)){
 			/*
 				value of "number of days" is not a number, try to calculate differences betweeen days in stead.
 			*/
 			
			if(isaDate(usDateFormat(fDate)) && isDate(usDateFormat(tDate))){
				fromD = new Date(usDateFormat(fDate));
				toD = new Date(usDateFormat(tDate));
				
				myDays = 	(Math.ceil(toD.getTime()-fromD.getTime())/(one_day)) + one_day;

			}else{
				alert("Sjekk datoverdier. Det virker som om ikke alt er helt korrekt.");
			}
			
		}else{
			/*
				value of "number of days" is a number, calculate days depending on 
				if we're entering data in
				- from field or
				- to field
			*/	
	
			tValue= (numD * one_day) ;
			
			fromD = new Date(usDateFormat(fDate));
			toD = new Date(usDateFormat(tDate));
		
			if(isaDate(usDateFormat(fDate))){
					calcDays = Math.ceil(fromD.getTime())+tValue ;// + one_day; removed "one_day" here.. 
			}else{
				alert("fra dato virker å være ukorrekt format. sjekk dato");
			}
		}
			
		
		if(calcDays >0){
			calcDate = new Date(calcDays);
					
			var cD = calcDate.getDate();
			var cM = Number(calcDate.getMonth())+1;
			var cY = takeYear(calcDate);

		if(cD<10){
				cD="0" + cD;
			}
			if(cM<10){
				cM="0" + cM;
			}

			newDate = cD + "." + cM +"." +cY;
			
			
			return newDate;
		}
		
	}
	
	function addDays(oldDate, addDay) { 
	
	//alert(oldDate + " - " + addDay);
	
	dArr = oldDate.split("/");
	
	// define variables
	
	var month3, month3Integer, day3, day3Integer, year3, year3Integer, addDay;
	
	//	month3Integer = form.month3.selectedIndex;
	//	day3Integer = form.day3.selectedIndex;
	//	year3Integer = form.year3.selectedIndex;
		myMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		month3 = myMonths[dArr[0]-1];
		day3 = dArr[1];
		year3 = dArr[2];
	
	// carry out the calculation of the new date
	
		var datestring1 = month3 + " " + day3 + ", " + year3 + " 04:00:00";
		
	//alert(datestring1);
	
	/*
		 The above line creates a string representing 4am on the date specified.  It is necessary
		 to add in the time (say 4am, or any time after 1am) because otherwise there is a bug
		 when adding a number of days which takes the result over the change of clocks
		 (ie. one hour forward in the spring or one hour back in the autumn).  If the time is simply
		 left at midnight and the starting date is in BST but the ending date is in GMT, then
		 the ending date produced will be one day behind as it will be 23:00 on the evening
		 BEFORE the date which it ought to be.  Another way of solving the problem would be
		 to use the Date.getUTCdate method throughout, but this was only implemented in
		 JavaScript 1.3 and therefore would not work with earlier versions..
	*/
	
	datestring1 = Date.parse(datestring1);
	
	var datestring2 = (datestring1 + (addDay*24*60*60*1000));
	
	datestring2 = new Date(datestring2);
	//alert(datestring2);
	
	
	// extract individual day, month, year, and day of week from result date
	var dayofweekarray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var montharray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var resultyear=datestring2.getFullYear();
		// The new method getFullYear in the above line was implemented in JavaScript 1.3
		// and returns the full four-digit year.  There is therefore no need for the special Y2K fixes in
		// the four commented-out lines below.
		// if ((navigator.appName == "Microsoft Internet Explorer") && (resultyear < 2000))  // Y2K Fix	
		// resultyear="19" + resultyear;
		// if (navigator.appName == "Netscape")
		// resultyear=1900 + resultyear;
	
	var resultmonth=datestring2.getMonth();
	monthNum =resultmonth+1;
	resultmonth = montharray[resultmonth];
	 
	var resultday=datestring2.getDate();
	var resultdayofweek=datestring2.getDay();
	resultdayofweek = dayofweekarray[resultdayofweek];
	
	var resultday = resultday ;
	return(resultday + "." + monthNum +"." + resultyear);
	// write the results into the form
	//form.endingdate2.value = resultdayofweek + ", " + resultmonth + " " + resultday + ", " + resultyear;

}

//ccms_standard.js
function change_img(newimg,url){
//	alert(url);
	myImg=findDOM("theImage");
	
	myImg.src= url + "images/upload/350/" + newimg;
}
	
//#getRadioValue?
function radioValue(fieldName, fieldLabel ) {
	myValue = fieldName.options[fieldName.selectedIndex].value;
	fieldValue   = fieldName.options[fieldName.selectedIndex].value;
	return fieldValue;
}

function getCheckedValue(radioName) {
	radioObj = document.getElementsByName(radioName);
	
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	//alert(radioLength);
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioName, newValue) {
	radioObj = document.getElementsByName(radioName);
	
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function usDateFormat(dVal){
	/*
		mottar dd.mm.yyyy
		returnerer mm/dd/yyy
	*/
	
	var dArr = new Array();
	dArr = dVal.split(".");
	
	retVal = dArr[1]+"/"+dArr[0]+"/"+dArr[2];
	//for(i=0;i<dArr.le
	//alert(dVal + "\n" + retVal);
	//alert(dArr.length);
	
	return retVal;
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}


function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


function isaDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

	

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


/*
 * Date prototype extensions. Doesn't depend on any
 * other code. Doens't overwrite existing methods.
 *
 * Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear,
 * isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear,
 * setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods
 *
 * Copyright (c) 2006 JÃ¶rn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 *
 * Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString -
 * I've added my name to these methods so you know who to blame if they are broken!
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * An Array of day names starting with Sunday.
 * 
 * @example dayNames[0]
 * @result 'Sunday'
 *
 * @name dayNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

/**
 * An Array of abbreviated day names starting with Sun.
 * 
 * @example abbrDayNames[0]
 * @result 'Sun'
 *
 * @name abbrDayNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

/**
 * An Array of month names starting with Janurary.
 * 
 * @example monthNames[0]
 * @result 'January'
 *
 * @name monthNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

/**
 * An Array of abbreviated month names starting with Jan.
 * 
 * @example abbrMonthNames[0]
 * @result 'Jan'
 *
 * @name monthNames
 * @type Array
 * @cat Plugins/Methods/Date
 */
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];


// date localization for locale 'se'
// generated by Gabriel Svennerberg | www.svennerberg.com
Date.dayNames = ['Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'];
Date.abbrDayNames = ['Sø', 'Ma', 'Ti', 'On', 'To', 'Fr', 'Lø'];
Date.monthNames = ['Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'];
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'];


/**
 * The first day of the week for this locale.
 *
 * @name firstDayOfWeek
 * @type Number
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.firstDayOfWeek = 1;

/**
 * The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc).
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.format = 'dd/mm/yyyy';
//Date.format = 'mm/dd/yyyy';
//Date.format = 'yyyy-mm-dd';
//Date.format = 'dd mmm yy';

/**
 * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
 * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.fullYearStart = '20';

(function() {

	/**
	 * Adds a given method under the given name 
	 * to the Date prototype if it doesn't
	 * currently exist.
	 *
	 * @private
	 */
	function add(name, method) {
		if( !Date.prototype[name] ) {
			Date.prototype[name] = method;
		}
	};
	
	/**
	 * Checks if the year is a leap year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isLeapYear();
	 * @result true
	 *
	 * @name isLeapYear
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isLeapYear", function() {
		var y = this.getFullYear();
		return (y%4==0 && y%100!=0) || y%400==0;
	});
	
	/**
	 * Checks if the day is a weekend day (Sat or Sun).
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekend();
	 * @result false
	 *
	 * @name isWeekend
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekend", function() {
		return this.getDay()==0 || this.getDay()==6;
	});
	
	/**
	 * Check if the day is a day of the week (Mon-Fri)
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekDay();
	 * @result false
	 * 
	 * @name isWeekDay
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekDay", function() {
		return !this.isWeekend();
	});
	
	/**
	 * Gets the number of days in the month.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDaysInMonth();
	 * @result 31
	 * 
	 * @name getDaysInMonth
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDaysInMonth", function() {
		return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
	});
	
	/**
	 * Gets the name of the day.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName();
	 * @result 'Saturday'
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName(true);
	 * @result 'Sat'
	 * 
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getDayName", function(abbreviated) {
		return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
	});

	/**
	 * Gets the name of the month.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName();
	 * @result 'Janurary'
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName(true);
	 * @result 'Jan'
	 * 
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getMonthName", function(abbreviated) {
		return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
	});

	/**
	 * Get the number of the day of the year.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayOfYear();
	 * @result 11
	 * 
	 * @name getDayOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDayOfYear", function() {
		var tmpdtm = new Date("1/1/" + this.getFullYear());
		return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
	});
	
	/**
	 * Get the number of the week of the year.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getWeekOfYear();
	 * @result 2
	 * 
	 * @name getWeekOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getWeekOfYear", function() {
		return Math.ceil(this.getDayOfYear() / 7);
	});

	/**
	 * Set the day of the year.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.setDayOfYear(1);
	 * dtm.toString();
	 * @result 'Tue Jan 01 2008 00:00:00'
	 * 
	 * @name setDayOfYear
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("setDayOfYear", function(day) {
		this.setMonth(0);
		this.setDate(day);
		return this;
	});
	
	/**
	 * Add a number of years to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addYears(1);
	 * dtm.toString();
	 * @result 'Mon Jan 12 2009 00:00:00'
	 * 
	 * @name addYears
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addYears", function(num) {
		this.setFullYear(this.getFullYear() + num);
		return this;
	});
	
	/**
	 * Add a number of months to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMonths(1);
	 * dtm.toString();
	 * @result 'Tue Feb 12 2008 00:00:00'
	 * 
	 * @name addMonths
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMonths", function(num) {
		var tmpdtm = this.getDate();
		
		this.setMonth(this.getMonth() + num);
		
		if (tmpdtm > this.getDate())
			this.addDays(-this.getDate());
		
		return this;
	});
	
	/**
	 * Add a number of days to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addDays(1);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 * 
	 * @name addDays
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addDays", function(num) {
		//this.setDate(this.getDate() + num);
		this.setTime(this.getTime() + (num*86400000) );
		return this;
	});
	
	/**
	 * Add a number of hours to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addHours(24);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 * 
	 * @name addHours
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addHours", function(num) {
		this.setHours(this.getHours() + num);
		return this;
	});

	/**
	 * Add a number of minutes to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMinutes(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 01:00:00'
	 * 
	 * @name addMinutes
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMinutes", function(num) {
		this.setMinutes(this.getMinutes() + num);
		return this;
	});
	
	/**
	 * Add a number of seconds to the date object.
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addSeconds(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 * 
	 * @name addSeconds
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addSeconds", function(num) {
		this.setSeconds(this.getSeconds() + num);
		return this;
	});
	
	/**
	 * Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
	 * 
	 * @example var dtm = new Date();
	 * dtm.zeroTime();
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 * 
	 * @name zeroTime
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("zeroTime", function() {
		this.setMilliseconds(0);
		this.setSeconds(0);
		this.setMinutes(0);
		this.setHours(0);
		return this;
	});
	
	/**
	 * Returns a string representation of the date object according to Date.format.
	 * (Date.toString may be used in other places so I purposefully didn't overwrite it)
	 * 
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.asString();
	 * @result '12/01/2008' // (where Date.format == 'dd/mm/yyyy'
	 * 
	 * @name asString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("asString", function(format) {
		var r = format || Date.format;
		return r
			.split('yyyy').join(this.getFullYear())
			.split('yy').join((this.getFullYear() + '').substring(2))
			.split('mmmm').join(this.getMonthName(false))
			.split('mmm').join(this.getMonthName(true))
			.split('mm').join(_zeroPad(this.getMonth()+1))
			.split('dd').join(_zeroPad(this.getDate()));
	});
	
	/**
	 * Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
	 * (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
	 *
	 * @example var dtm = Date.fromString("12/01/2008");
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/yyyy'
	 * 
	 * @name fromString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	Date.fromString = function(s)
	{
		var f = Date.format;
		var d = new Date('01/01/1977');
		
		var mLength = 0;

		var iM = f.indexOf('mmmm');
		if (iM > -1) {
			for (var i=0; i<Date.monthNames.length; i++) {
				var mStr = s.substr(iM, Date.monthNames[i].length);
				if (Date.monthNames[i] == mStr) {
					mLength = Date.monthNames[i].length - 4;
					break;
				}
			}
			d.setMonth(i);
		} else {
			iM = f.indexOf('mmm');
			if (iM > -1) {
				var mStr = s.substr(iM, 3);
				for (var i=0; i<Date.abbrMonthNames.length; i++) {
					if (Date.abbrMonthNames[i] == mStr) break;
				}
				d.setMonth(i);
			} else {
				d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
			}
		}
		
		var iY = f.indexOf('yyyy');

		if (iY > -1) {
			if (iM < iY)
			{
				iY += mLength;
			}
			d.setFullYear(Number(s.substr(iY, 4)));
		} else {
			if (iM < iY)
			{
				iY += mLength;
			}
			// TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
			d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2)));
		}
		var iD = f.indexOf('dd');
		if (iM < iD)
		{
			iD += mLength;
		}
		d.setDate(Number(s.substr(iD, 2)));
		if (isNaN(d.getTime())) {
			return false;
		}
		return d;
	};
	
	// utility method
	var _zeroPad = function(num) {
		var s = '0'+num;
		return s.substring(s.length-2)
		//return ('0'+num).substring(-2); // doesn't work on IE :(
	};
	
})();





  function validateMe(fm){
  
	
  	
  	
    retval=false;
   if($("#bookingform").valid()){
      $("#vCh").val(2);
      retval=false;
   }
   return retval;
  }
  
 function setMinMax(input){

 		$("#dtm_end").datepicker('option', 'minDate', new Date($("#dtm_start").datepicker( 'getDate' )));
 		
 //		$("#dtm_start").datepicker('option', 'maxDate', new Date($("#dtm_end").datepicker( 'getDate' )));
 	}
  
function bookForm(){
	

$.datepicker.setDefaults({ dateFormat: 'dd.mm.yy',
														firstDay:1,
														changeYear:true,
														changeMonth:true,
														monthNames: ['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'],
														monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'],
														 dayNames: ['S&oslash;ndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'L&oslash;rdag'] ,
														 dayNamesShort: ['S&oslash;n', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'L&oslash;r'],
														 dayNamesMin: ['S&oslash;', 'Ma', 'Ti', 'on', 'To', 'Fr', 'L&oslash;'] });
	$("#dtm_start").datepicker({minDate:0,defaultDate: 0,
		
														beforeShow: function(input) {
															
																						setMinMax(input);
																						 }});
	$("#dtm_end").datepicker({minDate:0,
														defaultDate: +21,
														
														beforeShow: function(input) {
														
																						setMinMax(input);
																						 }
																						 
															});
	
	jQuery.validator.setDefaults({
	debug:true
	});


 var validator = $("#bookingform").validate({
 	debug:true,

 rules: {
     
     str_firstname: "required",
     str_lastname: "required",
     from_email: {
				required: true,
				email: true
			},
     dtm_start: {
     		dateDE : true,
     		required: true
     	},
		 dtm_end:  {
     		dateDE : true,
     		required: true
     	},
     	int_persons:  {
     			digits:true
     		},
     	int_cabins:  {
     			digits:true
     		},
     	int_caravans:  {
     			digits:true
     		},
     	int_apartments:  {
     			digits:true
     		},
     	int_mobile_homes:  {
     			digits:true
     		},
     	int_standplass:  {
     			digits:true
     		}
     	
},
messages:{
	str_firstname: 'Nødvendig felt: Fornavn',
	str_lastname: 'Nødvendig felt: Etternavn',
 from_email: {
				required: "Nødvendig felt: Oppgi en korrekt e-post adresse",
			  minlength: "Vennligst oppgi en korrekt e-post adresse",
			  email: "Vennligst oppgi en korrekt e-post adresse"
			},
			
	dtm_start: "Oppgi en korrekt dato i formatet dd.mm.yyyy",
	dtm_end: "Oppgi en korrekt dato i formatet dd.mm.yyyy",
		int_persons:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_cabins:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_caravans:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_apartments:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_mobile_homes:  {
     			digits:"Feltet aksepterer kun tall"
     		},
     	int_standplass:  {
     			digits:"Feltet aksepterer kun tall"
     		}
     	
	},
  	errorPlacement: function(error, element) {
  	  
  	  //alert(element.is("#txtMessage")+ element.attr("id"));
  	 // alert(error);
			if ( element.is(":radio") ){
				error.appendTo( element.parent().next().next() );
			}else if ( element.is(":checkbox") ){
				error.appendTo ( element.next() );
			//}else if ( element.is("#txtMessage") ){
			 // error.insertBefore(element );
			  //alert("textarea");
			}else{
			  // error.insertBefore(element );
				error.insertAfter( element );
				}
		},
		// specifying a submitHandler prevents the default submit, good for the demo
	/*	submitHandler: function() {
			alert("submitted!");
		},*/
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
  });
    
  };  
  
  $.maxZIndex = $.fn.maxZIndex = function(opt) {
    /// <summary>
    /// Returns the max zOrder in the document (no parameter)
    /// Sets max zOrder by passing a non-zero number
    /// which gets added to the highest zOrder.
    /// </summary>    
    /// <param name="opt" type="object">
    /// inc: increment value, 
    /// group: selector for zIndex elements to find max for
    /// </param>
    /// <returns type="jQuery" />
    var def = { inc: 10, group: "*" };
    $.extend(def, opt);
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
    });
}
