// **************** Add/Remove report  **************************************
function updateReport(CenterID,action){

 var cidParam     = document.getElementById('CenterID');
 var actParam     = document.getElementById('Action');
 var reportForm   = document.getElementById('addReport');

 cidParam.value=CenterID; 
 actParam.value=action;
 
 reportForm.submit();
 return true;
}
function disableHilite(){
  var dObj=document.getElementById("hiliteRepCID");
  dObj.className="noclass";
}
function enableHilite(){
  var dObj=document.getElementById("hiliteRepCID");
  dObj.className="blink";
}
function hilite(alertText){
  
  if(alertText){
   showPopup();
  }
  var i=0;
  while ( i <= 8){
    setTimeout("enableHilite()",i*500+1000);
    setTimeout("disableHilite()",(i+1)*500+1000);
  i=i+2;
  }
}

// **************** PopUp vindue  **************************************

function hidePopup() {
	document.getElementById('popup').style.visibility = 'hidden';
}
function showPopup() {
	document.getElementById('popup').style.visibility = 'visible';
}

//  ***************  Order report sidebar, validate input *********************
function validateForm(){
 var Name=document.getElementById('name');
 var Phone=document.getElementById('phone');
 var Email=document.getElementById('email');
 var Workstations=document.getElementById('workstations');
 
 var errName=document.getElementById('errName');
 var errPhone=document.getElementById('errPhone');
 var errMail=document.getElementById('errMail');
 var errNotValidMail=document.getElementById('errNotValidMail');
 var errWorkstations=document.getElementById('errWorkstations');
 
 if (''==Name.value){
 alert (errName.value);
 return false;
 }
 
 if ( ! phoneOK(Phone.value) ){
 alert (errPhone.value);
 return false;
 }
 if (''==Email.value){ // or invalid email
 alert (errMail.value);
 return false;
 }
 if (!isEmailAddress_nl(Email.value)){
 alert (errNotValidMail.value);
 return false;
 }

 if ('0'==Workstations.value){
 alert (errWorkstations.value);
 return false;
 } 

 return true;
 
}

function phoneOK(strPhone){
	if(strPhone == '') return false;
	if(strPhone.length < 6) return false;
	return true;
}

var sBadCharacters = " ;,|:()[]{}&\'\"\\/"

function isEmailAddress_nl(strEmail){
	var fRes;
	var i;
	var iLength;
	
	// Extra check for 2 @:
	if(strEmail.indexOf("@") != strEmail.lastIndexOf("@"))
		return false;
	if(strEmail.lastIndexOf(".") == strEmail.length-1 || strEmail.indexOf(".") == 0)
		return false;
	
	fRes = strEmail.length > 5;
	if(fRes){
		i = strEmail.indexOf("@");
		fRes = i > 0;
		if(fRes){
			
			i = strEmail.indexOf(".", i + 2);	//Second level domain must be at least 1 characters (2?).
			fRes = i > 0;
			if(fRes){
				fRes = strEmail.length-1 > i + 1; // Top level domain must be at least 2 characters.
				// Now check for various disallowed characters:
				iLength = sBadCharacters.length;
				i = 0;
				while(fRes && i < iLength){
					fRes = strEmail.indexOf( sBadCharacters.substr(i,1)) == -1;
					i++;
				}
			
			}
		}
	}
	return fRes;
}



//  ***************  OfficeC. profiele view open image in window *************

function o(p, w, h, name) {
	MyWindow=window.open('http://matchoffice.dk/fileadmin/scripts/pic.php?p='+p+'&w='+w+'&h='+h, name ,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width='+w+', innerWidth='+w+', height='+h);
}

//  *************** Open page in 500x500 window *************

function openpage(url,name) {
       MyWindow=window.open(url,'','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=500, innerWidth=500, height=500, innerHeight=500');

}

//  ***************  Q and A sidebar ********************************************

function startList() {
	navRoot = document.getElementById("frontqa");
	if (!navRoot){navRoot = document.getElementById("qa");}
	if (!navRoot){return;}
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="DIV") {
			node.className="closed";
			node.title = "Vis svar";
			node.onclick=function() {
				if (this.className == "closed") {
					this.className="open";
					this.title = "Skjul svar";
				} else {
					this.className="closed";
					this.title = "Vis svar";
				}
			}
		}
	}
}
window.onload = function(){
	startList();
	if (window.loadMap) {
		loadMap();
	}
	
}