// util.js


function getUrl() {

	var url = window.location.href;
	var pos = 0;

	pos = url.indexOf("/", 10);
	return url.substring(0, pos);
}


function getBookUrl(sURL) {

	return sURL.replace(/http/i, "https");

}

function getWCBaseURL(sURL){

 	var bUrl =sURL.replace(/http/i, "https");
 	bUrl =bUrl.replace(/book/i, "register"); 
 	if(bUrl.indexOf("au", 6)!=-1)	{
 		bUrl.replace(/au/i, "uk");
 		bUrl.replace(/cunardline/i, "cunard");
 	}
 	return (bUrl);

}

function getWCLoginURL(){
 	var url = getWCBaseURL(getUrl()) + "/worldclub/promptbookinglogin.page?srcURL="+escape(document.location.href); 
  	document.location.href=url;
}

function getHomeURL(){

  	var url=getUrl()+'/find/pb/find.do';
  	document.location.href=url;
}


function getMiscBaseURL(){


	var bUrl = getUrl();
	var dotPos = bUrl.indexOf(".", 6);
	var servername;
	if(bUrl.indexOf("https", 0)!=-1)
 		servername = bUrl.substring(8,dotPos);
 	else
	 	servername = bUrl.substring(7,dotPos);
	var tUrl;
	if(dotPos==-1) return "http://stage.cunard.com";
	if(servername.length>6)
		tUrl= bUrl.replace(servername,'stage');
	else 
		tUrl= bUrl.replace(servername,'www');
	return tUrl;

}


function startTimer (){   

  	setTimeout ( "goToHomePage( )", 5000 );
}


function goToHomePage(){

	var tUrl= getMiscBaseURL().toString();	
	if(tUrl.indexOf("https", 0)!=-1)	{
 		tUrl=tUrl.replace(/https/i, "http");
 	}
  	window.location=tUrl;
}


function getHeaderURL(){
	
	var bRetUrl="<script src=\"aa/HeaderFooter.js\" type=\"text/javascript\"></script><script src=\"aa/stm31.js\" type=\"text/javascript\"></script>";
	var tUrl= getMiscBaseURL().toString();	
	var replaceUrl = bRetUrl.replace(/aa/gi,tUrl);
	document.write(replaceUrl);	
		
}

function getErrorPageURL()
{
	var tUrl= getMiscBaseURL().toString();	
	var dotPos = tUrl.indexOf(".", 6);
	var domainName=tUrl.substring(dotPos+1,tUrl.length);
	if(tUrl.indexOf("https", 0)!=-1)	{
 		tUrl=tUrl.replace(/https/i, "http");
 	}
	document.write("<a href=\""+tUrl+"\"  title= \"Go to "+domainName+"\">"+domainName+"</a>");
}