var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function getElement(aID)
{
    return (document.getElementById) ? document.getElementById(aID) : document.all[aID];
}
function getIFrameDocument(aID) {
    var rv = null;
    var frame=getElement(aID);
    // if contentDocument exists, W3C compliant (e.g. Mozilla)
    if (frame.contentDocument)
        rv = frame.contentDocument;
    else // bad Internet Explorer  ;)
        rv = document.frames[aID].document;
    return rv;
}
function adjustFrameHeight(nomeframe) {
    var frame = getElement(nomeframe);
    var frameDoc = getIFrameDocument(nomeframe);
//    alert('frame.height= '+frame.height+', frameDoc.body.offsetHeight= '+frameDoc.body.offsetHeight);
//    alert('frameDoc.body.scrollHeight= '+frameDoc.body.scrollHeight);
//    frame.height = frameDoc.body.offsetHeight;
    frame.height = frameDoc.body.scrollHeight+FFextraHeight;
}



var raampje, xtra, ytra;
function sleepen(divid) {
  if (event.button!=1)return;
  raampje = eval(divid);
  temp1=raampje.style.posLeft;
  temp2=raampje.style.posTop;
  window.status='temp1left= '+temp1+', temp2top= '+temp2;
  xpos=event.clientX;
  ypos=event.clientY;
  xtra = temp1-xpos;
  ytra = temp2-ypos;
  raampje.style.cursor='move';
  document.onmousemove=plaats;
}
function plaats(){
  if (event.button==1){
    raampje.style.pixelLeft=event.clientX+xtra;
    raampje.style.pixelTop=event.clientY+ytra;
//    raampje.style.pixelLeft=event.clientX;
//    raampje.style.pixelTop=event.clientY;
    return false;
  }
}

//============================================================
//Capturing The Mouse Position in IE4-6 & NS4-6
//(C) 2000 www.CodeLifter.com
//Free for all users, but leave in this  header
//-->

//Part One:
//Set up a form named "Show" with text fields named "MouseX"
//and "MouseY".  Note in the getMouseXY() function how fields
//are addressed, thus: document.FormName.FieldName.value


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove


//document.onmousemove = getMouseXY;



// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
//  document.Show.MouseX.value = tempX
//  document.Show.MouseY.value = tempY
 
  return true
}



function setSizeMenu() {
  topmenu=document.getElementById("top_menu_container");
  topmenu.style.width="814px";
}

function getSearch() {
	nrs=document.getElementById("navigation_right_search");
	if (nrs) {
		//if (nrs.style.display!="none") return opensearch(document.f_search.search.value);
		if (nrs.style.display!="none") nrs.style.display="none";
		else if (nrs.style.display=="none") nrs.style.display="block";
	}
}

function popupgen(type, sWidth, sHeight) {
	nrs=document.getElementById("popup_gen");
	if (nrs) {
		//if (nrs.style.display!="none" && nrs.style.display!="") {
//			nrs.src.reload();
		//	nrs.style.display="none";
		//}
		//else if (nrs.style.display=="none" || nrs.style.display=="") {
			nrs.style.display="block";
			nrs.style.width=(parseInt(sWidth)+2)+'px';
			var addThisHeight=0 
			if (navigator.userAgent.indexOf("Chrome")>-1) addThisHeight=(type=='fwdcmp' ? 61:(type=='cntcmp' ? -44:16)) //61
			else if (navigator.userAgent.indexOf("Firefox")>-1) addThisHeight=(type=='fwdcmp' ? 77:(type=='cntcmp' ? -59:12))
			else if (navigator.userAgent.indexOf("Safari")>-1) addThisHeight=(type=='fwdcmp' ? 76:(type=='cntcmp' ? -44:16))
			else if (navigator.userAgent.indexOf("Opera")>-1) addThisHeight=(type=='fwdcmp' ? -11:(type=='cntcmp' ? 0:0))
			//alert(navigator.userAgent+' - '+addThisHeight)
			//var addThisHeight=36
			//if (navigator.userAgent.indexOf("Chrome")>0) addThisHeight=(type=='fwdcmp' ? 61:(type=='cntcmp' ? 0:36))
			//else if (navigator.userAgent.indexOf("Firefox")>0) addThisHeight=(type=='fwdcmp' ? 77:(type=='cntcmp' ? 0:36))
			//else if (navigator.userAgent.indexOf("Safari")>0) addThisHeight=(type=='fwdcmp' ? 76:(type=='cntcmp' ? 0:36))
			nrs.style.height=(parseInt(sHeight)+addThisHeight)+'px';			
		//}
	}
}

function hidepopupgen() {
	nrs=document.getElementById("popup_gen");
	if (nrs) {nrs.style.display="none"}
}

function changeframesource(type, cWidth, cHeight) {
	ifr=document.getElementById("frame_gen");
	docFra=getIFrameDocument("frame_gen");
	bodFra=docFra.getElementsByTagName("body")[0];
	bodFra.style.width=cWidth+'px';
	bodFra.style.height=cHeight+'px';
	bodFra.style.background="#FFFFFF";
	bodFra.style.visibility="hidden";
	ifr.src=strLeft(ifr.src, '&type=')+'&type='+type;
	ifr.height=cHeight+'px';
	//ifr.height='450px';
	ifr.width=cWidth+'px';
	popupgen(type, cWidth, cHeight);
}

function getUrl() {return document.location.href}

/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var dragobject={
	z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
	initialize:function(){
		document.onmousedown=this.drag
		document.onmouseup=function(){this.dragapproved=0}
	},
	drag:function(e){
		var evtobj=window.event? window.event : e
		this.targetobj=window.event? event.srcElement : e.target
		if (this.targetobj.className=="drag"){
			this.dragapproved=1
			if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
			if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
			this.offsetx=parseInt(this.targetobj.style.left)
			this.offsety=parseInt(this.targetobj.style.top)
			this.x=evtobj.clientX
			this.y=evtobj.clientY
			if (evtobj.preventDefault)
				evtobj.preventDefault()
			document.onmousemove=dragobject.moveit
		}
	},
	moveit:function(e){
		var evtobj=window.event? window.event : e
		if (this.dragapproved==1){
			this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
			this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
			return false
		}
	}
}
dragobject.initialize()
//*******************************

//Author: Phillip Roberts - phillroberts@yahoo.com
//Released under GNU General Public License : http://www.gnu.org/copyleft/gpl.html


//@Left equivalent
function strLeft(sourceStr, keyStr){
return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : sourceStr.split(keyStr)[0];
}

//@Right equivalent
function strRight(sourceStr, keyStr){
idx = sourceStr.indexOf(keyStr);
return (idx == -1 | keyStr=='') ? '' : sourceStr.substr(idx+ keyStr.length);
}

//@RightBack equivalent
function rightBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr);
return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop()
}

//@LeftBack equivalent
function leftBack(sourceStr, keyStr){
arr = sourceStr.split(keyStr)
arr.pop();
return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr)
}

//@Middle equivalent
function middle(sourceStr, keyStrLeft, keyStrRight){ 
return strLeft(strRight(sourceStr,keyStrLeft), keyStrRight);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["sldimg","frame_gen"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
   var dyniframe=new Array()
   for (i=0; i<iframeids.length; i++) {
      if (document.getElementById)
         resizeIframe(iframeids[i])
         //reveal iframe for lower end browsers? (see var above):
      if ((document.all || document.getElementById) && iframehide=="no") {
         var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
         tempobj.style.display="block"
      }
   }
}

function resizeIframe(frameid) {
   var currentfr=document.getElementById(frameid)
   if (currentfr && !window.opera) {
      currentfr.style.display="block"
//      alert(currentfr.height);
      if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {//ns6 syntax
         currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
//			adjustParentDivHeight(currentfr.contentDocument.body.offsetHeight+FFextraHeight);
//         alert(currentfr.contentDocument.body.offsetHeight+FFextraHeight);
      } else if (currentfr.Document && currentfr.Document.body.scrollHeight) {//ie5+ syntax
         currentfr.height = currentfr.Document.body.scrollHeight;
//			adjustParentDivHeight(currentfr.Document.body.scrollHeight);
//         alert(currentfr.Document.body.scrollHeight);
      }
      if (currentfr.addEventListener)
         currentfr.addEventListener("load", readjustIframe, false)
      else if (currentfr.attachEvent) {
         currentfr.detachEvent("onload", readjustIframe) // Bug fix line
         currentfr.attachEvent("onload", readjustIframe)
      }

   }
}


function readjustIframe(loadevt) {
   var crossevt=(window.event)? event : loadevt
   var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
   if (iframeroot)
      resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url) {
   if (document.getElementById)
   document.getElementById(iframeid).src=url
}

if (window.addEventListener)
   window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
   window.attachEvent("onload", resizeCaller)
else
   window.onload=resizeCaller

function adjustDivHeight(divid) {
 //   alert('adjustDivHeight('+divid+')');
    divele=document.getElementById(divid);
	 if (!divele) return false;
    offHgt=parseInt(document.body.offsetHeight);
	//alert(offHgt)
    //winHgt=getSize('mh');
    //if (offHgt>winHgt) return false;
    //offHgt=(winHgt-offHgt);
    divele.style.height=offHgt+'px';
}
function getSize(what) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (what=='mw') return myWidth;
  if (what=='mh') return myHeight;
}	
	
function closePopup(idPopup) {
   objPopup=document.getElementById(idPopup);
   //adjustDivHeight(idPopup);
   objPopup.style.display='none';
}


function ajaxReq(url, divId, objForm) {
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				if ((xmlhttp.responseText).indexOf("##close##")>-1) {
//					if ((xmlhttp.responseText).length>10) {
	
						tempDiv=document.getElementById(divId)
						tempDiv.style.display='block'
						tempDiv.innerHTML=xmlhttp.responseText.replace("##close##","");
						//alert(xmlhttp.responseText.replace("##close##",""))
						//tempDiv.style.display='none'"
//					} else {

						setTimeout("parent.closePopup('popup_gen')", 4000)	
//					}
					return false;
				}
				tempDiv=document.getElementById(divId)
				tempDiv.style.display='block'
				tempDiv.innerHTML=xmlhttp.responseText;
				
				setTimeout("tempDiv.style.display='none'",3000)
			}
		}
	aParam=''
	if (objForm) {
		aParam='&'+formData2QueryString(objForm);
		//xmlhttp.open("POST",url,true);
		//xmlhttp.send(aParam);
		xmlhttp.open("GET",url+aParam,true);
		xmlhttp.send(null);
	} else {
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	//prompt("url Check", url+aParam)
}

function formData2QueryString(docForm) {
		
  var submitContent = '';
  var formElem;
  var lastElemName = '';
		
  for (i = 0; i < docForm.elements.length; i++) {
		
    formElem = docForm.elements[i];
	switch (formElem.type) {
      // Text fields, hidden form elements
      case 'text':
      case 'hidden':
      case 'password':
      case 'textarea':
      case 'select-one':
        submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        break;
		
      // Radio buttons
      case 'radio':
        if (formElem.checked) {
          submitContent += formElem.name + '=' + escape(formElem.value) + '&'
        }
        break;
		
      // Checkboxes
      case 'checkbox':
	     if (formElem.checked) {
          // Continuing multiple, same-name checkboxes
          if (formElem.name == lastElemName) {
            // Strip of end ampersand if there is one
            if (submitContent.lastIndexOf('&') == submitContent.length-1) {
              submitContent = submitContent.substr(0, submitContent.length - 1);
            }
            // Append value as comma-delimited string
            submitContent += ',' + escape(formElem.value);
          }
	     else {
            submitContent += formElem.name + '=' + escape(formElem.value);
          }
          submitContent += '&';
          lastElemName = formElem.name;
        }
        break;
    }
  }
  // Remove trailing separator
  submitContent = submitContent.substr(0, submitContent.length - 1);
  return submitContent;
}

function changeLanguage(sLan) {
	sUrl=getUrl();
	sLft=strLeft(sUrl,'lng/')+'lng/'
	sRgt='/'+strRight(strRight(sUrl,'lng/'),'/')
	//alert('sUrl='+sUrl+'\n sNewUrl= '+sLft+sLan+sRgt)
	location.href=sLft+sLan+sRgt;
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function ajaxBrochure(psp)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var ajaxDisplay;
	try{ajaxRequest = new XMLHttpRequest(); // Opera 8.0+, Firefox, Safari
	} catch (e){
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			oDiv=parent.document.getElementById("divbro");
			oDiv.style.display='block'
			oDiv.innerHTML=ajaxRequest.responseText;
		}
	}
	var loc = ((parent.location.href).split(".nsf"))[0]+'.nsf'
	var now = new Date()
	var url=loc+"/(WEB_ALL_GETBRO_010)?openagent&psp="+psp+"&"+now.getTime()
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}


function getWindowSize(what) {
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth-16;
  winH = window.innerHeight-16;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth-20;
  winH = document.body.offsetHeight-20;
 }
 if (what=='W') return winW;
 if (what=='H') return winH;
}
}

/*
function searchActiveAnchor() {
	allActiveAnchor=getElementsByClass("highslide-active-anchor",document,"A")
	if (allActiveAnchor[0].innerHTML.indexOf('ajaxBrochure(')>-1) {
		//alert(allActiveAnchor[0].getAttribute('name'))
	}
}
*/
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

$(document).ready(function() {
	$('#FieldMap').css('width', '100%');
	$('#FieldMap th').addClass('ui-accordion-header ui-state-default ui-corner-all');
	$('#FieldMap td').addClass('ui-widget-content');
	$('#FieldMap tbody tr').mouseover(function() {
		$(this).children().addClass('ui-state-hover');
	});
	$('#FieldMap tbody tr').mouseout(function() {
		$(this).children().removeClass('ui-state-hover');
	});
});
