function displayMessage() 
{
	alert("<%=gstrError%>");
	return false
}


function ShowSub(id,visibility) {
    obj = document.getElementsByTagName("div");
    obj[id].style.display = visibility;
}
function HideSub() {
	ShowSub('sub1','none');
	ShowSub('sub2','none');
	ShowSub('sub3','none');
}

var TimeOutID;
TimeOutID = 0;
var skillWin, jtWin;

function SetMenuTimeout() {
   ResetTimeout();
   TimeOutID = setTimeout('ClearDownMenu();',5000);
}

function ClearDownMenu() {
   MM_showHideLayers('Layer1','','hide','Layer2','','hide');
}

function ResetTimeout() {
   clearTimeout(TimeOutID);
}

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_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_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); 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 getTop(ll) {
	if (ll.offsetParent)
		return (ll.offsetTop + getTop(ll.offsetParent));
	else
		return (ll.offsetTop);
}

function getLeft(ll) {
	if (ll.offsetParent)
		return (ll.offsetLeft + getLeft(ll.offsetParent));
	else 
		return (ll.offsetLeft);
}

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 CheckEmail(formname,fieldname) {
	
	// If the email entry box has something in it carry out the email
	// address validation, otherwise just return true
	if (formname.value.length > 0) {
		
		// split the entered string at the @ sign, if 
		// there aren't at least 2 array elements created
		// no @ sign was entered so therefore it is an
		// invalid email address so return false.
		string = formname.value;
		check_for_at = string.split("@");
		
		if ( ! check_for_at[0] || ! check_for_at[1] ) {
			alert(fieldname + ' must be a valid email address');
			return false;
		} else {
			
			// If there is a valid @ sign, split the second 
			// half of the string by the first dot.  If 
			// there aren't at least 2 array elements created
			// no . was entered so therefore it is an
			// invalid email address so return false.
			check_for_dot = check_for_at[1].split(".");
			if ( ! check_for_dot[0] || ! check_for_dot[1] ) {
				alert(fieldname + ' must be a valid email address');
				return false;
			}
		}

		var re = / |;/;
		if ((/[ ;]/).exec(formname.value) != null) {
			alert(fieldname + ' must be a valid email address');
			return false;
		}
	}

	return true;
}

function CheckBlank(formname,fieldname) 
{
	// If nothing has been entered return false
	
	var strTemp = formname.value;
	strTemp=strTemp.replace(/ /g,"");	
	
	if (strTemp.length < 1) {
		alert('Please complete the "' + fieldname + '" field.');
		return false;
	} else {
		return true;
	}
}

function CheckTelephone(sText,fieldname)
{
	// If not a valid telephone number return false

	var ValidChars = " +()0123456789";
	var IsValid = true;
	var Char;
	
	for (i = 0; i < sText.value.length && IsValid == true; i++) 
	{	    
	   Char = sText.value.charAt(i); 
	   if (ValidChars.indexOf(Char) == -1) 
	   {
	      IsValid = false;
	   }
	}   

	if (IsValid == false) 
	{
		alert('Please enter a valid "' + fieldname + '" number.');
		return false;
	} 
	else 
	{
		return true;
	}
	
}


function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++) 
		   { 
	   Char = sText.charAt(i); 
	   if (ValidChars.indexOf(Char) == -1) 
	      {
	      IsNumber = false;
	      }
	   }
	return IsNumber;
}




function CheckExpiredDate(field, message)
{
    var checkstr = "0123456789";
    var DateTemp = "";
        
    var DateField = field;
    DateValue = DateField.value;

    /* Delete all chars except 0..9 */
    for (i = 0; i < DateValue.length; i++) 
    {
        if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) 
        {
     		DateTemp = DateTemp + DateValue.substr(i,1);
    	}
    }
      
    DateValue = DateTemp;
           
    /* Always change date to 8 digits - string*/
    /* if year is entered as 2-digit / always assume 20xx */
    if (DateValue.length == 6) 
    {
    	DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
    }
                
      
    var year = DateValue.substr(4,4);
    var month = DateValue.substr(2,2);
    var day = DateValue.substr(0,2);
        
    var now = new Date();
    now = now.getTime(); //NN3

    var dateToCheck = new Date();
    dateToCheck.setYear(year);
    dateToCheck.setMonth(month-1);
    dateToCheck.setDate(day);
    var checkDate = dateToCheck.getTime();

    if (now < checkDate)
    {
        return true;
    }
    else
    {
        alert('Please enter ' + message + ' in the future');
        return false;
    }    
}
    

function CheckSelect(formname,fieldname,bMulti,Maxnoitems,bNoItems) {
	
	// If this is NOT a multi select
	if ( ! bMulti ) {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// Check they haven't just selected the default option
			// or even just not selected anything at all.  If this is
			// the case return false.
			mySelectedIndex = formname.selectedIndex;
			if ( formname.options[mySelectedIndex].value<1 || formname.options[mySelectedIndex].value=="" ) {
				alert('Please select ' + fieldname);
				return false;
			} 
		} 
		return true;
	
	// If this IS a multi select list
	} else {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// If selectedIndex is a negative value nothing
			// has been selected so print error and return false
			mySelectedIndex = formname.selectedIndex;
			if ( mySelectedIndex < 0 ) {
				alert('Please select ' + fieldname);
				return false;
			}
			
			// If a maximum number of items has been set check
			// that the user hasn't selected more.  If they have
			// print the error and return false.
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		} else {
			// If the user IS allowed to select nothing, just check that 
			// they haven't selected more than the maximum allowed (if
			// it is set)
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		}
		
	}

}

function contains(smstring,lrgstring) {
        //returns true if lrgstring contains smstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        istrue = false
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        istrue = true
                        break
                }
        }
        return istrue
}

function lcase(str) {
        //returns str in all lowercase letters.
        return str.toLowerCase()
}


function left(str,n) {
        //returns the left n characters from str.
        return str.substring(0,n)
}

function leftOf(smstring,lrgstring) {
        //returns leftmost characters of lrgstring up to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(0,(foundat-1))
}

function mid(str,start,n) {
        //returns a substring of str starting at 'start' that's n characters long.
        strlen = str.length
        var jj = str.substring(start-1,strlen)
        jj = jj.substring(0,n)
        return jj
}

function pcase(str) {
        //returns str in proper-noun case (first letter uppercase)
        strlen = str.length
        jj = str.substring(0,1).toUpperCase()
        jj = jj + str.substring(1,strlen).toLowerCase()
        for (i = 2; i <= strlen; i++) {
                if (jj.charAt(i)==" ") {
                        lefthalf = jj.substring(0,i+1)
                        righthalf = jj.substring(i+1,strlen)
                        righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
                        jj=lefthalf+righthalf
                }
        }
        return jj
}

function right(str,n) {
        //returns the right n characters of str
        strlen = str.length
        return str.substring(strlen-n,strlen)
}

function rightOf(smstring,lrgstring) {
        //returns the rightmost characters of lrgstring back to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=strlen2;i>=0;i--) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(foundat,255)
}

function spot(smstring,lrgstring) {
        //returns a number indicating the spot where smstring appears in lrgstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return foundat
}



function ucase(str) {
        //returns str in all uppercase letters.
        return str.toUpperCase()
}

// Create and display the progress dialog.
// end: The number of steps to completion
function ProgressCreate(end) {
	// Initialize state variables
	_progressEnd = end;
	_progressAt = 0;

	// Move layer to center of window to show
	if (document.all) {	// Internet Explorer
		progress.className = 'show';
		progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
		progress.style.top = (document.body.clientHeight/2) - (progress.offsetHeight/2);
	} else if (document.layers) {	// Netscape
		document.progress.visibility = true;
		document.progress.left = (window.innerWidth/2) - 100;
		document.progress.top = (window.innerHeight/2) - 40;
	}

	ProgressUpdate();	// Initialize bar
}

function MessageDisplay(id, str) {
  if (! document.all) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}


function cleanNumber(inputNum)
     {
     var i;
     var ch;
      var outputNum = "";
     // walk through the string character by character to build a new string with numbers only
     i = 0;
     while (i < inputNum.length)
          {
          // get the current character
         ch = inputNum.substring(i, i+1);
          if ((ch >= "0") && (ch <= "9"))
           {
              // if the current character is a digit then add it to the numbers-only string we're building
           outputNum += ch;
           }
          else
           {
           // not a digit, so check if its a dash or a space
           if ((ch != " ") && (ch != "-")) {
                 // not a dash or a space so fail
                 // return "";
              }
            }
        i++;
     }
     // we got here if we didn't fail, so return what we built
      return outputNum;
}

// Submit a form (rather than using a submit image) and set the command value
function submitForm(formname,strCommand) {

   var thisObj = eval("document." + formname);
   thisObj.command.value = strCommand;
   thisObj.submit();

}

function setCookie(name, value, expires, path, domain, secure) {
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function check_date(field,fieldname){
   var checkstr = "0123456789";
   var DateField = field;
   var Datevalue = "";
   var DateTemp = "";
   var seperator = "/";
   var day;
   var month;
   var year;
   var leap = 0;
   var err = 0;
   var i;
   err = 0;
   DateValue = DateField.value;

   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
     alert("Please enter a valid date (dd/mm/yyyy) in the " + fieldname + " field");
     DateField.select();
     DateField.focus();
   }
}

function CheckLength (formname,fieldname,minlength,maxlength) {
	if (minlength != 0) {
		if (formname.value.length < minlength) {
			alert(fieldname + ' must be greater than ' + minlength + ' characters.');
			return false;
		}
	}
	if (maxlength != 0) {
		if (formname.value.length > maxlength) {
			alert(fieldname + ' must be less than ' + maxlength + ' characters.');
			return false;
		}
	}

	return true;
}


function addBookmark(title,url)
{
    if (window.sidebar)
    {
        window.sidebar.addPanel(title, url, "");
        alert("Firefox users: This link will open in your Sidebar\nrather than the main page!\nTo prevent this please right click the link and choose\n'Properties' and then uncheck the box marked:\n'Load This Bookmark in the Sidebar'\n\nSorry about this, but it is unavoidable with Firefox");

    } 
    else if( window.opera && window.print )
    {
        alert("Opera users: By Default this link will open in your Sidebar\nrather than the main page!\nTo prevent this please uncheck the box marked\n'Show in Panel' that appears on the Add Bookmark window\n\nSorry about this, but it is currently unavoidable with Opera");
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    } 
    else if( document.all )
    {
        window.external.AddFavorite(url, title);
    }
}



function openImageSelect (section) {
	var url='/admin/imagelibrary/imageSelect.asp?section=' + section;
	
//	var newWin = window.open(url);
	var newWin = window.open(url,'newWin','location=no,scrollbars=0,toolbar=no,width=400,height=250');

}



function roundToTwoDecimalPlaces(number) {
   // Move the decimal place 2 down and round the resulting integer and move
   // the decimal place back again
   var s = "" + Math.round(number * 100) / 100

   // Find out where the decimal place is
   var i = s.indexOf('.')

   // If there is no decimal place just return the passed in number with .00
   // appended to the end.
   if (i < 0) return s + ".00"

   // Now that necessary rounding has been done get rid of any unwanted numbers
   // on the end and return the new round number.
   var roundedNumber = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
   if (i + 2 == s.length) roundedNumber += "0"
   return roundedNumber
}

function cleanFloat(inputNum)
     {
     var i;
     var ch;
      var outputNum = "";
     // walk through the string character by character to build a new string with numbers only
     i = 0;
     while (i < inputNum.length)
          {
          // get the current character
         ch = inputNum.substring(i, i+1);
          if (((ch >= "0") && (ch <= "9")) || (ch == "."))
           {
              // if the current character is a digit then add it to the numbers-only string we're building
           outputNum += ch;
           }
          else
           {
           // not a digit, so check if its a dash or a space
           if ((ch != " ") && (ch != "-")) {
                 // not a dash or a space so fail
                 // return "";
              }
            }
        i++;
     }
     // we got here if we didn't fail, so return what we built
      return outputNum;
}

function UpdateCount (afrmFormFieldName, aintMaxChar, afrmCountFieldName) {

	afrmCountFieldName.value = afrmFormFieldName.value.length;	
	if (afrmCountFieldName.value == "1") {
		afrmCountFieldName.value = afrmFormFieldName.value.length + " character";
	} else {
		if (afrmCountFieldName.value > aintMaxChar) {
			alert ("You may not enter more than " + aintMaxChar + " characters");
			
			afrmFormFieldName.value = afrmFormFieldName.value.substring(0, (aintMaxChar));
			afrmCountFieldName.style.color = "red";
		} else {									
			afrmCountFieldName.style.color = "white";
		}		
		afrmCountFieldName.value = afrmFormFieldName.value.length + " characters";	
	}
}

function getTop(ll) {
	if (ll.offsetParent)
		return (ll.offsetTop + getTop(ll.offsetParent));
	else
		return (ll.offsetTop);
}

function getLeft(ll) {
	if (ll.offsetParent)
		return (ll.offsetLeft + getLeft(ll.offsetParent));
	else 
		return (ll.offsetLeft);
}



//****************************************************************************************************/
// Detect browser
//****************************************************************************************************/
isIE = document.all;
isNN = !document.all&&document.getElementById;
isN4 = document.layers;

var lsBrowser = navigator.appName
if (lsBrowser.indexOf("Microsoft") >= 0)
	{
	var findIndex;	
	var browserVersion = 0;
	lsBrowser = "MSIE";
	browserVersion = navigator.userAgent;
	findIndex = browserVersion.indexOf(lsBrowser) + 5;
	browserVersion = parseInt(browserVersion.substring(findIndex,findIndex + 1));
	}





function CheckCheckBox(formname,fieldname,bMulti,Maxnoitems,bNoItems) {
	
	// If this is NOT a multi select
	if ( ! bMulti ) {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// Check they haven't just selected the default option
			// or even just not selected anything at all.  If this is
			// the case return false.
			mySelectedIndex = formname.selectedIndex;
			if ( formname.options[mySelectedIndex].value<1 || formname.options[mySelectedIndex].value=="" ) {
				alert('Please select ' + fieldname);
				return false;
			} 
		} 
		return true;
	
	// If this IS a multi select list
	} else {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// If selectedIndex is a negative value nothing
			// has been selected so print error and return false
			mySelectedIndex = formname.selectedIndex;
			if ( mySelectedIndex < 0 ) {
				alert('Please select ' + fieldname);
				return false;
			}
			
			// If a maximum number of items has been set check
			// that the user hasn't selected more.  If they have
			// print the error and return false.
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		} else {
			// If the user IS allowed to select nothing, just check that 
			// they haven't selected more than the maximum allowed (if
			// it is set)
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		}
		
	}

}