/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
*	[DESCRIPTION]
*	Common Javascript functions for use with the Park-line internetmanager.
*
*	[FILE]
*	PLcommon.js
*
*	[LOCATION]
*	/Javascript/
*
*	[CHANGES]
*	(2002-11-20) Maarten van Bree - Park-line
*	* Created
*	* Added PL_SetTitle()
*
*	[EXAMPLE]
*	None
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Generic function setting fields from/until based on value selected from dropdown
function PLSelPeriod(f, fVan, fTm) {
var a
  a = f.value.split('|');
  if(a.length==3) {
	fVan.value = a[1];
	fTm.value = a[2];
  }
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
*	Some common functions for radio/check buttons
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function


function formatVoorletters(object) {
	var VLArray
	var newVL
	newVL = ''
	VLArray = trim_string(object.value).toUpperCase().split('')
	if(VLArray.length > 0){
		for( i = 0 ; i < VLArray.length; i ++){
			if(VLArray[i] != '.' && VLArray[i] != ' ' && VLArray[i] != ',' ){
				newVL = newVL + VLArray[i] + '.';
			}
		}
		object.value = newVL
	}
}
function formatHuisNRToevoeging(object){
	FirstChar = object.value.substring(0,1)
	if(FirstChar != '' && !isNaN(FirstChar) ){
		object.value = '-'+ object.value
	}
}


function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

function _onload() {
	// Standard onload script
	if (typeof(_gForceFrameset) != 'undefined' && _gForceFrameset) {
		forceFrameset();
	}
	if(typeof(TTPSelInitValues)!='undefined'&&typeof(TTPSelInit)=='function') TTPSelInit(TTPSelInitValues);
	if(typeof(onPageLoad)=='function') return onPageLoad();
	return true;
}

function forceFrameset(){
	if(parent == self) {
		document.location = 'default.asp?URL='+escape(document.location);
		return;
	}
}

function go(fld) {
  if (fld.selectedIndex != 0) {
    document.location = fld.options[fld.selectedIndex].value
  }
}

function ABOActies(sURL) {
var s
	// find form with TTPSEL field to pick up string with selected ABOs
	s = TTPGetSelection();
	if (s == "") {
		alert('Geen abonnement(en) geselecteerd');
	} else {
		if(s.indexOf(',') >= 0 &&
			(sURL == 'hdkAanAfmelden' ||
			 sURL == 'hdkAbonnementLog')) {
			alert('Deze actie kan alleen worden uitgevoerd op 1 abonnement');
		} else {
			document.location = sURL + ".asp?ABO=" + s;
		}
	}
}

function Get_Cookie(name,dflt) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return dflt;
    if (start == -1) return dflt;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
	return document.cookie;
}

function setVisible(item,bVisible) {
	if(item) {
		item.style.visibility = (bVisible) ? 'visible' : 'hidden';
		item.style.display = (bVisible) ? 'block' : 'none';
	}
}

function checkZoekAdres(fld) {
var fPC, fHN, frm = fld.form;
	fPC = frm.checkpostcode;
	fHN = frm.checkhuisnummer;
	if (fPC && fHN) {
		if (fPC.value.length == 6 && fHN.value.length > 0) {
			frm.submit();
		} else if(fld.name == 'checkpostcode' && fPC.value.length > 0 && fPC.value.length != 6) {
			showAlert(fld, 'Ongeldige postcode\n');
		} else if (fld.name == 'checkhuisnummer' && fPC.value.length == 6) {
			showAlert(fld, 'Vul huisnummer in\n');
		}
	}
}
