// initialize ourselves when the page is
// finished loading
//window.onload = initialize;

var localUrl = document.location.href
if (localUrl.indexOf("index.php") == -1) {
	//window.stop();
	//document.location.href = "index.php?";
	
}
/** Our function that initializes when the page
    is finished loading. */
function initialize() {
   // initialize the DHTML History framework
   dhtmlHistory.initialize();
   dhtmlHistory.addListener(handleHistoryChange);
		
   // determine what our initial location is
   // by retrieving it from the browser's
   // location after the hash
   var currentLocation = dhtmlHistory.getCurrentLocation();
      
   // if there is no location then display
   // the default, which is the inbox
   if (currentLocation == "p=&s=&n=") {
      currentLocation = "section:home";
   }
   
   // extract the section to display from
   // the initial location 
   currentLocation = currentLocation.replace(/section\:/, "");
}

/** Handles history change events. */
function handleHistoryChange(newLocation, 
                             historyData) {
	var p = "";
	var s = "";
	var n = "";
   // if there is no location then display
   // the default, which is the inbox
   if (newLocation == "") {
      newLocation = "section:inbox";
   }
      
   // extract the section to display from
   // the location change; newLocation will
   // begin with the word "section:" 
   newLocation = newLocation.replace(/section\:/, "");
   newLocation = newLocation.replace(/\&/, ":");
   newLocation = newLocation.replace(/\&/, ":");
   	
	var parmPat=/p=(.*)s=(.*)n=(.*)/
	
	var result=newLocation.match(parmPat)
	for(i = 0; i < result.length; i++) 
	{
		
		myRegEx	= result[i].replace(/\:/, "");
		if(i == 1) {
			p	= myRegEx;
		}else if (i == 2) {
			s	= myRegEx;
		}else if (i == 3) {
			n	= myRegEx;	
		}
	}
	
	if(p == "") {
		p = "home";
	}
	
	callPage("content", "process.php", p, s, n, "subMenu");	
}

function CreateControl(DivID, CLSID, ObjectID,
                       WIDTH, HEIGHT, URL, MOKE)
{
  var d = document.getElementById(DivID);
  var p = "";
  var v = "";
  
  if(MOKE) {
	 p = "<PARAM NAME=FlashVars VALUE=\"xmlFile="+MOKE+"\">";
	 v = "FlashVars=\"xmlFile="+MOKE+"\"";
  }

  d.innerHTML = 
  	'<object classid="'+ CLSID +'" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ WIDTH +'" height="'+ HEIGHT +'" id="'+ ObjectID +'" align="middle">' +
	p +
	'<param name="wmode" value="transparent" />' + '<param name="allowScriptAccess" value="sameDomain" />' +
	'<param name="movie" value="'+  URL +'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'+  URL +'" '+ v +' wmode="transparent" quality="high" bgcolor="#ffffff" width="'+ WIDTH +'" height="'+ HEIGHT +'" name="header" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>';
}

function emailCheck (emailStr) {
			var emailPat=/^(.+)@(.+)$/
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var validChars="\[^\\s" + specialChars + "\]"
			var quotedUser="(\"[^\"]*\")"
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			var atom=validChars + '+'
			var word="(" + atom + "|" + quotedUser + ")"
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
			
			
			
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
				alert("Email address seems incorrect (check @ and .'s)")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]
			
			if (user.match(userPat)==null) {
				alert("The username doesn't seem to be valid.")
				return false
			}
			
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
				// this is an IP address
				  for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						alert("Destination IP address is invalid!")
					return false
					}
				}
				return true
			}
			
			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
				alert("The domain name doesn't seem to be valid.")
				return false
			}
			
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 || 
				domArr[domArr.length-1].length>3) {
			   alert("The address must end in a three-letter domain, or two letter country.")
			   return false
			}
			
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			   alert(errStr)
			   return false
			}else{
				
				document.getElementById('email_sent').style.display = 'block';
				setTimeout("swapDisplay('email_sent')",20000);
							
			
				parms	= '&p=send_form&s=contact_us';
				parms	+= '&your_email='+$('your_email').value;
				parms	+= '&your_name='+$('your_name').value;
				parms	+= '&message='+$('message').value;
				doAction('email_sent', 'process.php', parms, 'post');
 
				
				$('your_email').value	= "";
				$('your_name').value	= "";
				$('message').value	= "";
				
				window.scrollTo(0,0);
			}
			
			return false;
}

function swapDisplay(what) {
		document.getElementById(what).style.display = 'none'
}