//toont in content een popup image
function showmodal(url){
   try{
      my_window = window.open (url,"mywindow","menubar=1,resizable=1,location=1,status=1,scrollbars=1,width=400,height=600");
      my_window.moveTo(0,0);
   }catch(err){
      alert(err);
   }
}
//sluiten van een popup scherm
function closepopup(newvalue){
   try{
      var strField = querySt("field");
      if(strField != ''){
         window.opener.document.getElementById(strField).value = newvalue;
      }
      self.close();
   }catch(err){
      alert(err);
   }
}
//is onderdeel van closepopup
function querySt(ji){
   hu = window.location.search.substring(1);
   gy = hu.split("&");
   for (i=0;i<gy.length;i++) {
      ft = gy[i].split("=");
      if (ft[0] == ji) {
         return ft[1];
      }
   }
   return '';
}

//use the code below to retrieve a cookie
//var value = getCookie("Name");  //enter the name of the cookie
//use the code below to set a cookie
//setCookie("Name", "Value", 365);  //enter cookie name and value and # of days to remain set
function setCookie(name, value, days) {
   var exp = new Date();
   exp.setTime(exp.getTime() + 24 * 60 * 60 * days * 1000);
   document.cookie = name+"="+value+"; expires="+exp.toGMTString();
}

function getCookie(name) {
   if (document.cookie) {
      var temp = document.cookie.split(";");
      var cookies = new Array(temp.length);
      for (j=0; j<temp.length; ++j) {
         cookies[j] = temp[j].split("=");
      }
      for (j in cookies) {
         if (cookies[j][0].substr(0,1) == " ") {
            cookies[j][0] = cookies[j][0].replace(/ /,"");
         }
         if (cookies[j][1].substr(0,1) == " ") {
            cookies[j][1] = cookies[j][1].replace(/ /,"");
         }
      }
      for (j in cookies) {
         if (cookies[j][0] == name) {
            var cooval = cookies[j][1];
         }
      }
      return cooval;
   } else {
      return null;
   }
}

function setContentAction(strPage,strPageseq ,strModuleseq ,strPageAction ){
   if(document.frmCnt1){
      document.frmCnt1.elements['pageid'].value = strPage;
      document.frmCnt1.elements['pageseq'].value = strPageseq;
      document.frmCnt1.elements['moduleseq'].value = strModuleseq ;
      document.frmCnt1.elements['pageAction'].value = strPageAction ;
      document.frmCnt1.action = document.frmCnt1.action+'index.html#'+strPage+'_'+strModuleseq;
      document.frmCnt1.submit();
   }else{
      alert('no form found');
   }
}
// strPage,strPageseq, strDatetime, strDatetimeStart,strDatetimeEnd ,
function setAgendaAction(strType, strPageAction, strYear ){
   if(document.frmAg1){
      document.frmAg1.elements['mType'].value = strType;
      document.frmAg1.elements['pageAction'].value = strPageAction ;
      if('' != strYear ){
         document.frmAg1.elements['tbl_datetimeStart'].value = strYear+'-01-01' ;
         document.frmAg1.elements['tbl_datetimeEnd'].value = strYear+'-12-31' ;
      }
      document.frmAg1.submit();
   }else{
      alert('no form found');
   }
}

function setActionlistAction(strType, strPage,strSeq ,strDatum ,strPageAction ){
   if(document.frmAct1){
      if("Search" == strPageAction){
         if(document.frmAct1.elements['search'].value == ''){
            document.frmAct1.elements['search'].value = ' ';
         }
      }
      document.frmAct1.elements['mType'].value = strType;
      document.frmAct1.elements['pageid'].value = strPage;
      document.frmAct1.elements['moduleseq'].value = strSeq;
      if('' != strDatum)
         document.frmAct1.elements['datum'].value = strDatum ;
      document.frmAct1.elements['pageAction'].value = strPageAction ;
      document.frmAct1.submit();
   }else{
      alert('no form found');
   }
}

function setImporttextAction(strPageAction ){
   if(document.frmtext){
      document.frmtext.elements['pageAction'].value = strPageAction ;
      document.frmtext.submit();
   }else{
      alert('no form found');
   }
}

function setNewsAction(strType, strPageAction ){
   if(document.frmNews){
      document.frmNews.elements['mType'].value = strType;
      document.frmNews.elements['pageAction'].value = strPageAction ;
      document.frmNews.submit();
   }else{
      alert('no form found');
   }
}

function setProductAction(strPage,strMenueseq ,strModuleseq ,strPageAction ){
   if(document.frmPrd1){
      document.frmPrd1.elements['pageid'].value = strPage;
      document.frmPrd1.elements['pageseq'].value = strMenueseq ;
      document.frmPrd1.elements['moduleseq'].value = strModuleseq ;
      document.frmPrd1.elements['pageAction'].value = strPageAction ;
      document.frmPrd1.submit();
   }else{
      alert('no form found');
   }
}

function setImageUploadAction(strType,strModuleseq, strPageAction ){
   if(document.frmImage){
      document.frmImage.elements['mType'].value = strType;
      document.frmImage.elements['moduleseq'].value = strModuleseq ;
      document.frmImage.elements['pageAction'].value = strPageAction ;
      document.frmImage.submit();
   }else{
      alert('no form found');
   }
}
//------------------------------------------------------------------------------
// Maak een popup met daarin de Google Maps applicatie
//------------------------------------------------------------------------------

function routePopup(form) {
   // Check of beide velden zijn ingevuld
   if (form.adres.value == "") {
      alert("Voor het optimaal berekenen van een route op maat moet er een adres ingevuld worden.")
   }
   if (form.plaatsnaam.value == "") {
      alert("Voor het optimaal berekenen van een route op maat moet er een plaats ingevuld worden.")
   }
   else {
      // Haal het vertrekpunt uit het formulier en vervang de spaties door + tekens
      var vertrekpunt = form.adres.value +"+"+ form.plaatsnaam.value
      vertrekpunt = vertrekpunt.replace(/ /,"+")
      // Open een nieuw venster met de routebeschrijving
      window.open("http://maps.google.nl/maps?f=d&hl=nl&saddr="+ vertrekpunt +"&daddr=Produktieweg+20,+zoeterwoude+rijndijk&ie=UTF8&z=13&om=1","_blank","resizable=yes, height=750, width=1000")
   }
   return false;
}

//----------------------------------------------------------------------------------------------------
// Route switcher
function showRoute(route) {
   // Verberg alles
   Element.hide('alphen');
   Element.setStyle('alphenlink',{ color:'#00ADEF' });
   Element.hide('amsterdam');
   Element.setStyle('amsterdamlink',{ color:'#00ADEF' });
   Element.hide('denhaag');
   Element.setStyle('denhaaglink',{ color:'#00ADEF' });
   // Toon gekozen route
   Element.show(route);
   Element.setStyle(route+'link',{ color:'#000000' });
}

function onSilverlightError(sender, args) {
   var appSource = "";
   if (sender != null && sender != 0) {
      appSource = sender.getHost().Source;
   }
   var errorType = args.ErrorType;
   var iErrorCode = args.ErrorCode;
   if (errorType == "ImageError" ||
      errorType == "MediaError") {
      return;
   }
   var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";
   errMsg += "Code: " + iErrorCode + "    \n";
   errMsg += "Category: " + errorType + "       \n";
   errMsg += "Message: " + args.ErrorMessage + "     \n";
   if (errorType == "ParserError") {
      errMsg += "File: " + args.xamlFile + "     \n";
      errMsg += "Line: " + args.lineNumber + "     \n";
      errMsg += "Position: " + args.charPosition + "     \n";
   }
   else if (errorType == "RuntimeError") {
      if (args.lineNumber != 0) {
         errMsg += "Line: " + args.lineNumber + "     \n";
         errMsg += "Position: " + args.charPosition + "     \n";
      }
      errMsg += "MethodName: " + args.methodName + "     \n";
   }
   throw new Error(errMsg);
}

var BrowserDetect = {
   init: function () {
      this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
      this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
      this.OS      = this.searchString(this.dataOS) || "an unknown OS";
   },
   searchString: function (data) {
      for (var i=0;i<data.length;i++)	{
         var dataString = data[i].string;
         var dataProp = data[i].prop;
         this.versionSearchString = data[i].versionSearch || data[i].identity;
         if (dataString) {
            if (dataString.indexOf(data[i].subString) != -1)
               return data[i].identity;
         }
         else if (dataProp)
            return data[i].identity;
      }
      return false;
   },
   searchVersion: function (dataString) {
      var index = dataString.indexOf(this.versionSearchString);
      if (index == -1) return false;
      return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
   },
   dataBrowser: [
      {   prop: window.opera,                                identity: "Opera" },
      { string: navigator.userAgent,  subString: "MSIE",     identity: "Explorer",  versionSearch: "MSIE" },
      { string: navigator.userAgent,  subString: "Firefox",  identity: "Firefox" },
      { string: navigator.userAgent,  subString: "Chrome",   identity: "Chrome" },
      { string: navigator.userAgent,  subString: "Netscape", identity: "Netscape" /* for newer Netscapes (6+) */ },
      { string: navigator.userAgent,  subString: "OmniWeb",  identity: "OmniWeb",   versionSearch: "OmniWeb/" },
      { string: navigator.vendor,     subString: "Apple",    identity: "Safari",    versionSearch: "Version" },
      { string: navigator.vendor,     subString: "iCab",     identity: "iCab" },
      { string: navigator.vendor,     subString: "KDE",      identity: "Konqueror" },
      { string: navigator.vendor,     subString: "Camino",   identity: "Camino" },
      { string: navigator.userAgent,  subString: "Gecko",    identity: "Mozilla",   versionSearch: "rv" },
      { string: navigator.userAgent,  subString: "Mozilla",  identity: "Netscape",  versionSearch: "Mozilla" /* for older Netscapes (4-) */ }
   ],
   dataOS : [
      { string: navigator.platform,   subString: "Win",      identity: "Windows" },
      { string: navigator.platform,   subString: "Mac",      identity: "Mac" },
      { string: navigator.userAgent,  subString: "iPhone",   identity: "iPhone/iPod" },
      { string: navigator.platform,   subString: "Linux",    identity: "Linux" }
   ]

};


