function init() {
		checkWindowSize();
		checkWindowSize2();			
		setUsernamePassword();
		loadStyleSheet();

	window.onresize = function() {
		checkWindowSize();
		checkWindowSize2();
	}
}

// stylesheet changing for font sizes

function loadStyleSheet() {
	var soaData = getCookie('soa_style');
	
	if (soaData != null) {
		var i;
		var myArray = document.getElementsByTagName('link');
		var copy = 'copy';
		
		for (i=0; i<myArray.length; i++) {
			var arrayAttributeType = myArray[i].getAttribute('href');
			
			if (arrayAttributeType.indexOf('copy') > -1) {
				var ss = soaData;
				myArray[i].setAttribute('href', ss);
			}
			
		}
		
	}
	
}

function setStyleSheetSmall() {
		var i;
		var myArray = document.getElementsByTagName('link');
		var copy = 'copy';
		
		for (i=0; i<myArray.length; i++) {
			var arrayAttributeType = myArray[i].getAttribute('href');
			
			if (arrayAttributeType.indexOf('copy') > -1) {
				var ss = '/media/styles/copy_small.css';
				myArray[i].setAttribute('href', ss);
				setCookie("soa_style", ss, 87650, "/");
				return false;
			}
			
			else {
				return false;
			}
			
		}
}

function setStyleSheetNormal() {
		var i;
		var myArray = document.getElementsByTagName('link');
		var copy = 'copy';
		
		for (i=0; i<myArray.length; i++) {
			var arrayAttributeType = myArray[i].getAttribute('href');
			
			if (arrayAttributeType.indexOf('copy') > -1) {
				var ss = '/media/styles/copy.css';
				myArray[i].setAttribute('href', ss);
				setCookie("soa_style", ss, 87650, "/");
				return false;
			}
			
			else {
				return false;
			}
			
		}
}

function setStyleSheetLarge() {
		var i;
		var myArray = document.getElementsByTagName('link');
		var copy = 'copy';
		
		for (i=0; i<myArray.length; i++) {
			var arrayAttributeType = myArray[i].getAttribute('href');
			
			if (arrayAttributeType.indexOf('copy') > -1) {
				var ss = '/media/styles/copy_large.css';				
				myArray[i].setAttribute('href', ss);
				setCookie("soa_style", ss, 87650, "/");
				return false;
			}
			
			else {
				return false;
			}
			
		}
}

function setCookie(name, value, exp, path, domain, secure) {
//alert(name + value + exp);
	var expires = new Date();
	expires.setTime(expires.getTime() + (exp * 3600 * 1000));
//alert(expires);
	document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +
//        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

}

function getCookie(name) {

	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) {

	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}

}


function setUsernamePassword() {
	if (document.getElementById("loginForm")) {
		var theForm = document.getElementById("loginForm");
		if (getCookie("soa_username")) {
			theForm.username.value = getCookie("soa_username");
		}
		if (getCookie("soa_password")) {
			theForm.password.value = getCookie("soa_password");
			theForm.savedetails.checked = "checked";
		}
	}
}

function saveUsernamePassword() {
	if (document.getElementById("loginForm")) {	
		var theForm = document.getElementById("loginForm");
	
		deleteCookie("soa_username", "/");
		deleteCookie("soa_password", "/");
		
		if (theForm.savedetails.checked) {
//	alert("Details being saved");
			setCookie("soa_username", theForm.username.value, 87650, "/");
			setCookie("soa_password", theForm.password.value, 87650, "/");
			<!-- exp passed is passed as an hour - we have set to 87650 so it lasts 10 years -->
		}
			
		return true;
	}
}

function expandDiv() {
		if (document.getElementById('hidden-container')) {
				document.getElementById('hidden-container').style.display = 'block';
		}
}

function collapseDiv() {
		if (document.getElementById('hidden-container')) {
				document.getElementById('hidden-container').style.display = 'none';
		}
}



function getNextObject(n) { 
	n = n.nextSibling;
	while (n && !n.tagName) {
		n = n.nextSibling;
	} 
	return n; 
} 

function getPreviousObject(n) { 
	p = p.previousSibling;
	while (p && !p.tagName) {
		p = p.previousSibling;
	} 
	return p; 
} 

	function toggleTr(aTagRef) {
		parentNextSibling = getNextObject(aTagRef.parentNode);
		parentNextSiblingId = parentNextSibling.getAttribute('id');
//			alert(parentNextSibling.style.display);		
		if (parentNextSiblingId == "hidden-list-container") {
			if (parentNextSiblingId == "hidden-list-container" && parentNextSibling.style.display == 'block') {
				parentNextSibling.style.display = 'none';
				return false;
			}		
			parentNextSibling.style.display = 'block';
		}
	}

	function checkPassword(theForm) {
		enteredPassword = theForm.password.value;
		lowerPassword = enteredPassword.toLowerCase();
		
		if (lowerPassword.indexOf(" ") > -1) {
			finalPassword = lowerPassword.replace(/ /g, "");
			theForm.password.value = finalPassword;
		}
	}

	function checkWords(theTextArea) {
		areaValue = theTextArea.value;
		areaSplit = areaValue.split(' ');
		var finalString = '';
		if (areaSplit.length > 150) {
			for (var i = 0; i < 150; i++) {
				if (i == 149) {
					finalString = finalString + areaSplit[i];
				}
				else {
					finalString = finalString + areaSplit[i] + " ";
				}
			}
			theTextArea.value = finalString;
			alert('Word limit reached. Please make sure your personal statement is no more then 150 words');
		}
	}
