// General functions used on the site
function myVoid() {;}

function windowOpen(url,width,height,left,top,name) {
	if(name){
		windowname = name;
	}else{
		windowname = "windowRef";
	}
    myWindow = window.open(url,windowname,"resizable=yes,status=yes,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
    if (!myWindow.opener) myWindow.opener = self;
}

function windowOpenScroll(url,width,height,left,top,name) {
	if(name){
		windowname = name;
	}else{
		windowname = "windowRef";
	}
	
	myWindow = window.open(url,windowname,"scrollbars=yes,resizable=yes,status=yes,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
	if (!myWindow.opener) myWindow.opener = self;
	}

function closewin(){
	window.close();
}

function mywindowOpen(url,width,height,left,top) {
	myWindow = window.open(url,"windowRef","resizable=yes,status=yes,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
	if (!myWindow.opener) myWindow.opener = self;
}

function mywindowOpenScroll(url,width,height,left,top) {
	myWindow = window.open(url,"windowRef","scrollbars=yes,resizable=yes,status=yes,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
	if (!myWindow.opener) myWindow.opener = self;
	}
function mywindowOpenBasic(url,width,height,left,top) {
	myWindow = window.open(url,"windowRef","scrollbars=yes,resizable=no,status=no,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
	if (!myWindow.opener) myWindow.opener = self;
	}
function mywindowOpenCV(url,width,height,left,top) {
	myWindow = window.open(url,"windowRef","scrollbars=no,resizable=no,status=no,width=" + width + ",height=" + height+",top="+top+",left="+left+",screenX="+top+",screenY="+left);
	if (!myWindow.opener) myWindow.opener = self;
	}

function checkText(formtext,origtext){
	if(formtext.value == origtext){
		formtext.value = "";
	}
}


function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter() {
	var footerElement = document.getElementById('footer');

	if (footerElement) {
		var makeAbsolute = true;	
		var footerHeight  = footerElement.clientHeight;
		var windowHeight = getWindowHeight();
		var contentHeight;

		if (windowHeight > 0) {
			if (document.getElementById('outer_wrapper_nolimit')){
				contentHeight = document.getElementById('outer_wrapper_nolimit').offsetHeight;
			}else if (document.getElementById('outer_wrapper')){
				contentHeight = document.getElementById('outer_wrapper').offsetHeight;			
			}

			if (windowHeight < (contentHeight - footerHeight)) {
				makeAbsolute = false;
			}
		}
		
		if (makeAbsolute)
		{
			footerElement.style.position = 'absolute';
			footerElement.style.marginLeft = '10px';
		}else{
			footerElement.style.position = 'relative';
			footerElement.style.marginLeft = '0px';
			footerElement.style.marginTop = '10px';
		}

	}
}

window.onload = function() {
	setFooter();
}

window.onresize = function() {
	setFooter();
}


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;
   
}


//check for stronger passwords
function checkPass(pw){
	var errorMsg = "";
	var msg = "";

	if (pw.indexOf(" ") > -1) {
		 errorMsg += "not include a space\n";
	}     
	if (!(pw.match(/\d/))) {
		 errorMsg += "include at least one number\n";
	}
	if (!(pw.match(/[A-Z]/))) {
		 errorMsg += "include at least one uppercase letter\n";
	}
	if (!(pw.match(/[a-z]/))) {
		 errorMsg += "include one or more lowercase letters\n";
	}
	if (!(pw.match(/[\W+|_]/))) {
		 errorMsg += "include at least one special character - £@%!\n";
	}
	if ((pw.length < 8 || pw.length > 30)) {
		 errorMsg += "be between 8 and 30 characters long\n";
	}
	if (pw.match(/(.)\1/)){
		 errorMsg += "not have 2 identical consecutive characters\n";
	}
	
	if (errorMsg != ""){
		msg = "Passwords must also  :\n\n";
		msg = msg + errorMsg;
	}
	
	return msg;
}
 
function changeBgColor(col,navitem,classname){
	var elem = document.getElementById(navitem);
	elem.style.backgroundColor = col;
	elem.className = classname;
}
	
function getLinkToPage( fieldID, currentValue )
{
	var openURL = "/cms/wteadmin/sitetools/getPageLink.cfm?fieldID=" + fieldID + "&currentValue=" + currentValue;
	windowOpenScroll(openURL, 500, 400, 10, 10, "pageLinker");
}