
//
// Create link to a page. 
//
function changeAction(theForm, URL) {
	var newURL, host;
//	alert("The form action is "+URL);
	
	host = window.location.host;
	var hostParts = host.split('.');
	
	if (hostParts[0] == "www") {
		newURL = linkto(URL, true);
//		alert("1 - The new form action is "+newURL);
		theForm.action = newURL;
	}
	else {
//		alert("Server is not a www one.  No need for https here "+hostParts[0]);
	}
}

function linkto( page, secure ) {

	var protocol, host, url, port;
//	alert ("page is "+page);
	
	if ( secure == true ) {
		protocol = "https";
	} else {
		protocol = "http";
	}

	
	port = window.location.port;
	
	if ( port == "" ) {
		// Default ports, no need to change
		host = window.location.host;
	} else {
		// www stage environment, adjust ports
		if ( protocol == "http" ) {
			port = "81";
		} else {
			port = "444";
		}
		host = window.location.hostname + ":" + port;
	}
		

	// If page is a relative path - prefix with current path

	if ( page.charAt(0) != "/" ) {

		var thisPage = window.location.pathname + ' '; //Pad a space so netscape will behave properly
//		alert ("Page: " + thisPage);
		// Extract path only

		var pathComp = thisPage.split('/');
//		alert ("pathComp: "+pathComp.length);
		var i = 0;
		var path = "";
				
		for ( i = 0; i < pathComp.length - 1; i++ ) {
			if (pathComp[i].length > 0) {
				path += "/" + pathComp[i];
//				alert ("pathComp: "+ pathComp[i]);
			}
		}
		page = path + "/" + page;

	}

	url = protocol + "://" + host + page;

	//alert ( "Switching to " + url );

	return url;

}
