//Menus and Navigation***************************************************************
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function navigate(str){
	MM_goToURL('parent',str);return document.MM_returnValue
}
function navigate_external(str){
	MM_openBrWindow(str,'','top=0,left=0,width=1024,height=768,scrollbars=yes,resizable=yes,status=yes')
}
function restartLogin(){
	popupwindow.window.close();
	launchpopup('../Popup_DMS_Login.php',400,230);
}
function launchpopup(url,w,h){
	var width=w, height=h;
    var left = (screen.width/2) - width/2;
    var top = (screen.height/3) - height/3;
    MM_openBrWindow(url,'','top='+top+',left='+left+',width='+w+',height='+h)
}
function BC_swapClass() {
   BC_swapClassRestore()
   var i,j=0,x,a=BC_swapClass.arguments; 
   document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oClassName) x.oClassName=x.className; x.className=a[i+2];}
}
function BC_swapClassRestore() { //v3.0
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oClassName;i++) x.className=x.oClassName;
}
function calmenutop(imgid){
	var TT = findObj(imgid)
	var yPos = eval(TT).offsetTop;
	var tempEl = eval(TT).offsetParent;
  	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
function calmenuleft(imgid){
	var LL = findObj(imgid)
	var xPos = eval(LL).offsetLeft;
	var tempEl = eval(LL).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
//End of Menus and Navigation************************************************************

//Generic Functions**********************************************************************
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function tmt_formManager(f,c){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"')."+c);}
}
function tmt_formAction(f,p){
	if(MM_findObj(f)){eval("MM_findObj('"+f+"').action='"+p+"'");}
}
function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}
function reposmenus(){
	newheight=getHeight()
	if(newheight!=currentheight){
	var curloc = document.location.href
    MM_goToURL('parent',curloc); 
	return document.MM_returnValue;
	}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function getHeight(){
	return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
}
function getWidth(){
	return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
}
function close_window() {
    window.close();
}
//End of Generic Functions***************************************************************
//Popup Boxes
function launchpopup(url,w,h){
	var width=w, height=h;
    var left = (screen.width/2) - width/2;
    //var top = (screen.height/2) - height/2;
	var top = 10;
    MM_openBrWindow(url,'','top='+top+',left='+left+',width='+w+',height='+h)
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  popupwindow=window.open(theURL,winName,features);
}
function close_window() {
    window.close();
}
//End of Popup Boxes
//Link to Admin
function gotoadmin(){
	MM_goToURL('parent','Admin/Login.php');return document.MM_returnValue;
}
//End of Link to Admin
function showLocation(str){
	var targetTable=document.getElementById(str)
	var locationArray=new Array('Whangarei','Auckland','Tauranga','Hamilton','Rotorua','New Plymouth','Stratford','Hastings','Palmerston North','Wellington','Nelson','Greymouth','Christchurch','Timaru','Dunedin','Alexandra','Queenstown','Invercargill','Taupo','Te Kuiti','Masterton','Amberley','Oamaru','Cromwell','Winton','Warkworth');
	for (var i=0;i<locationArray.length;i++) {
		var locTable=locationArray[i];
		var isTablePresent=document.getElementById(locTable);
		if(isTablePresent){
		document.getElementById(locTable).className="hidden";
		}
    }
	if(targetTable){
	document.getElementById(str).className="";
	}
}
function seekDBdetails(str){
	locationPages=new Array();
	locationPages['Humes Pipeline Systems']="Location_DB_Details.php#";
	locationPages['Hynds Pipe Systems']="Hynds_Location_DB_Details.php#";
	var pageTitle=document.title
	var pageTitleArray=pageTitle.split(" : ");
	var pageTitleTarget=pageTitleArray[2];
	page=locationPages[pageTitleTarget];
	document.getElementById('Locations').src=(page+str)
}
function seekdetails(str){
	locationPages=new Array();
	locationPages['Humes Pipeline Systems']="Location_Details.php#";
	locationPages['Hynds Pipe Systems']="Hynds_Location_Details.php#";
	var pageTitle=document.title
	var pageTitleArray=pageTitle.split(" : ");
	var pageTitleTarget=pageTitleArray[2];
	page=locationPages[pageTitleTarget];
	document.getElementById('Locations').src=(page+str)
}
function hideLocation(){
	var locationArray=new Array('Whangarei','Auckland','Tauranga','Hamilton','Rotorua','New Plymouth','Stratford','Hastings','Palmerston North','Wellington','Nelson','Greymouth','Christchurch','Timaru','Dunedin','Alexandra','Queenstown','Invercargill','Taupo','Te Kuiti','Masterton','Amberley','Oamaru','Cromwell','Winton','Warkworth');
	for (var i=0;i<locationArray.length;i++) {
		var locTable=locationArray[i];
		var isTablePresent=document.getElementById(locTable);
		if(isTablePresent){
		document.getElementById(locTable).className="hidden";
		}
	}
}
var hideLocationtimer;
function activateTimer(){
	if(hideLocationtimer){
	clearTimeout(hideLocationtimer);
	}
	hideLocationtimer=setTimeout("hideLocation()", 2000);
}
function in_array(needle, haystack, argStrict) {
    var found = false, key, strict = !!argStrict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}
//Toggle Header/footer/news
function toggleHeader(){
	var isPresent=currentdisplay=document.getElementById('headerOne');
	if(!isPresent){
		return false;
	}
	var currentdisplay=document.getElementById('headerOne').className
	if(currentdisplay=="hidden"){
		document.getElementById('headerOne').className="";
		document.getElementById('headerTwo').className="hidden";
	}else{
		document.getElementById('headerOne').className="hidden";
		document.getElementById('headerTwo').className="";
	}
}
function toggleFooter(){
	var isPresent=currentdisplay=document.getElementById('footerOne');
	if(!isPresent){
		return false;
	}
	var currentdisplay=document.getElementById('footerOne').className
	if(currentdisplay=="hidden"){
		document.getElementById('footerOne').className="";
		document.getElementById('footerTwo').className="hidden";
	}else{
		document.getElementById('footerOne').className="hidden";
		document.getElementById('footerTwo').className="";
	}
}
function toggleNews(){
	var isPresent=currentdisplay=document.getElementById('newsOne');
	if(!isPresent){
		return false;
	}
	var currentdisplay=document.getElementById('newsOne').className
	if(currentdisplay=="hidden"){
		document.getElementById('newsOne').className="";
		document.getElementById('newsTwo').className="hidden";
	}else{
		document.getElementById('newsOne').className="hidden";
		document.getElementById('newsTwo').className="";
	}
}
//Endof Header/footer
//Contact Us
function emailRecipient(str){
	var contactsArray=new Array();
	contactsArray['frank']="frank.swanberg@shorenz.co.nz";
	contactsArray['jarrad']="jarrad.christie@shorenz.co.nz";
	contactsArray['ross']="ross.hansen@humes.co.nz";
	contactsArray['molly']="molly.hulbert@csppacific.co.nz";
	contactsArray['enquiries']="enquiries@shorenz.co.nz";
	var recipient=contactsArray[str];
	document.location.href='mailto:'+recipient;
}
function requestDVD(id){
	if(id.checked==1){
		document.getElementById('PostalDetails').className="";
		document.getElementById('Require').value="Name,Email,Enquiry,Postal_Address";
		document.getElementById('PostalAsterisk').className="asterisk";
	}else{
		document.getElementById('PostalDetails').className="hidden";
		document.getElementById('Require').value="Name,Email,Enquiry";
		document.getElementById('PostalAsterisk').className="hidden";
	}
}
function contactUs(){
	tmt_formAction('former','Mail.php');
	tmt_formManager('former','submit()');
}
function checkDVDRequest(){
	var DVD=document.getElementById('demoDVD');
	requestDVD(DVD);
}
//Endof Contact Us
//Web stats
function seekStats(){
	tmt_formManager('StatsForm','submit()');
}
//Print Location
function sendtoprt(oTgt){
	parent.frames[oTgt].focus();
	parent.frames[oTgt].print();
}
function ActivateSlideRailMenu(str){
	document.getElementById('Slide_Rail_System').className="slide_rail_button_on";
	document.getElementById('SlideRailMenu').className="";
	document.getElementById('Slide_Rail_menu_spacing').className="hidden";
	var MenuContainer=document.getElementById('SlideRailMenu')
	MenuContainer.getElementsByTagName('a').item(str).style.color="E05224";
}