function SwapImage(objImage, strNewpath) {	
	objImage.src = strNewpath;
}

function updateLinks(mapval){
var hrefStr = ""
	if (mapval) {	
		for (index = 0; index < document.links.length;index++) {
			hrefStr = document.links[index].href
			if (document.links[index].search == "" && hrefStr.indexOf("#") < 0 && hrefStr.indexOf("javascript:") < 0 && hrefStr.indexOf("mailto:") < 0) {
				document.links[index].href = document.links[index].href + "?map=" + mapval
			}
			else {
				//alert (hrefStr.indexOf("#")) 
				if (hrefStr.indexOf("#") < 0 && hrefStr.indexOf("javascript:") < 0 && hrefStr.indexOf("mailto:") < 0) {
					document.links[index].href = document.links[index].href + "&map=" + mapval
					
				}
			}
		}
	}
}



function checkMinSize(elementArray,size,showMessage){

var testVal
testVal = ""
var failedItems = new Array()
var failedNames = ""
	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(testVal.length < size){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 
		}
	}
	
	if (showMessage && failedNames.length > 0){
		alert ("The following item(s) must be at least " + size + " characters in length: " + failedNames)	
	}

	return failedItems;

}

function checkMaxSize(elementArray,size,showMessage){

var testVal
testVal = ""
var failedItems = new Array()
var failedNames = ""
	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(testVal.length > size){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 
		}
	}
	
	if (showMessage && failedNames.length > 0){
		alert ("The following item(s) must be no more than " + size + " characters in length: " + failedNames)	
	}

	return failedItems;

}

function checkBlank(elementArray,showMessage){

var testVal
var failedNames = ""

testVal = ""
var failedItems = new Array()

	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(testVal.length < 1){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

		}
	}
	if (showMessage && failedNames.length > 0){
		alert ("Please enter data into the following field(s): " + failedNames)	
	}
	return failedItems;

}
function checkNumeric(elementArray,showMessage){
var testVal
var failedItems = new Array()
var failedNames = ""

testVal = ""
	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(isNaN(testVal)){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

		}
	}
	
	if (showMessage && failedNames.length > 0){
		alert ("The following item(s) may only contain numbers: " + failedNames)	
	}
	return failedItems
}

function checkEmail(elementArray,showMessage){
	 //make sure there's an '@' followed at some point by a '.'
	 var atLoc
	 var failedItems = new Array()
	 var failedNames = ""
	for (index=0;index < elementArray.length;index++){
		 emailStr = elementArray[index].value
		 atLoc = emailStr.indexOf("@")
		 if (atLoc > 0){
			if(emailStr.indexOf(".",atLoc) > 0){
				continue;
				
			}
		 }
		failedItems[failedItems.length] = elementArray[index]
		failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

	}
	//if we get here then the email is not valid
	if (showMessage && failedNames.length > 0){
		alert ("Please enter a valid email address for the following field(s): " + failedNames)	
	}
	return failedItems

}
 
function catchChange(sender){
//generic function that can be redirected for use with autogenerated inputs (from Inputs2.asp)
//e.g.

}



////PFIKS CALC
function chkNumeric(strString) {
   
   //  check for valid numeric strings
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
   
   
function docalculation() {

	var costpermonth
	var costperyear
	var costperuserpermonth
	
	if (document.pfikscalc.nousers.value.length == 0) {
		alert("Please enter a value.");
		return false;
	} 
	
	if (chkNumeric(document.pfikscalc.nousers.value) == false) {
		alert("Please check - non numeric value!");
		return false;
	}
	
	if (chkNumeric(document.pfikscalc.nousers.value) == true) {
		
		if ((document.pfikscalc.nousers.value > 0) && (document.pfikscalc.nousers.value <= 5)) {
			//COST PER MONTH - UPPER LIMIT TIMES COST PER USER
			costpermonth = 15 * 5;
		}
	
		if ((document.pfikscalc.nousers.value >= 6) && (document.pfikscalc.nousers.value <= 10)) {
			costpermonth = 13.5 * 10;
		}
		
		if ((document.pfikscalc.nousers.value >= 11) && (document.pfikscalc.nousers.value <= 25)) {
			costpermonth = 12 * 25;
		}
		
		if ((document.pfikscalc.nousers.value >= 26) && (document.pfikscalc.nousers.value <= 50)) {
			costpermonth = 11 * 50;
		}
		
		if ((document.pfikscalc.nousers.value >= 51) && (document.pfikscalc.nousers.value <= 100)) {
			costpermonth = 10 * 100;
		}
		
		if ((document.pfikscalc.nousers.value >= 101) && (document.pfikscalc.nousers.value <= 200)) {
			costpermonth = 8.50 * 200;
		}
		
		if ((document.pfikscalc.nousers.value >= 201) && (document.pfikscalc.nousers.value <= 500)) {
			costpermonth = 8 * 500;
		}
		
		if (document.pfikscalc.nousers.value >= 500) {
			alert ("Please call us for prices for more than 500 users");
		}
		
	}
	
	//NOW CALCULATE COST PER YEAR
	costperyear = costpermonth * 12;
	
	//COST PER USER MONTH
	costperuserpermonth = costpermonth / document.pfikscalc.nousers.value;
	document.getElementById('costperuserpermonth').innerHTML = "<strong>Cost per user per month:</strong> &pound;" + Math.round(costperuserpermonth*100)/100;
	document.getElementById('totalcostpermonth').innerHTML = "<strong>Your total cost per month:</strong> &pound;" + Math.round(costpermonth*100)/100;
	document.getElementById('totalcostperyear').innerHTML = "<strong>Your total cost per year:</strong> &pound;" + Math.round(costperyear*100)/100;
}

