//Functions used by Engineers Compendium pages

function getSearchAsArray() {
   // Browser-sniffing variables.
   var minNav3 = (navigator.appName == "Netscape" && 
      parseInt(navigator.appVersion) >= 3);
   var minIE4 = ((navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4));
   var minDOM = minNav3 || minIE4;   // Baseline DOM required for this function
   // Initialize array to be returned.
   var results = new Array();
   if (minDOM) {
      // Unescape and strip away leading question mark.
      var input = unescape(location.search.substring(1));
      if (input) {
         // Divide long string into array of name/value pairs.
         var srchArray = input.split("&");
         var tempArray = new Array();
         for (i = 0; i < srchArray.length; i++) {
            // Divide each name/value pair temporarily into a two-entry array.
            tempArray = srchArray[i].split("=");
            // Use temp array values as index identifier and value.
            results[tempArray[0]] = tempArray[1];
         }
      }
   }
   return results;
}

function EmailLink(){
window.location = "mailto:"+"?subject=I thought this link might interest you."+"&body="+document.title+"  "+window.location;
}

function Sendkey(){
window.location = "mailto:engcomp@gmail.com"+"?subject=Please send access key for Engineers Compendium"+"&body=From "+document.signup.name.value+"\r\n"+document.signup.comments.value;
}

function addfavorites(loc,title){
  window.external.addfavorite(loc+", "+title);
}

function address(loc,mod) {
document.write ("\r\n");
document.write ("<HR>\r\n");
document.write ("<P class=\"address\">Sheba Conctruction & Management Pty. Limited established 1974\r\n");
document.write ("<BR>trading as <A style=\"color:blue\" href=\"http://www.engs-comp.com/index.html\">Engineers Compendium</A>\r\n");
document.write ("<BR>Australian Company Number 001 212 684\r\n");
document.write ("<BR>PO Box 2160 Bowral, NSW, 2576 Australia\r\n");
document.write ("<BR>Phone (02) 4862 1295 Fax (02) 4862 2485\r\n");
document.write ("<BR>Email <A style=\"color:blue\" href=\"mailto:engcomp@gmail.com\">engcomp@gmail.com</A>\r\n");
document.write ("<BR>URL:&nbsp;");
document.write (loc+" modified "+mod+"\r\n");
document.write("<FORM><INPUT class=\"select\" TYPE=\"button\" VALUE=\"E-mail this link to a friend\" onClick=\"EmailLink()\"></FORM>");
document.write ("</P>\r\n");
}

//Copyright Yehuda Shiran, Ph.D
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

// Copyright 2000 William Bontrager
function SetName() {
	var name=document.signup.Name.value;
	if (name == "" || name==" ") {
		alert("Please enter a name");
		document.signup.Name.focus();
		return false;
	}
	
	PutCookie("visitorname",name);
}

function SetEmail() {
	var emailvalue=document.signup.Email.value;
	if (! isEmail(emailvalue)) {
		alert("Please enter a proper email address");
		document.signup.Email.focus();
		return false;
	}

	PutCookie("visitoremail",emailvalue);

}

function GetVisits(name) {
	var cookievalue = '0';
	if(document.cookie.length > 0) {
		cookiename = name + '=';
		cookiebegin = document.cookie.indexOf(cookiename);
		cookieend = 0;
		if(cookiebegin > -1) {
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			cookievalue = document.cookie.substring(cookiebegin,cookieend);
		}
	}
	var value = parseInt(cookievalue) + 1;
	PutCookie(name,value);
	return value;
}

function PutCookie(n,v) {
	var expir = '';
	if(DaysToLive > 0) {
		var now = new Date();
		then = now.getTime() + (DaysToLive * 24 * 60 * 60 * 1000);
		now.setTime(then);
		expir = '; expires=' + now.toGMTString();
	}
	else {
		expir = "";
	}
	document.cookie = n + "=" + v + "; path=/; domain=.engs-comp.com" + expir;
}

/*
function GetCookie(name) {
	var cookiecontent = '';
	if(document.cookie.length > 0) {
		var cookiename = name + '=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) {
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
			cookiecontent = unescape(cookiecontent);
		}
	}
	return cookiecontent;
}
*/
function GetCookie(name) {

    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
    
}

function Popup(url,w,h) {
	var attributes = 'resizable=yes,scrollbars=yes,' + 
	'width=' + w + ',height=' + h + ',top=0,left=0';
	window.open(url,"DescPopup",attributes);
} 

function MsgBox(aText, aTitle) 
{ MsgBox=window.open("","MsgBox","width=300,height=100,menubar=no,locationbar=no,resizable=no,status=no,scrollbars=yes");
  with (MsgBox.document)
  { open();
    writeln("<html><head><title>"+aTitle+"</title></head>");
//    writeln("<body onblur='this.close()'>");
    writeln("<body>");
    writeln(aText);
    writeln("</body></html>");
    close();
  }
}

function ImplixPop()
 {
  if (top.name != 'ImplixPopup') {
    var display = 'http://www.implix.com/popup1.html?user=39111';
    newwin = 
window.open(display,'ImplixExit','Width=370,Height=180,toolbar=no,menubar=no,scrollbars=no,status=no,resizable=no,location=no');
   }
 }
/*
function swarm() {

	if (top.name!='TrafficSwarm') {

//		var swarmurl = 'http://www.trafficswarm.com/cgi-bin/swarm.cgi?' + id;
		var swarmurl = 'http://www.trafficswarm.com/go.cgi?18396';
		window2=window.open(swarmurl,'TrafficSwarm','width=750,height=550,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');
		window2.blur();
		window.focus();
		return true;
	}
}
/*
function swarmnew() {

	var tsuser = GetCookie('LID');

	if (tsuser == null || tsuser == id) {
	
		if (top.name!='TrafficSwarm') {
			
			var swarmurl = 'http://www.trafficswarm.com/cgi-bin/exit.cgi?' + id;
			if (typeof cat != "undefined") { swarmurl += '&' + cat; }

			window2=window.open(swarmurl,'TrafficSwarm','width=750,height=550,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');
			window2.blur();
			window.focus();
			return true;
		}	
	}
}
*/
function SetCookie (name, value) {

	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");

}

var expir = new Date(); 
expir.setTime(expir.getTime() + 1200000);

function swarm() {

	var tsexit = GetCookie('TSEXIT');
	
	if (tsexit == null || tsexit != id) {
	
		var tsuser = GetCookie('LID');
	
		if (tsuser == null || tsuser == id) {

			if (top.name!='TrafficSwarm') {

				SetCookie('TSEXIT', id, expir);

				var swarmurl = 'http://www.trafficswarm.com/cgi-bin/exit.cgi?' + id;
				if (typeof cat != "undefined") { swarmurl += '&' + cat; }

				exit = window.open(swarmurl,'TrafficSwarm','width=750,height=550,left=1,right=1,top=0,toolbar=yes,menubar=yes,scrollbars=yes,status=yes,resizable=yes,status=yes,location=yes');
				
				exit.blur();
				self.focus();

				return true;

			}	

		}
	
	}
        
}

var id = '18396';
var cat = '15';
// document.onunload=swarm();
// window.onunload=swarm();