/* This Script was developed by Jon Hughes of Phazm Webdesign */
/* PLEASE DO NOT USE WITHOUT PERMISSION */
/* CONTACT jon@phazm.com for permission. */

function init_Links() {
	var Link = document.getElementsByTagName("a");
	var LinkLength = Link.length;
	for(var i = 0;i<LinkLength;i++) {
		if(Link[i].rel.indexOf("nofollow") != -1) {
			Link[i].target = "_blank";
		};
	};
}


function GetXmlHttpObject() {
 var objXMLHttp=null;
 if (window.XMLHttpRequest)
 {
 objXMLHttp=new XMLHttpRequest()
 }
 else if (window.ActiveXObject)
 {
 try
 {
 objXMLHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0")
 }
 catch (e)
 {
 try {
 objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
 }
 catch (e) {}
 }
 }
 return objXMLHttp
}

function CallUrl(UrlToCall, IDtoFill, Parameters, InputElement){

	var CallUrlXmlHttp = null;
	CallUrlXmlHttp = GetXmlHttpObject();
	if(CallUrlXmlHttp == null){
		return;
	}
	
	if(UrlToCall == "contact.php" || UrlToCall == "order.php") {
		var InputElements = document.getElementById("innercontent").getElementsByTagName("input");
		
		for(var i=0;i<InputElements.length;i++) {
			Parameters += "&"+InputElements[i].name+"="+InputElements[i].value;
		}
		
		var InputElements = document.getElementById("innercontent").getElementsByTagName("textarea");
		
		for(var i=0;i<InputElements.length;i++) {
			Parameters += "&"+InputElements[i].name+"="+InputElements[i].value;
		}
	}
	if (!Parameters || Parameters == null || Parameters == "undefined") {
		Parameters = "";
	}
	Parameters=encodeURI(Parameters);
	CallUrlXmlHttp.onreadystatechange=CallUrlStateChanged;
	CallUrlXmlHttp.open("POST", UrlToCall, true);
	CallUrlXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	CallUrlXmlHttp.setRequestHeader("Content-Length", Parameters.length);
	CallUrlXmlHttp.setRequestHeader("Connection", "close");
	CallUrlXmlHttp.send(Parameters);
	
	function CallUrlStateChanged(){
	
		if(CallUrlXmlHttp.readyState == 4 || CallUrlXmlHttp.readyState == "complete") {
		
			if(IDtoFill != "") {
				if(InputElement) {
					document.getElementById(IDtoFill).value = CallUrlXmlHttp.responseText;
				} else {
					document.getElementById(IDtoFill).innerHTML = CallUrlXmlHttp.responseText;
				}
				init_Links();
				init_Navigation();
				init_Unobtrusify();
				init_Contact();
			}
		}
	}
}

function init_Navigation() {
	
	var Page = get_cookie("Page");
	if(Page == null || Page == "")
	return;
	
	var NavigationItems = document.getElementById("navigation").getElementsByTagName("a");

	for(var i = 0;i < NavigationItems.length;i++) {
		//alert(NavigationItems[i].href);
		NavigationItems[i].onclick = function() { CallUrl(this.href.substring(this.href.lastIndexOf('/') + 1)+'?page='+this.href.substring(this.href.lastIndexOf('/') + 1),'innercontent'); set_cookie("Page",this.href.substring(this.href.lastIndexOf('/') + 1)); RefreshNav(); this.href='javascript:void(0)' };
	}

}

function RefreshNav() {
	CallUrl('includes/innernav.php','navigation')
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );
  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path )
        cookie_string += "; path=" + escape ( path );
  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  if ( secure )
        cookie_string += "; secure";
  document.cookie = cookie_string;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}


function init_Unobtrusify() {
	
	if(document.getElementById("ContactSubmit")) {
		document.getElementById("ContactSubmit").onclick = function() { CallUrl(this.title.toLowerCase()+".php",'innercontent', 'page=contact.php&FormSent=true'); this.value='Processing...';
		this.disabled='disabled'; return false; }
	}
	
	if(document.getElementById("init_Navigation")) {
		document.getElementById("init_Navigation").onclick = function() { set_cookie("Page",this.href.substring(this.href.lastIndexOf('/') + 1)); var Page = get_cookie("Page"); init_Navigation(Page); CallUrl('examples.php?page=examples.php','innercontent'); return false; }
	}
	
	if(document.getElementById("init_NoNavigation")) {
		document.getElementById("init_NoNavigation").onclick = function() { set_cookie("Page",""); var Page = get_cookie("Page"); }
	}
	
	
	if(document.getElementById("AjaxExamples")) {
		var Examples = document.getElementById("AjaxExamples").getElementsByTagName("a");
		for(var i=0;i<Examples.length;i++) {
		Examples[i].onclick = function() { return GB_showCenter(this.title, this.href,550,750) }
		}
	}
	
}


function WindowLoad() {
	init_Links();
	if(document.getElementById("ContactSubmit"))
	init_Contact();
	init_Unobtrusify();
}

window.onload = WindowLoad;