// JavaScript Document
function IsEmail(emailStr){
  var regex =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{1,}[.][a-z]{2,4}$/
  return (regex.exec(emailStr)!=null)
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v5.0
  var i,p,q,nm,nm1,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; ed=args[i+1];val1=val; if ((val=val.value)!=""){
      if (test.indexOf('isEmail')!=-1) {
        if (!IsEmail(val)) errors+='- '+ed+'\n';
      }else if (test.indexOf('isChecked')!=-1){// val1=boxens navn - ed=alert , ex. "'mybox','Kryds af!','RisChecked'
           if(!val1.checked) errors+='- '+ed+'\n';
      }else if (test.indexOf('isSelect')!=-1){// val1=boxens navn - ed=alert , ex. "'myList','Vælg!','RisSelect'
           if(!val1.selectedIndex) errors+='- '+ed+'\n';
      }else if (test!='R'){ 
         num = parseFloat(val);
          if (isNaN(val)) errors+='- '+ed+'\n';
          if (test.indexOf('inRange') != -1) { 
            p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+ed+'\n';
          } 
      }
    }else if(test.charAt(0) == 'R') errors += '- '+ed+'\n'; }
	//alert(test)
} 
  if (errors) alert('!!!\n'+errors);
  document.MM_returnValue = (errors == '');
}

function ncms_getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
    } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
    } else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
    } 
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
		pageHeight = windowHeight;
    } else { 
		pageHeight = yScroll;
    }
    
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){ 
		pageWidth = windowWidth;
    } else {
		pageWidth = xScroll;
    }
    
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

function ncms_getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;    
    }
    arrayPageScroll = new Array(xScroll,yScroll);
    return arrayPageScroll;
}

function getQuerystringKey(key) { // optionally pass a querystring to parse
    qs = null//alert(key)
    if (qs == null)
        qs=window.location.search.substring(1,window.location.search.length);
    if (qs.length == 0) return "";
    
// Turn <plus> back to <space>
    qs = qs.replace(/\+/g, ' ')
    var args = qs.split('&') // parse out name/value pairs separated via &
// split out each name=value pair
    for (var i=0;i<args.length;i++) {
        var value;
        var pair = args[i].split('=')
        var name = unescape(pair[0])

        if (pair.length == 2)
            value = unescape(pair[1])
        else
            value=""
        if (name==key)
         return value
    }
    return ""
}

function goToUrl(tUrl){
    document.location.href=tUrl;
}
function goAway(tUrl){
	window.open(tUrl,'','');
}
function leaveSite(tUrl){
	goAway(tUrl);
}

function showHideDiv(obj){
    if(document.getElementById(obj).style.display==""){
        document.getElementById(obj).style.display="none"
    }else{
        document.getElementById(obj).style.display=""
		if((navigator.userAgent.indexOf("MSIE 7")>0)&&(document.getElementById("overlay").style.display=="")){ // IE 7 Z-index virker ikke overlay'et kommer over div'en 
			var bar = document.getElementById(obj); 
			document.body.appendChild(bar); 
			document.getElementById(obj).style.left=(document.body.clientWidth/2)-(parseInt(document.getElementById(obj).style.width)/2)+"px"
			document.getElementById(obj).style.zIndex=1000
		}
    }
}

function submitThisForm(fName){
    document[fName].submit();
}

function bigImageStr(imgStr){
	newImgStr=imgStr.replace('_m.jpg','_b.jpg')
	newImgStr=newImgStr.replace('_s.jpg','_b.jpg')
	newImgStr=newImgStr.replace('/micro/','/')
 	return newImgStr
}
function showDetailImage(imgStr,thisDiv){
	try{document.getElementById("detailImageContainer").src=bigImageStr(imgStr)}catch(imgStr){}
}
function showDetailImageGallery(imgStr,thisDiv){
	try{document.getElementById("detailImageContainer").src=bigImageStr(imgStr)}catch(imgStr){}
	changeClass('thumbGalleryImage',thisDiv,'active','notactive')
}

/////// OVERLAY ///////
function showOverlay(){
    ncms_getPageSize()
    document.getElementById("overlay").style.display=""
    document.getElementById("overlay").style.height=arrayPageSize[1]+"px"
    document.getElementById("overlay").style.filter = "alpha(opacity=60)";
    document.getElementById("overlay").style.opacity = "0.6";
}
function hideOverlay(){
    document.getElementById("overlay").style.display="none"
}
///////////////////////

