var picWindow;

/*

this part of the fix is not delivered.

var message = "Sorry, right-click has been disabled"; 
function rtclickcheck(keyp) { 
	if (navigator.appName == "Netscape" && keyp.which == 3) {         
		alert(message); return false; 
	} 
    
    if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {         
    	alert(message);         
    	return false; 
    } 
} 

document.onmousedown = rtclickcheck; 
*/
        
function openPicture(pictureUrl, width, height) {
    settings="toolbar=no,location=no,directories=no,"+
                    "status=no,menubar=no,scrollbars=no,"+
                    "resizable=no,width="+width+",height="+height;

    if (picWindow && !picWindow.closed) {
        picWindow.close();
    }
    picWindow = window.open(pictureUrl,'',settings);
    if (!picWindow.opener) {
        picWindow.opener=window;
    }
}
var defaultEmptyOK = false

function submitAddress(form, cmnd,  message, fieldname){
    var field = document.forms[form][fieldname];
    var radio_choice = false;
    for (counter = 0; counter < field.length; counter++){
        if (field[counter].checked)radio_choice = true;
    }
    if (!radio_choice){
       alert(message)
    }else{
        submitForm(form, cmnd);
    }
}



function openPDF(pdfUrl){
    settings="toolbar=no,location=no,directories=no,"+
                    "status=no,menubar=no,scrollbars=yes,"+
                    "resizable=yes,width=800,height=600";

    myDate=new Date();

    fileName = myDate.getDay()+"_"+myDate.getMonth()+"_"+myDate.getFullYear()+"_"+myDate.getHours()+"_"+myDate.getMinutes()+"_"+myDate.getSeconds();

    window.open(pdfUrl, fileName, settings);
}

function focusElement(formName, elemName) 
{
   	var elem = document.forms[formName].elements[elemName];
    	
    elem.focus( );
    elem.select( );
}

//fucntion that checks the email address
//returns true or false
function check_email(obj)
// This function checks if  x  is an emailaddress
{
  	var x = obj.value;

	// an emailadress may not contain two of these next to eachother:
	// ".", "_", "-", "@", "&"
  	var b = /[\._\-@&]{2}/;	
  	
  	// an emailadress may not start with these characters:
  	// ".", "_", "-", "&"
  	var c = /^[\._\-&]/;		

  	var m = /(^[A-Za-z0-9_\.\-&]{1,})@([A-Za-z0-9\.\-\[\]]{5,})$/;
  	var p = x.match(m);

  	var n = /(^\"[A-Za-z0-9_ \.\-&]{1,})\"@([A-Za-z0-9\.\-\[\]]{5,})$/;
  	var q = x.match(n);

  	var o = /(^[A-Za-z]{1,}) \<(([A-Za-z0-9_ \.\-&]{1,})@([A-Za-z0-9\.\-\[\]]{5,}))\>$/;
  	var r = x.match(o);
	
	var s = /(^\"[A-Za-z0-9_ \.\-&,:]{1,})\" \<(([A-Za-z0-9_ \.\-&]{1,})@([A-Za-z0-9\.\-\[\]]{5,}))\>$/;
	var t = x.match(s);
	
	if ( p != null ) 
	{
		return  ( !(b.test(x))) && (!(c.test(x)) );
	}	
	else 
	{
		if ( q!=null ) 
		{
			return    ( !(b.test(x))) && (!(c.test(x)) );
		}
	}
	
  	if ( r != null) 
  	{
  		return check_email(r[2]);
  	}	
  	else 
  	{
  		if ( t != null) 
  		{
  			return check_email(t[2]);
  		}
	}
	
  	alert('You entered an invalid email address.');
  
  	return false;
}



function emailCheck (emailObject, formName, canBeEmpty) 
{
	emailStr = emailObject.value;
	
	// An email field can be empty
	if ( canBeEmpty == "true" && emailStr.length == 0 )
	{
		return true;
	}
	 
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/

	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"

	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"

	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'

	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"

	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		alert("Email address [" + emailStr + "] seems incorrect (check @ and .'s)");
		
		setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
		
		return false;
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    alert("The username in email address [" + emailStr + "] doesn't seem to be valid.")
	    setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
	    
	    return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
	    // this is an IP address
		  for (var i=1;i<=4;i++) 
		  {
		    if (IPArray[i]>255) 
		    {
		        alert("Destination IP address in email addres [" + emailStr + "] is invalid!")
				
				setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
				
				return false
		    }
	    }
	    return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		alert("The domain name in email addres [" + emailStr + "] doesn't seem to be valid.")
	    setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
	    
	    return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>4) {
	   // the address must end in a two letter or three letter word.
	   alert("The address in email address [" + emailStr + "] must end in a four- or three-letter domain, or two letter country.")
	   setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
	   
	   return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address [" + emailStr + "] is missing a hostname!"
	   alert(errStr)
	   setTimeout("focusElement('" + formName + "', '" + emailObject.name + "')", 0);
	   
	   return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}

var SearchForbittenCharArray = new Array();
var ForbittenCharMsg = 'You can not use the following characters "=" and "+".';

var RequiredFieldsString = '';
var RequiredFieldsStringArray = new Array();
var RequiredFieldsArray = new Array();
var RequiredFieldsMsgArray = new Array();
var Domain = '';


var SearchAndReplaceChar = new Array();


var SearchAndReplaceCharURL = new Array()
SearchAndReplaceCharURL[0] = new Array(/&/g,"hop_met_de_geit");
SearchAndReplaceCharURL[1] = new Array(/=/g,"is_gelijk_aan");
SearchAndReplaceCharURL[2] = new Array(/\+/g,"plustiekenske");

function ReplaceCharURL(CheckString) {
	RegExp.multiline=true;
	for(i=0;i<SearchAndReplaceCharURL.length;i++) {
	Searcher = SearchAndReplaceCharURL[i];
	CheckString = CheckString.replace(Searcher[0],Searcher[1]);
	}
return CheckString;
}

// The second number in the "onLoad" command in the body
// tag determines the form's focus. Counting starts with '0'
function putFocus(formInst, elementInst) {
    if (document.forms.length > 0) {
        document.forms[formInst].elements[elementInst].focus();
    }
}


function num_keypress() {
	if ((window.event.keyCode != 13) && (window.event.keyCode != 46) && (window.event.keyCode != 44) && ((window.event.keyCode < 48) || (window.event.keyCode > 57))) {
		window.event.returnValue=false
	}
}

function int_keypress() {
	if ((window.event.keyCode < 48) || (window.event.keyCode > 57)) {
		window.event.returnValue=false
	}
}

function alpha_num_keypress() {
	if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))||
	   ((window.event.keyCode >= 65) && (window.event.keyCode <= 90))||
	   ((window.event.keyCode >= 97) && (window.event.keyCode <= 122)))) {
		window.event.returnValue=false
	}
}

function character_keypress() {
	if ((window.event.keyCode < 33) || (window.event.keyCode > 126)) {
		window.event.returnValue=false
	}
}

// validates that the entry is x characters long
function hasLengthOrEmpty(elem, length) {
    var str = elem.value;
    
    if ( str.length == 0 )
    	return true;
    	
    if (str.length != length) {
        alert("Current inputfield does not contain the required " + length + " characters.");
        return false;
    } else {
        return true;
    }
}

function ReplaceChar(CheckString) {

//RegExp.multiline=true;
//	for(s=0;s<SearchAndReplaceChar.length;s++) {
//	Searcher = SearchAndReplaceChar[s];
//	CheckString = CheckString.replace(Searcher[0],Searcher[1]);
//	}
return CheckString;
}


//function checks if field is filled in
//returns true or false

function FillRequiredFieldsArray() {
    RequiredFieldsStringArray = new Array();
    RequiredFieldsArray = new Array();
    RequiredFieldsMsgArray = new Array();
	if (RequiredFieldsString != '') {
	    RequiredFieldsStringArray = RequiredFieldsString.split(",");
	    g = 0;
		for(f=0;f<RequiredFieldsStringArray.length;f++) {
			RequiredFieldsArray[g] = RequiredFieldsStringArray[f];
			RequiredFieldsMsgArray[g] = RequiredFieldsStringArray[f+1];
			f++;g++;
		}
	    RequiredFieldsArrayString = '';
	}
}




// functions that will return the values of the different kind of form elements
function checkField_normal(thisform,ThisField,TheObj,TheLayer) {
 TheString="";
   if (thisform[ThisField]){	
	   // In the case of doublures of ThisFields, the value of TheString is null. 
	   // This leads to javascripts. So we avoid the null assignment.
	   if (thisform[ThisField].value != null) {
    	 	 TheString = thisform[ThisField].value;
	   } 
		TheString = ReplaceChar(TheString);
		thisform[ThisField].value = TheString;
   }
	return TheString;
}

function checkField_radio(thisform,ThisField) {
TheString = '';
checkOut = thisform[ThisField];
	for(j=0;j<checkOut.length;j++) {
		if(checkOut[j].checked) {
		TheString = checkOut[j].value;
		TheString = ReplaceChar(TheString);
		}
	}

	if (!checkOut.length){
		if (checkOut.checked){
			TheString = checkOut.value;
			TheString = ReplaceChar(TheString);
		}
	}
return TheString;
}

function checkField_checkbox(thisform,ThisField) {
TheString = ''
checkOut = thisform[ThisField];
	if(checkOut[0]) {
		for(j=0;j<checkOut.length;j++) {
			if(checkOut[j].checked) {
			InputString = checkOut[j].value;
			TheString += '+' + InputString;
			TheString = ReplaceChar(TheString);
			}
		}
	}
	else {
		TheString = '+' + checkOut.checked;
	}
TheString = TheString.slice(1);
return TheString;
}

function checkField_selectone(thisform,ThisField) {
TheString = ''
checkOut = thisform[ThisField];
	for(j=0;j<checkOut.length;j++) {
		if(checkOut[j].selected) {
		TheString = checkOut[j].value;
		TheString = ReplaceChar(TheString);
		}
	}
return TheString;
}

function checkField_selectmultiple(thisform,ThisField) {
TheString = ''
checkOut = thisform[ThisField];
	for(j=0;j<checkOut.length;j++) {
			if(checkOut[j].selected) {
			InputString = checkOut[j].value;
			TheString += '+' + InputString;
			TheString = ReplaceChar(TheString);
			}
	}
TheString = TheString.slice(1);
return TheString;
}

function checkForm(form, myAction) {
  form = document.forms[form];
	if (check_values(form)){
	    form.action= myAction;
        form.submit();
	}
}

function checkFormNoAction(form){
  form = document.forms[form];
  return check_values(form);
}


// - myAction is a reference to a function
function checkFormDoAction(form, myAction){
  form = document.forms[form];
	if (check_values(form)){
	    myAction();
	}
}

function submitForm(form, myAction) {
	form = document.forms[form];
	form.action= myAction;

	form.submit();
}


//function checks if you are sure you want to delete
function confirmDelete(form, myAction, message, startindex, endindex){
	var count = 0;

	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if (document.forms[form]['list_checkbox_'+x]){
			if(document.forms[form]['list_checkbox_'+x].checked){
				count++;
			}
		}
	}

	if (count>0){
		if (confirm(message)){
			submitForm(form,myAction);
		}
	}
}

//function checks if any checkbox is selected
function checkSelection(form, action, message, startIndex, endIndex) {

	if (nrOfSelectedItems(form,startIndex,endIndex) > 0){
        checkForm(form,action,startIndex,endIndex);
        return true;
	}else{
		alert(message);
		return false;
	}
}

function nrOfSelectedItems(form,startIndex,endIndex) {
	var count = 0;

	for (x=parseInt(startIndex);	x<=parseInt(endIndex);	x++){
		if (document.forms[form]['list_checkbox_'+x]){
			if(document.forms[form]['list_checkbox_'+x].checked){
				count++;
			}
		}
	}
	return count;
}

//function that looks whether any checkbox is selected and asks if you really want to do that
function checkSelectionAndConfirmDelete(form, action, messageSelection, messageDelete, startindex, endindex) {
    var count = 0;
	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if (document.forms[form]['list_checkbox_'+x]){
			if(document.forms[form]['list_checkbox_'+x].checked){
				count++;
			}
		}
	}
	if (count<=0) {
	    alert(messageSelection);
	} else {
	    if (confirm(messageDelete)){
            submitForm(form,action);
        }
	}
}


//function checks if any checkbox is selected
// - action is a reference to a function
function checkSelectionDoAction(form, action, message, startindex, endindex){

	var count = 0;

	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if (document.forms[form]['list_checkbox_'+x]){
			if(document.forms[form]['list_checkbox_'+x].checked){
				count++;
			}
		}
	}

	if (count>0){
        checkFormDoAction(form,action);
	}else{
		alert(message);
	}
}

//function checks if any radiobutton is selected
function checkRadios(form, action, message, fieldname){

	var field = document.forms[form][fieldname];
        var radio_choice = false;
        for (counter = 0; counter < field.length; counter++){
            if (field[counter].checked)radio_choice = true;
        }

        if (!radio_choice){
            alert(message)
        }else{
	    checkForm(form,action);
	}
}

//function checks if any checkbox is selected
function checkSelectionOnlyOne(form, action, message, startindex, endindex){
	var count = 0;

	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if(document.forms[form]['list_checkbox_'+x].checked){
			count++;
		}
	}

	if (count==1){
	    if (action != '') {
			checkForm(form,action);
	    }
	    return true;
	}else{
		alert(message);
		return false;
	}
}

//function checks if a maximum number of checkboxes between is selected
function checkSelectionMaximum(form, maximum, startindex, endindex){
	var count = 0;

	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if(document.forms[form]['list_checkbox_'+x].checked){
			count++;
		}
	}
	return (count <= parseInt(maximum));
}

function checkHasAtLeastOneSelected(form,startindex,endindex){
	for (x=parseInt(startindex);x<=parseInt(endindex);x++){
		if(document.forms[form]['list_checkbox_'+x].checked){
			return true;
		}
	}
	return false;
}


//function to make string out of form values
function check_values(thisform) {
FillRequiredFieldsArray();

//Make Arrays with the names and types of the form elements

FieldErrorMsg = ''; FieldName = new Array(); FieldType = new Array(); x = 0; RadioName = ''; CheckboxName = '';
//Fill the Arrays
	for(i=0;i<thisform.length;i++) {
		if(thisform[i].type == "radio") {
			if (thisform[i].name != RadioName) {
			FieldName[x] = thisform[i].name;
			FieldType[x] = thisform[i].type;
			RadioName = thisform[i].name;
			x++;
			}
		}
		else if(thisform[i].type == "checkbox") {
			if (thisform[i].name != CheckboxName) {
			FieldName[x] = thisform[i].name;
			FieldType[x] = thisform[i].type;
			CheckboxName = thisform[i].name;
			x++;
			}
		}
		else {
			if ((thisform[i].type != "button") && (thisform[i].type != "reset") && (thisform[i].type != "submit")) {
				FieldName[x] = thisform[i].name;
				FieldType[x] = thisform[i].type;
				x++;

			}
		}
	}
ErrorMsg = false; NewString=''; ValueString=''; RequiredFields=true;

	for(i=0;i<FieldName.length;i++) {
	ThisField = FieldName[i];
	ThisType = FieldType[i];

		switch(ThisType) {
			case "radio":
				valstring = checkField_radio(thisform,ThisField);
			break;

			case "checkbox":
				valstring = checkField_checkbox(thisform,ThisField);
			break;

			case "select-one":
				valstring = checkField_selectone(thisform,ThisField);
			break;

			case "select-multiple":
				valstring = checkField_selectmultiple(thisform,ThisField);
			break;

			default:
				valstring = checkField_normal(thisform,ThisField);
			break;
		}

		//lengthChecker == 0 ---> input field must be at least 1 long
		LengthChecker = 0;
		//if(ThisField == "first_name") LengthChecker = 1;

		if(trimString(valstring).length > LengthChecker) NewString += '&' + ThisField + '=' + valstring;
		else {
			if (RequiredFieldsArray.length > 0) {
				for(k=0;k<RequiredFieldsArray.length;k++) {
					if (ThisField == RequiredFieldsArray[k]) {
					FieldErrorMsg += " - " + RequiredFieldsMsgArray[k] + "\n";
					}
				}
			}
		}
	}

	if (FieldErrorMsg != '') {
		if (RequiredFieldsArray.length > 0) {
			alert(FieldErrorMsg);
			return false;
		}else{
			return true;
		}
	}else {
		return true;
	}


  /** -- trim --
*** This method removes all nasty spaces in TEXTBOX elements
***
*** @input: obj -> valid object name for TEXTBOX
**/
	function trim(obj) {
	  if(obj.value!="") {
	    obj.value = obj.value.replace(/\s{1,}/g, " ");
	    obj.value = obj.value.replace(/^\s{1,}/, "");
	    obj.value = obj.value.replace(/\s{1,}$/, "");
	  }


	  return;
	}
}

function trimString(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function checkPriceFormat(isGroupingEnabled, defaultSep, price, fieldname, form, message, decimals, ignoreEmptyInput, defaultGroupingSeparator){
    var i;                                                                                         
	var j;
    var teken;
	var priceformat;
	var integerPartSuggestedFormat;

    // First action remove spaces from price, 
    // Norway issue,  G.J. Kruizinga 31/08/2011
    
    price = price.replace('\xA0', '');
	price = price.replace(' ', '');
		
	if (ignoreEmptyInput == null)
		ignoreEmptyInput = false;
		
	if (defaultSep == ".")
	    defaultGroupingSeparator = ",";
	    
	if (defaultGroupingSeparator == null) 
		defaultGroupingSeparator  = ".";
	
    // remove space from groupingseparator.
    defaultGroupingSeparator = defaultGroupingSeparator.replace('\xA0', '');
	defaultGroupingSeparator = defaultGroupingSeparator.replace(' ', '');

	if (isGroupingEnabled == "false") {
	    integerPartSuggestedFormat = " ########";
	} else {
	    integerPartSuggestedFormat = " ##"+ defaultGroupingSeparator +"###"+ defaultGroupingSeparator +"###";
	}

	// functions .replace(/^\s+/,'').replace(/\s+$/,'') are a proper 'trim' function.
	if (ignoreEmptyInput == true && price.replace(/^\s+/,'').replace(/\s+$/,'').length == 0) {
	    return true; 
	}

    if (isGroupingEnabled == "false") {
        if (price.indexOf(defaultGroupingSeparator) > 0) {
            priceformat = integerPartSuggestedFormat;
            if (parseInt(decimals) > 0) {
                priceformat = priceformat + defaultSep;
                for (j = 0; j < parseInt(decimals); j++){
                        priceformat = priceformat + '#';
                }
            }
            alert(price + ' ' + message + priceformat);
            document.forms[form][fieldname].value = '';
            return false;
        }
    }

	if (defaultSep == "" || defaultSep == null){
            defaultSep = ".";
    }
    
    if (! isValidFloat(price, defaultSep, defaultGroupingSeparator)) {
            priceformat = integerPartSuggestedFormat;
            if (parseInt(decimals) > 0) {
                priceformat = priceformat + defaultSep;
                for (j = 0; j < parseInt(decimals); j++){
                    priceformat = priceformat + '#';
                }
            }
            alert(price + ' ' + message + priceformat );

            document.forms[form][fieldname].value = '';
            return false;
    }

    var countDefault = 0;
    var nbrDefaultSep = 0;

    for(i = 0; i < price.length; i++){
        teken = price.charAt(i);
        countDefault++;
        if (teken == defaultSep){
            countDefault = 10 - decimals;
            if (nbrDefaultSep > 0) {
                priceformat = integerPartSuggestedFormat;
                if (parseInt(decimals) > 0){
                    priceformat = priceformat + defaultSep;
                    for (j = 0; j < parseInt(decimals); j++){
                        priceformat = priceformat + '#';
                    }
                    alert(price + '  ' + message + priceformat);
                    document.forms[form][fieldname].value='';
                    break;
                }
            }
            else {
                nbrDefaultSep++;
            }
        }

        if (countDefault > 10){
            priceformat = integerPartSuggestedFormat;

            if (parseInt(decimals) > 0){
                priceformat = priceformat + defaultSep;

                for (j = 0; j < parseInt(decimals); j++){
                    priceformat = priceformat + '#';
                }
            }

            alert(price + ' ' + message + priceformat);
            document.forms[form][fieldname].value='';
            break;
        }
        
    }
    
    
}

function checkValueDivisibility(value, divisor, message)
{
	if ( ! isDividable(value, divisor) )
	{
		alert(value + ' ' + message + ' [' + divisor + ']');
		
		return false;
	}
	
	return true;
}
	
//check or uncheck all checkboxes in the list
//generalname = the name of the general checkbox
//fieldname = the fixed part of the name of the checkbox
//form = the name of the form
//startindex = first checkbox
//endindex = last checkbox
        function checkAll(generalname, fieldname, form, startindex, endindex) {
            if (document.forms[form][generalname].checked) {
                for (i = parseInt(startindex); i <= parseInt(endindex); i++) {
                    if (document.forms[form][fieldname + i]){
                        document.forms[form][fieldname + i].checked = true;
                    }
                }
            } else {
                for (i = parseInt(startindex); i <= parseInt(endindex); i++) {
                    if (document.forms[form][fieldname + i]){
                        document.forms[form][fieldname + i].checked = false;
                    }
                }
            }
        }

//loops over all textareas in the form and checks if the length is greater than the given length
//if one textarea's content is found that's too long, the user is shown a confirm box : if he presses ok,
//the textarea's content is trimmed and the method returns true. If he presses cancel, nothing happens, and the method returns false
function checkTextAreas(formname,message,leng) {

	if (!leng) {
        leng = 254;
    }

    toLongTextAreas = new Array();

    var textAreas = document.forms[formname].getElementsByTagName("TEXTAREA");

    for (i=0; i < textAreas.length; i++){
    	if (textAreas[i].value.length>leng){
        	toLongTextAreas[toLongTextAreas.length] = textAreas[i];
        }
   	}

    if (toLongTextAreas.length > 0){
        for (j=0;j<toLongTextAreas.length;j++){
            if (toLongTextAreas[j].value.length>leng){
            	toLongTextAreas[j].value = ReplaceChar(toLongTextAreas[j].value);
                message+='\n\t'+'-'+'\t'+toLongTextAreas[j].value.substring(0,leng)+'\n\n';
            }
        }

		if(confirm(message)){
             for (j=0;j<toLongTextAreas.length;j++){
                if (toLongTextAreas[j].value.length>leng){
                    toLongTextAreas[j].value = ReplaceChar(toLongTextAreas[j].value);
                    toLongTextAreas[j].value = trimValue(toLongTextAreas[j].value.substring(0,leng));
                }
             }
		}
        else {
          	return false;
		}
	}

    return true;
}

//loops over all textareas in the form and checks if the length is greater than the given length
//if one textarea's content is found that's too long, the user is shown a confirm box : if he presses ok,
//the textarea's content is trimmed and the method returns true. If he presses cancel, nothing happens, and the method returns false
function checkSelectionAndMinimumPricesFilled(form, action, messageOne, messageTwo, startIndex, endIndex)
{
 	// first check if any item selected at all
    if (nrOfSelectedItems(form,startIndex,endIndex) == 0)
    {
	    alert(messageOne);
    }
	else
	{
		var countEmptyMinimumXBR = 0;
		var auctionFirmsInfo;
		var AuctionIdList = new Array();
		var AuctionXMLInfo = new Array();
		
		// search in look up table which P_AUCTIONEERING_FIRMs uses xml_interface and which not
		// And store this in an array
		for (j=0; document.forms[form].elements['is_xml_interface_' + j] != null; j++) 
		{
			auctionFirmsInfo = document.forms[form].elements['is_xml_interface_' + j].value;
	    	var auctionElements= auctionFirmsInfo.split(",");
	
			AuctionIdList[j] = auctionElements[0];
			AuctionXMLInfo[j] =  auctionElements[1];
			// alert( AuctionIdList[j] + "   /  "   + AuctionXMLInfo[j]);
		}
	
		// so there is at least one item selected
		// no test for every selected vehicle which use xml interface if the xbr_min_price is set
		for (i=parseInt(startIndex); i<=parseInt(endIndex); i++)
	    {
        	if (document.forms[form].elements['list_checkbox_' + i].checked)           
	        {
	        	var xmlInterfaceUsed = 'N';
	        	var choice = document.forms[form].elements['P_AUCTIONEERING_FIRM_' + i].value;
	        	
	        	// look up in our created array to see if the selected item uses xml interface
	        	for (k=0; AuctionIdList[k] != null; k++)
	        	{
	        		if (AuctionIdList[k] == choice)
	        		{
	        			xmlInterfaceUsed = AuctionXMLInfo[k];
	        			break;
	        		}
	        	}
	        
         	    var xbrField = document.forms[form].elements['xbr_min_price_' + i].value;
            	if ((xbrField == null || xbrField == 0) && xmlInterfaceUsed == 'Y') 
	            {
    	        	countEmptyMinimumXBR++;
    	        	break;
        	    }
			}
   		}

		// if any item is found which doesn't have xbr_min_price set ask for confirmation
	   	if (countEmptyMinimumXBR > 0)
		{
	   		if(confirm(messageTwo))
			{
				checkForm(form,action,startIndex,endIndex);
	  		}
		}
	   	else
		{
			// every selected item has xbr_min_price set
  			checkForm(form,action,startIndex,endIndex);
		}
	}
}

//generic confirm dialog, returns true if user clicks OK, false otherwise
function confirmDialogue(message) {
    var isConfirmed = confirm(message);

    if (isConfirmed)
	    return true ;
    else
	    return false ;
}

function isInteger (s) {
	var i;

    s = trimValue(s);

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isValidFloat(s, decimalSeparator, thousandSeparator)
{
	var i;
    var seenDecimalPoint = false;
    var seenThousandSep = false;
    var numberAfterThousandSep = 0;

    if (isEmpty(s)) {
       if (isValidFloat.arguments.length == 3) return defaultEmptyOK;
       else return (isValidFloat.arguments[3]);
    }

    if (s == decimalSeparator) return false;
    if (s == thousandSeparator) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (c == decimalSeparator) {
            if (seenDecimalPoint) {
                return false;
            }
            else if (seenThousandSep && numberAfterThousandSep != 3) {
                return false;
            }
            else {
                seenDecimalPoint = true;
                seenThousandSep = false;
                numberAfterThousandSep = 0;
            }
        }
        // Nordic Issue Skip also spaces
        else if (c == thousandSeparator || isSpace(c) ) {
            if (seenThousandSep && numberAfterThousandSep != 3) {
                return false;
            }
            else {
                numberAfterThousandSep = 0;
                seenThousandSep = true;
            }
        }
        else {
            if (!isDigit(c)) {
                //alert('no digit ' + c);
                return false;
            }
            else if (seenThousandSep) {
                numberAfterThousandSep++;
            }
        }
    }
    if (seenThousandSep && numberAfterThousandSep != 3) {
        return false;
    }

    // All characters are numbers.
    return true;
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

// Returns true if character c is a space
function isSpace (c) {
   // alert( c.charCodeAt(0) == 32 || c.charCodeAt(0) == 160)
   return ( c.charCodeAt(0) == 32 || c.charCodeAt(0) == 160 );

}

function isDividable(number, divisor)
{

  
	// First remove of all the dots (european style)
	var withoutDotNumber = number.replace('.', '');
	
	// Now replace the comma seperator by a dot 
	var divNumber = withoutDotNumber.replace(',', '.');  
	
	divNumber = divNumber.replace('\xA0', '');
	divNumber = divNumber.replace(' ', '');
  
	var result1;  
  	if (divisor < 1) {
  	    // to avoid division problems; sometimes result2 is not null.
    	result1 = Math.round ( 100 * divNumber / divisor) / 100;    	
	} else {
    	result1 = divNumber / divisor;
	}	
	var result2 = result1 % 1;
	

	if ( result2 == 0 )
	{
		return true;
	}
	else
	{
		return false;
	}
		

}

function isEmpty(text) {
	if ((text == null) || (text.length == 0)) {
	    return true;
    }

    return false;
}

function trimValue(value) {
    if (isEmpty(value)) {
        return value;
    }

    value = value.replace(/^\s+/,'').replace(/\s+$/,'');

    return value;
}

// 
// Function hideId(id)
//
// Description: All the output of the id will be hide in the window
//
function hideId(id)
{
	if ( document.getElementById(id) )
	{
		document.getElementById(id).style.display = "none";
	}
}

// 
// Function hideId(id)
//
// Description: All the output of the id will be shown in the window
//
function showId(id)
{
	if ( document.getElementById(id) )
	{
		document.getElementById(id).style.display = "block";
	}
}



var SearchAreaIsShown = true;

function hideSeachArea(areaId, searchButtonId, hideButtonId, showButtonId)
{
	// Hide the search area
	hideId(areaId);
		
	// Hide the search button
	hideId(searchButtonId);
		
	// Hide the hide button
	hideId(hideButtonId);
	
	// Show the showButton
	showId(showButtonId);
	
	SearchAreaIsShown = false;
}

function showSeachArea(areaId, searchButtonId, hideButtonId, showButtonId)
{
	// Show the search area
	showId(areaId);
	
	// Show the search button
	showId(searchButtonId);
	
	// Show the hide button
	showId(hideButtonId);
	
	// Hide the shown button
	hideId(showButtonId);
	
	SearchAreaIsShown = true;
}

function showOrHideSeachArea(areaId, searchButtonId, toggleButtonId, hideText, showText)
{
	if ( SearchAreaIsShown )
	{
		// Hide the search area
		hideId(areaId);
		
		SearchAreaIsShown = false;
		
		document.getElementById(toggleButtonId).value = showText;
	}
	else
	{
		// Show the search area
		showId(areaId);
		
		SearchAreaIsShown = true;
		
		document.getElementById(toggleButtonId).value = hideText;
	
	}
}

var bajb_backdetect = {
	Version: '1.0.0',
	Description: 'Back Button Detection',

	Browser: {
		IE:     !!(window.attachEvent && !window.opera),
		Safari:	navigator.userAgent.indexOf('Apple') > -1,
		Opera:	!!window.opera
	},

	FrameLoaded: 0,
	FrameTry:0,
	FrameTimeout: null,

	OnBack: function(){
		// alert('Back Button Clicked');
	},

	BAJBFrame: function(){
		var BAJBOnBack = document.getElementById('BAJBOnBack');
		if(bajb_backdetect.FrameLoaded > 1)
		{
			if(bajb_backdetect.FrameLoaded == 2)
			{
				bajb_backdetect.OnBack();
				history.back();
			}
		}
		bajb_backdetect.FrameLoaded++;
		if(bajb_backdetect.FrameLoaded == 1)
		{
			if(bajb_backdetect.Browser.IE)
			{
				bajb_backdetect.SetupFrames();
			}
			else
			{
				bajb_backdetect.FrameTimeout = setTimeout("bajb_backdetect.SetupFrames();",700);
			}
		}
	},

	SetupFrames: function()
	{
		clearTimeout(bajb_backdetect.FrameTimeout);
		var BBiFrame = document.getElementById('BAJBOnBack');
		var checkVar = BBiFrame.src.substr(-11,11);

		if(bajb_backdetect.FrameLoaded == 1 && checkVar != "HistoryLoad")
		{
			BBiFrame.src = "blank.html?HistoryLoad";
		}
		else
		{
			if(bajb_backdetect.FrameTry < 2 && checkVar != "HistoryLoad")
			{
				bajb_backdetect.FrameTry++;
				bajb_backdetect.FrameTimeout = setTimeout("bajb_backdetect.SetupFrames();",700);
			}
		}
	},

	SafariHash: 'false',
	Safari: function()
	{
		if(bajb_backdetect.SafariHash == 'false')
		{
			if(window.location.hash == '#b')
			{
				bajb_backdetect.SafariHash = 'true';
			}
			else
			{
				window.location.hash = '#b';
			}
			setTimeout("bajb_backdetect.Safari();",100);
		}
		else if(bajb_backdetect.SafariHash == 'true')
		{
			if(window.location.hash == '')
			{
				bajb_backdetect.SafariHash = 'back';
				bajb_backdetect.OnBack();
				history.back();
			}
			else
			{
				setTimeout("bajb_backdetect.Safari();",100);
			}
		}
	},

	Initialise: function()
	{
		if(bajb_backdetect.Browser.Safari)
		{
			bajb_backdetect.Safari();
		}
		else
		{
			document.write('<iframe src="blank.html" style="display:none;" id="BAJBOnBack" onunload="alert(\'de\')" onload="bajb_backdetect.BAJBFrame();"></iframe>');
		}
	}
};
bajb_backdetect.Initialise();

