
//===============================================
//Admin Section
//===============================================
//Manage Council Portals

	function CheckAll(checkAllBox, childCheckBoxName){
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["frmOne"];
		}else{
			theform = document.frmOne;
		}

		var actVar = checkAllBox.checked;
		for (i = 0; i < theform.length; i++){
			elem = theform.elements[i];
			if (elem.type == 'checkbox' && elem.name.indexOf(childCheckBoxName) != -1)
				elem.checked = actVar;
		}
	}//End of CheckAll

	function UnCheck(parentCheckBoxName){
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["frmOne"];
		}else{
			theform = document.frmOne;
			//alert(theform.length);
		}
	
		for (i = 0; i < theform.length; i++){
			elem = theform.elements[i];
			if (elem.type == 'checkbox' && elem.name.indexOf(parentCheckBoxName) != -1){
				elem.checked = false;
				break;
			}
		}//End of for loop
	}//End of UnCheck
	
	
	
//===============================================
//Foreign URL Confirmations
//When a foreign URL has been eidted into content by the Member, CInfo alerts the Citizen
//===============================================
var returnvalue = "";

//In the dark shameful past of CInfo not much attention was paid to case sensitivity. Now it
//may be the case that we don't need this but the javascript console in Firefox seems to say different
//so we put this function here as a wrapper. Many councillors have this lower case function on their links
//and as some councillors can go years before editing their page we need this for backwards compatability.

function alertforeignurl(){
	AlertForeignUrl();
}//end of alertforeignurl
	
//This function is activated when someone clicks on a Foreign Link. It is written in when a person
//adds a link. 	
function AlertForeignUrl(){
	var msg = "Please note that the inclusion of a link to another organisation's website from any pages on this website does NOT constitute a recommendation or endorsement of that organisation or its website by individual councillors or their authority\n\nClick OK to stop this message appearing again.";
	var isIE = navigator.appName.indexOf('Microsoft') != -1;
	var urlCookie = GetCookie("UrlShowConfirm");	//Get cookie
	if (urlCookie == "false"){	//If there is a cookie on the visitor's machine no need to show dialogue
		return true;	
	}else{
		if(isIE){
			window.showModalDialog("/scripts/confirm.aspx", window, "dialogHeight: 160px; dialogWidth: 520px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
			return true;
		}else{
			if(window.confirm(msg)){
				var exp = new Date(); 
				exp.setTime(exp.getTime()+ 1200000);
				SetCookie('UrlShowConfirm', 'false', exp, '/');				
				return true;
			}else{
				return true;
			}
		}	//End of the check on IE
	}
}//end of AlertForeignUrl			
					
//Function taken from scripts/confirm.aspx					
function SetCookie (name, value, exp, path) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
	//alert(document.cookie+"\n"+expires);					
}	
	
function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}//End of getCookieVal

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}//End of while loop  
	return null;
}//End of GetCookie method


//===============================================
//Form Utilities
//===============================================

function tableHover() {
	var chosen = "";
	
	if (!document.getElementsByTagName("table")){ 
		return;
	}else{//proceed with this stuff
		var myTable = document.getElementsByTagName("table");
		
		for(i = 0;i < myTable.length; i++) {
			if (myTable[i].className == "membersPortal"){
				chosen = myTable[i];
				var trTable = chosen.getElementsByTagName("tr")
				for (i = 0;i < trTable.length; i++){
					if (trTable[i].className=="user") {
						trTable[i].onmouseover=function() {this.className="userHover"}
						trTable[i].onmouseout=function() {this.className="user"}
						trTable[i].onclick = function () {location.href = this.getElementsByTagName("a")[0].href}
					}	
				}//End of the for loop going through the TR tag				
				
			}//End of if className equals "membersPortal"
		}//End of the first for loop checking the table tags
		
	}
			
		
}//End of the function tableHover

// simon willison's addloadevent http://simon.incutio.com/archive/2004/05/26/addLoadEvent
	function addLoadEvent(func) {

		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}//End of addLoadEvent

addLoadEvent(tableHover);

function LogonLoad(){
	var arInputs = document.forms[0].getElementsByTagName("input");
	for (var i = 0; i < arInputs.length; i++){
		if (arInputs[i].type == "text" && (arInputs[i].name.indexOf('SearchStringField') == -1) ){
			arInputs[i].focus();
			break;
		}
	}//End of the for loop
}//End of LogonLoad

	