// FWS Site Javascript
// global declarations

function getRandom() { return Math.random(); }

var doc = docname();

function getLocation()
{
	var docLocation = new String(document.location);
	var separator = new String("</b>&nbsp;>&nbsp;<b>");
	var retString = new String("");
	var preURL = docLocation.substring(0, (docLocation.indexOf("://")+3));
	docLocation = docLocation.substring((preURL.length), docLocation.length);
	
	var aSlash = docLocation.indexOf("/");
	var domainName = docLocation.substring(0, aSlash);
	docLocation = docLocation.substring(aSlash+1, docLocation.length);
		
	if( 	(docLocation.valueOf() == "index.html") ||
		(docLocation.valueOf() == "index.htm") ||
		(docLocation.valueOf() == "index.php") ||
		(docLocation.valueOf() == "") )
	{
		retString = "<b>home</b>";
		return retString;
	}
	
	retString = "<b><a href='" + preURL + domainName + "'>home</a></b>";
	
	var sections = new Array();
	var numSections = 0;
		
	while (docLocation.valueOf() != "")
	{
		aSlash = docLocation.indexOf("/");
		if(aSlash == -1)
		{
			aSlash = docLocation.length - 1;
			sections[numSections] = docLocation.substring(0, docLocation.lastIndexOf('.'));
			if(sections[numSections].indexOf("index") == -1)
			{
				sections[numSections] = sections[numSections].replace(/_/gi, " ");
				retString = retString + separator + "<b>" + sections[numSections] + "</b>";
			}			
			docLocation = "";		
		}
		else
		{
			sections[numSections] = docLocation.substring(0, aSlash);
			if(sections[numSections] != "cgi")
			{
				retString = retString + separator + "<b><a href='" + preURL + domainName + "/";
				for(var i=0; i<=numSections; i++)
				{
					retString += sections[i] + "/";
				}
				retString += "'>" + sections[numSections].replace(/_/gi, " ") + "</a></b>";
			}
			docLocation = docLocation.substring(aSlash + 1, docLocation.length);
			
		}
		numSections++;
	}
	
	return retString;
	
}

// --- keep sidebar open for certain pages.:
function sideOpen() 
{
	var doc = docname();
	if (doc == 'web_hosting') {
		MM_changeProp('webhosting','','innerHTML',webhosting,'DIV'); show_webhosting=false; }
	if (doc == 'web_development') {
		MM_changeProp('webdevelopment','','innerHTML',webdevelopment,'DIV'); show_webdevelopment=false; }
	if (doc == 'domain_services') {
		MM_changeProp('domainservices','','innerHTML',domainservices,'DIV'); show_domainservices=false; }
	if (doc == 'domain_names'){
		MM_changeProp('domainnames','','innerHTML',domainnames,'DIV'); show_domainnames=false; }
	if (doc == 'about_us'){
		MM_changeProp('aboutus','','innerHTML',aboutus,'DIV'); show_aboutus=false; }		
	
}

function docname()
{
	var fullPath = new String(document.location);
	var firstSlash = fullPath.indexOf("/", 8);
	if(-1 != firstSlash)
	{		
		var lastSlash = fullPath.indexOf("/", firstSlash+1);				
		if(-1 != lastSlash)
		{
			return fullPath.substring(firstSlash+1, lastSlash);
		}
		return fullPath.substring(firstSlash+1, fullPath.length);				
	}
	return null;
}

function preload_docImage() 
{
	var overImg = new Array ('web_hosting','order','resellers','support','news');
	var doc = docname();
	for (var i=0;i<overImg.length;i++)
	{ 
		if (doc == overImg[i])  
		{
			MM_preloadImages(imgdir+"/"+doc+"f2.gif"); 
		}
			
	}
}

function process_registration(aForm)
{
	var domainName = new String(aForm.query.value);

	// Check that a Domain Name was entered
	if(domainName == "")
	{
		alert("Please enter a Domain Name");
		aForm.query.focus();
		return(false);
	}
	
	// Check that query does not contain illegal characters
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789--.";
	var allValid = true;
	for(var i=0; i<domainName.length; i++)
	{
		for(var j=0; j<checkOK.length; j++)
		{
			if(domainName.charAt(i) == checkOK.charAt(j))
			{
				break;
			}			
		}
		if(j == checkOK.length)
		{
			allValid == false;
			break;
		}
	}
	if (!allValid)
	{
		alerty("Domain name can only contain letters, digits and \"-.\" characters.");
    		aForm.query.focus();
    		return (false);
	}
	
	// remove a "www." prefix if it exists
	if(domainName.substring(0, 4) == "www.")
	{
		domainName = domainName.substring(4, domainName.length);
		aForm.query.value = domainName;
	}
	
	var dot = domainName.lastIndexOf('.');
	if(dot != -1)
	{		
		domainName = domainName.substring(0, dot);		
		aForm.query.value = domainName;
	}
	if(aForm.tld.value == ".ca")
	{
		document.location = "http://www.fastwebserver.ca/ca/newdomain/check.php?domain=" + domainName;
		return false;		
	}
	return true;
}

