rowfix=0;

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){
	myImg=findDOM("theImage");
	
	myImg.src= "/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";
  }
}
