//-----------------------------------------------------------
//JavaScript Library written by Adrian Bartlett November 2001
//18/02/2004	Chocks v1.1		Introduced special characters check.
//Important Note: Whenever this js file changed, make sure to change the version
// no in vol_redcare_top.asp file. Other wise user will get a cached copy..
// It was a bug in js/html --- Chocks
//gfdfgdgfd
//-----------------------------------------------------------

//validation and other javascript functions.
/*
function: validate()
			function validate(oControl as object, vType as String)
			this function gets passed the object that is to be validated, and the 
			type of validation to be performed on it.

function: MM_findObj, MM_showHideLayers, MM_preloadImages, MM_swapImg and MM_swapImgRestore
			these are dreamweaver layers functions.  not pretty, but robust and		
			browser compatible
		
function: expandIt()
			used to expand and contract list items

function formatDecimal(number, boolean, decimal)
			this function is used to format a decimal to
			a specified number of places. default is 2

function formatValue(argvalue, format)
			used to format a currency value to a format
			specified by the user (in the form £###,###,###)
			NB: This function sits on the back of the
			formatDecimal function
function RandomImage
			this function selects a random image for the left side of the
			screen
function OpenWindow (reportname)
			Opens a new window and displays the requested report	

function hideAllSelects, showAllSelects
			Used with layers, to hide and show selects beneath layers.  This is because
			they are treated as separate documents by ie so dont conform to zindex.  duh.			
							
*/

//This is the generic Message header for validation errors.
var strMessageHeader = "----------------------------------------------------------------------------\nProblems with this form are preventing it from being submitted.\nPlease see the descriptions below, make the necessary changes\nand re-submit the form.\n----------------------------------------------------------------------------\n"

function validate(oControl, vType){
	//first find out what kind of validation we are doing
	if (vType == "isNumber"){
		//testing for a number
		if (isNaN(oControl.value)){
			//alert("This needs to be a number");
			//oControl.focus();
			return false;
		}else{
			return true;
		}
	}

	if (vType == "isDate"){
		//testing for a date format d/m/yyyy or dd/mm/yyyy
		//first test the length is 8,9 or 10		
		strDate = oControl.value;
		if (strDate.length != 0){
			if (strDate.length == 8 || strDate.length == 9 || strDate.length == 10){
				re = new RegExp("/","i");
				//is the right initial delimiter is being used.
				if (strDate.search(re) >= 1){
					//and the second delimiter?

					if(strDate.substr((strDate.length-5),1) == "/"){
						//now get the date values..

						var dtDate = strDate.substr(0, strDate.search(re));
						var dtMonth = strDate.substr(strDate.search(re)+1,strDate.length-5-strDate.search(re)-1);
						var dtYear = strDate.substr((strDate.length-4),4);
						var dtTest = new Date(dtYear, dtMonth-1, dtDate);
	
						if (dtYear == dtTest.getFullYear() && (dtMonth-1 == dtTest.getMonth()) && (dtDate == dtTest.getDate())){
							//format of date is correct
							return true;
						}
					}
				}
			}
			//alert("Please Enter the date in the format (dd/mm/yyyy)");
			//oControl.focus();
			return false;
		}else{
			return true;
		}
	}

	if (vType == "isNull"){
		if (String((oControl.value)) == ""){
			//alert("This is a required field");
			//oControl.focus();
			return false;
		}else{
			return true;
		}
	}
	
	if (vType == "isEmail"){
		//testing email 
	
	}

	//nothing tested.
	alert("nothing tested");
	return false;
}

//layers code
function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

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_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_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];}
}

//function expandIt
function expandIt(objList, objImg){
	//open or close the list
	objList.style.display = (objList.style.display == "none")?"":"none";
}

//function formatDecimal(argvalue, addzero, decimaln)
function formatDecimal(argvalue, addzero, decimaln){
	var numOfDecimal = (decimaln == null) ? 2 : decimaln;
	var number=1;
	
	number = Math.pow(10, numOfDecimal);
	
	argvalue = Math.round(parseFloat(argvalue) * number) / number;
	argvalue = argvalue.toString();
	
	if (argvalue.indexOf(".") == 0){
		argvalue = "0" + argvalue;
	}

	if (addzero == true) {
		if (argvalue.indexOf(".") == -1){
			argvalue = argvalue + ".";
		}
		while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal)){
			argvalue = argvalue + "0";
		}
	}
	return argvalue;
}

//function formatValue(argvalue, format)
function formatValue(argvalue, format){
	var numOfDecimal=0;
	if(format.indexOf(".") != -1){
		numOfDecimal = format.substring(format.indexOf(".") + 1, format.length).length;
	}
	argvalue = formatDecimal(argvalue, true, numOfDecimal);
	argvalueBeforeDot = argvalue.substring(0, argvalue.indexOf("."));
	retValue = argvalue.substring(argvalue.indexOf("."), argvalue.length);
	strBeforeDot = format.substring(0, format.indexOf("."));
	
	for (var n = strBeforeDot.length-1; n>=0; n--){
		oneformatchar = strBeforeDot.substring(n,n+1);
		if(oneformatchar == "#"){
			if(argvalueBeforeDot.length>0){
				argvalueonechar = argvalueBeforeDot.substring(argvalueBeforeDot.length-1, argvalueBeforeDot.length);
				retValue = argvalueonechar + retValue;
				argvalueBeforeDot = argvalueBeforeDot.substring(0, argvalueBeforeDot.length-1);
			}
		}else{
			if(argvalueBeforeDot.length > 0 || n == 0){
				retValue = oneformatchar + retValue;
			}
		}
	}
	return retValue	;
}

//function RandomImage
function RandomImage(level){
   var j,d="",l="",m="",p="",q="",z="",list= new Array()
		list[list.length]=level + 'images/icons_left/1.jpg';
		list[list.length]=level + './images/icons_left/2.jpg';
		list[list.length]=level + './images/icons_left/3.jpg';
		list[list.length]=level + './images/icons_left/4.jpg';
		list[list.length]=level + './images/icons_left/5.jpg';
		list[list.length]=level + './images/icons_left/6.jpg';
		j=parseInt(Math.random()*list.length);
		j=(isNaN(j))?0:j;
		document.write("<img src='"+list[j]+"'>");
}			

//function OpenWindow(script)
function OpenWindow(script, path){
	window.open(path + script, 'machineWin', 'width=670,height=600,toolbar=no,status=no,location=no,resize=no,scrollbars=yes');
}

//show and hide selects.
function hideAllSelects(){
	for(i=0; i<document.all.length; i++) {
	    if (document.all(i).tagName == "SELECT"){
			document.all(i).style.visibility = "hidden"
		}
	}
}

function showAllSelects(){
	for(i=0; i<document.all.length; i++) {
	    if (document.all(i).tagName == "SELECT"){
			document.all(i).style.visibility = "visible"
		}
	}
}

function SpcCheck(v1)
{
	// Not to allow special characters
	var SpcValue = new RegExp("[\'\"%^&*+#]{1}");
	if (!SpcValue.test(v1))
	{
		return "success";
	}
	else
	{
		return "-- Please do not enter special characters such as \', \", &, %, *, +, #, ^ ";
	}
}

