//initialises the user mgt buttons in the banner


function WriteWelshEnglishLink(UrlPartToUse)
{
var deployURL = String(window.location);

//External
if (deployURL.indexOf("activeplacescymru") > 0 )
{
	deployURL = "http://www.lleoeddactifcymru.org.uk";
}
else if (deployURL.indexOf("lleoeddactifcymru") > 0 )
{
	deployURL = "http://www.activeplacescymru.org.uk";
}
//Esbic005s
else if (deployURL.indexOf("esbic005s:8220") > 0 )
{
	deployURL = "http://esbic005s:8110";
}
else if (deployURL.indexOf("esbic005s:8110") > 0 )
{
	deployURL = "http://esbic005s:8220";
}
//Localhost
else
{
	deployURL = "http://localhost/activeplaceswales";
}
//alert(deployURL + UrlPartToUse);
	document.getElementById('WelshEnglishLink').href = deployURL + UrlPartToUse;
}

function InitialiseBanner(UserLoggedIn, IgnoreBanner)
{
	if(UserLoggedIn == 'true'){//if user is logged in	
		document['RegisterImage'].src = "../Resources/Images/edit_profile_up.gif";
		document.getElementById('RegisterLink').href = "../View/En/EditUser.aspx"
		if(IgnoreBanner != "true"){
			document['BannerImage'].src = "../Resources/Images/banner_header_new_signout.jpg";
		}
		else
		{
			document.getElementById('SignOutLink').innerHTML = "Sign Out&nbsp;&nbsp;|&nbsp;&nbsp;";
			document.getElementById('SignOutLink').href = "Index.aspx?Action=true";
		}
	}else{//if user not logged in
		document.getElementById('registerlink').href = "../View/En/AddUser.aspx"
		if(IgnoreBanner != "true"){
			document['BannerImage'].src = "../Resources/Images/banner_header_new_signin.jpg";
		}
	}
}


//returns true if a hidden field on the page has been set
function UserLoggedIn(){
	if(document.getElementById('hdnID') == null){return false;}
	var LoggedIn = document.getElementById('hdnID').value;
	if(LoggedIn == "true")
	{return true;}
	else{return false;}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
		}
	}
	return curleft;
}
 
function MoveLogon() 
{
	var bannerTopLeftPosition = findPos(document.getElementById("ContactUsLink"));
 
 	var iframe = document.getElementById("UserLoggedInIFrame");
	var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
	var finalLeftPos = 0
	
	var lang = "";
	lang = GetLanguage();
	if (isIE)
	{
		if(lang == "en") {
			finalLeftPos = (bannerTopLeftPosition*1) - 88;
		} else {
			finalLeftPos = (bannerTopLeftPosition*1) - 119;
		}
	}
	else
	{
		//var finalLeftPos = 756 + (bannerTopLeftPosition*1);
		if(lang == "en") {
			iframe = document.getElementById("UserLoggedInIFrame");
			finalLeftPos = (bannerTopLeftPosition*1) - 76;
		} else {
			iframe = document.getElementById("UserLoggedInIFrameWelsh");
			finalLeftPos = (bannerTopLeftPosition*1) - 112;
		}
	}
	
	iframe.style.left = finalLeftPos + 'px'; 
	iframe.style.top=7 + 'px'; 
	iframe.style.visibility = 'visible';
 }

function GetLanguage()
{
	var collObjects = document.getElementsByTagName("HTML");
	if ( collObjects.length > 0)
	{
		return collObjects[0].getAttribute('lang');
	}

}

function MoveLogonBanner() 
{
	var bannerTopLeftPosition = findPos(document.getElementById("BannerText"));
 	var iframe = null;
 	var finalLeftPos = 0
 	var lang = "";
 	var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
	lang = GetLanguage();

	if (isIE)
	{
		//var finalLeftPos = 756 + (bannerTopLeftPosition*1);
		if(lang == "en") {
			iframe = document.getElementById("UserLoggedInIFrame");
			finalLeftPos = (bannerTopLeftPosition*1) - 3;
		} else {
			iframe = document.getElementById("UserLoggedInIFrameWelsh");
			finalLeftPos = (bannerTopLeftPosition*1) - 103;
		}
		iframe.style.top=2.5 + 'px';
	}
	else
	{
		//var finalLeftPos = 756 + (bannerTopLeftPosition*1);
		if(lang == "en") {
			iframe = document.getElementById("UserLoggedInIFrame");
			finalLeftPos = (bannerTopLeftPosition*1);
		} else {
			iframe = document.getElementById("UserLoggedInIFrameWelsh");
			finalLeftPos = (bannerTopLeftPosition*1) - 99;
		}
		iframe.style.top=2 + 'px';
	}
	
	iframe.style.left = finalLeftPos + 'px'; 
	iframe.style.visibility = 'visible';
} 
 
function WriteDate()
{
var mydate=new Date()
var theYear=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(dayarray[day]+"  "+daym+" "+montharray[month]+" "+theYear)
}

function WriteDateWelsh()
{
var mydate=new Date()
var theYear=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sul","Llun","Mawrth","Mercher","Iau","Gwener","Sadwrn")
var montharray=new Array("Ionawr","Chwefror","Chwefror","Ebrill","Mai","Mehefin","Gorffennaf","Awst","Medi","Hydref","Tachwedd","Rhagfyr")
document.write(dayarray[day]+"  "+daym+" "+montharray[month]+" "+theYear)
}

function ValidatePostCode()
{
	var myPostCode = document.getElementById('txtPostcode').value;
		
		if (myPostCode == "")
		{
			document.getElementById('hdnFullPostcode').value = false;
			return false;
		}else{
			var UpdatedPostcode = checkPostCode (myPostCode);
			if (UpdatedPostcode) 
			{
				//hdnFullPostcode is assigned in the checkPostCode() method
				document.getElementById('txtPostcode').value = UpdatedPostcode;
			} 
			else 
			{
				document.getElementById('hdnFullPostcode').value = false;
				document.getElementById('txtPostcode').focus();
				return false;
			}
		}
		return true;
}

function ResetPage(){
	document.Form1.reset();
}

function ReloadIfInFrameset()
		{
			// check if page loaded into a frameset
			
			if (parent.top.frames.length > 0)
			{
				if (parent.frames['mapframe'] != null)
					{
						parent.location.href = self.document.location;
					}
			}
			// check if page loaded into a popup window
			if (window.opener && !window.opener.closed)
			{
				if (parent.top.frames.length > 0)
				{
					window.opener.parent.location.href = self.document.location;
					self.close();
				} 
				else
				{
					window.opener.location.href = self.document.location;
					self.close();
				}
			}

		}
