function openWindow_func(url, wname, topleft, fullscreen, appw, apph, scroll) {
	fscreen = (fullscreen == 1)?"fullscreen":"";	
	if (topleft == 1){
		screenx = 0
		screeny = 0
	} else {
		screenx = (screen.width - appw)/2
		screeny = (screen.height - apph)/2
	}
	newWin = window.open(url, wname, "toolbar=no,status=yes,"+fscreen+",scrollbars="+scroll+",resizable=yes,menubar=no,width="+appw+",height="+apph+",left="+screenx+",top="+screeny+", maximize=yes");
	//return newWin;
}

function txtboxInit(txtboxObj, initVal){
	if (txtboxObj.value == initVal){
		txtboxObj.value = '';		
	}
	if (txtboxObj.className.substr(txtboxObj.className.length-4,4) == "init"){
		//txtboxObj.className = txtboxObj.className.substr(0,txtboxObj.className.length-4);// Bug in IE
		txtboxObj.style.color='#003366';
	} else if (txtboxObj.className.substr(txtboxObj.className.length-4,4) == "warn"){
		txtboxObj.style.color='#003366';
	}
}

function setStyle_func(obj, stylevar, styleval){
	if (navigator.userAgent.toLowerCase().indexOf("msie") > -1){
		obj.style[stylevar]=styleval;
	} else {
		obj.style[stylevar]=styleval;
	}
}

function replaceTxt_func(txtStr,replaceSelStr,replaceWithTxt){
	return txtStr.split(replaceSelStr).join(replaceWithTxt);
}

function decPlaces(no,noDecPlaces){
	return Math.round(no*Math.pow(10,noDecPlaces))/Math.pow(10,noDecPlaces);
}


function db2frm(dbValArr,frmObjArr,frm){ // Loads database values into a specified form
	var dbArrLen = dbValArr.length;
	for(i=0;i<dbArrLen;i++){
		if (frm[frmObjArr[i]]){
			if (frm[frmObjArr[i]].type == undefined){ // radio
				radSet_func(frm[frmObjArr[i]], dbValArr[i]);
			} else if (frm[frmObjArr[i]].type == "text" || frm[frmObjArr[i]].type == "textarea" || frm[frmObjArr[i]].type == "hidden"){
				frm[frmObjArr[i]].value = dbValArr[i];
			} else if (frm[frmObjArr[i]].type.indexOf("check") != -1){
				frm[frmObjArr[i]].checked=(dbValArr[i] != 0)?true:false;
				//alert(frmObjArr[i]+" "+frm[frmObjArr[i]].checked)
			} else if (frm[frmObjArr[i]].type == "select"){
				sel_func(frm[frmObjArr[i]], dbValArr[i]);
			}
		}
	}
}

function sel_func(selObj, selVal){ // Positions the select object at given index
	selL = selObj.length;
	for(p=0;p<selL;p++){
		if (String(selObj.options[p].value)==String(selVal)){
			selObj.selectedIndex=p;
			break;
		}
	}
}

function addZero(str){
	var res = str;	
	if (str.toString().length <= 1){
		res = "0"+str;
	}
	return res;
}
function inputIsPostcode(postcodetxt){
	var isFullPostcode = true;
	if (postcodetxt.length >=5 && postcodetxt.length <= 9){
		if (!isNaN(postcodetxt.substr(0,1))){
			isFullPostcode = false;
		}
		if (postcodetxt.indexOf(" ") == -1){
			postcodetxt = postcodetxt.substr(0,postcodetxt.length-3)+" "+postcodetxt.substr(postcodetxt.length-3,3);
		}
		postcode2ndPart = postcodetxt.substr(postcodetxt.length-3,3);
		if (isNaN(postcode2ndPart.substr(0,1))){ // first number of second part of postcode has to be a number
			isFullPostcode = false;
		}
		if (!isNaN(postcode2ndPart.substr(1,1)) || !isNaN(postcode2ndPart.substr(2,1))){  // second and third numbers of second part of postcode has to be a letters
			isFullPostcode = false;
		}
	} else {
		isFullPostcode = false;
	}
	return isFullPostcode;
}

function addPostcodeSpace(postcodetxt){	
	if (postcodetxt.indexOf(" ") == -1){		
		postcodetxt = postcodetxt.substr(0,postcodetxt.length-3)+" "+postcodetxt.substr(postcodetxt.length-3,3);
	}
	return postcodetxt;
}

// ******* FORM FUNCTIONS *******
function radioListCheckedVal_func(frm,radGroupName){ // Gets radiobox selected value
	res = "";
	var radObj = frm[radGroupName];
	l = radObj.length;
	for(i=0;i<l;i++){
		if (radObj[i].checked){
			res = radObj[i].value;
		}
	}
	return res;
}

function radValidate_func(radGroup){// Checks to see if a radio group has been checked
	rL = radGroup.length;
	radChked=0;
	for(a=0;a<rL;a++){
		if (radGroup[a].checked){
			radChked=1;
		}
	}
	if (radChked==1){
		return true;
	} else {
		return false;
	}
}

function sel_func(selObj, selVal){ // Positions the select object at given index
	selL = selObj.length;
	for(p=0;p<selL;p++){
		if (String(selObj.options[p].value)==String(selVal)){
			selObj.selectedIndex=p;
			break;
		}
	}
}

function radSet_func(radObj, radVal){ // Sets the radiobox group based on a radiobox value
	radL = radObj.length;
	for(p=0;p<radL;p++){
		if (String(radObj[p].value)==String(radVal)){
			radObj[p].checked=true;
			break;
		}
	}
}

function radHasVal_func(radObj, radVal){ // Checks whether the radiobox group has is checked on the given value
	var res=false;
	radL = radObj.length;
	for(p=0;p<radL;p++){
		if (String(radObj[p].value)==String(radVal) && radObj[p].checked){
			res=true;
		}
	}
	return res;
}

function radioListChecked_func(radGroupName){ // Checks if a radiobox group is checked
	radChecked=false;
	radObj = document.forms[0][radGroupName];
	l = radObj.length;
	for(i=0;i<l;i++){
		if (radObj[i].checked){
			radChecked=true;
		}
	}
	return radChecked;
}

function radSelIndex_func(radObj){ // Checks whether the radiobox group has is checked on the given value
	var radIndex=-1;
	radL = radObj.length;
	for(p=0;p<radL;p++){
		if (radObj[p].checked){
			radIndex=p;
		}
	}
	return radIndex;
}

// *************************** //






function sendXmlHttpRequestPost(url,callback,postdata) {	
	var xmlhttp=false;
	try  {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); /* for IE < 5 */
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	/* mozilla & opera */
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest();
	}	

	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	xmlhttp.onreadystatechange=function() {
		//alert(xmlhttp.readyState)
		if(xmlhttp.readyState == 4){ 
			if (xmlhttp.status == 200) {
				callback(xmlhttp.responseText);
				//alert(xmlhttp.responseText);
			}
		} else if(xmlhttp.readyState == 4 && xmlhttp.status != 200) {
			alert("Error:\n"+xmlhttp.error);
		}
	}
	xmlhttp.send(postdata); /* are sending null because we dont have any data to post */
}

function sendXmlHttpRequestGet(url,callback,callbackParam,getdata) {	// callbackParam is an array
	var xmlhttp=false;
	try  {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); /* for IE < 5 */
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	/* mozilla & opera */
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			callback(xmlhttp.responseText, callbackParam);
			//alert(xmlhttp.responseText);
		} else if(xmlhttp.readyState == 4 && xmlhttp.status != 200) {
			//alert("Error:\n"+xmlhttp.error);			
			window.status = 'http request aborted/error.';
		//} else if (xmlhttp.status == 500){
			//alert("There was an error retrieving live departure information for this station - it may not be available.")
		}
	}
	xmlhttp.send(getdata); /* are sending null because we dont have any data to post */
}

function sendXmlHttpRequestPostUpload(url,callback,postdata) {	
	var xmlhttp=false;
	try  {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); /* for IE < 5 */
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	/* mozilla & opera */
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest();
	}

	xmlhttp.open("POST",url,true);
	//xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	xmlhttp.setRequestHeader("Content-type", "multipart/form-data")
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			callback(xmlhttp.responseText);
			//alert(xmlhttp.responseText);
		} else if(xmlhttp.readyState == 4 && xmlhttp.status != 200) {
			alert("Error:\n"+xmlhttp.error);
		}
	}
	xmlhttp.send(postdata); /* are sending null because we dont have any data to post */
}



function validateForm(frm,inputsArr){
	var inputObjsL = inputsArr.length;
	var frmValid = true;
	for(i=0;i<inputObjsL;i++){
		frm[inputsArr[i]].className = 'required';
		if (frm[inputsArr[i]].type == "text" || frm[inputsArr[i]].type.indexOf("select") != -1 || frm[inputsArr[i]].type == "password"){
			if (frm[inputsArr[i]].value == ""){
				frm[inputsArr[i]].className = 'isrequired';
				frmValid = false;
			}
		}		
	}	
	return frmValid;
}


function detectIsIE6() {
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(b_version);
	if (browser.indexOf("Microsoft") != -1 && (version <= 6) ){
		// IE 6-
		return true;
	} else {
		// other browsers or IE 7+
		return false;
	}
}



function showHighlighfeature(no){
	var featObj = document.getElementById('highlightfeat'+no);
	for (i=1;i<=3;i++){
		if (document.getElementById('highlightfeat'+i)){
			document.getElementById('highlightfeat'+i).style.display="none";
		}
	}
	if (featObj){
		featObj.style.display="block";
	}
}

function randomizeBanner(){
	var rNo = Math.floor(Math.random()*19)+1; // random number 1-18
	var banner = document.getElementById('pgbanner');
	if (banner != undefined){
		if (rNo < 1 || rNo > 18){
			rNo = 1;
		}
		if (location.href.indexOf("members/") != -1){
			banner.getElementsByTagName("div")[0].style.backgroundImage = "url('../images/banners/"+rNo+".jpg')";		
		} else {
			banner.getElementsByTagName("div")[0].style.backgroundImage = "url('images/banners/"+rNo+".jpg')";		
		}
	}
}

window.onload = function(){
	randomizeBanner();
}
