window.onerror = HandleError
function HandleError(){
	return true;
}
var a_vars = Array();
var pagename = document.title;
var pagenameArray=pagename.split(" : ");
var titlelen=pagenameArray.length
if(titlelen>2){
pagenameArray.shift("Winstone Aggregates")
pagename=pagenameArray.join("/");
}
var phpmyvisitesSite = 1;
//var phpmyvisitesURL = "http://www.winstoneaggregates.co.nz/phpmv2/phpmyvisites.php";

//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);
}

//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;
}
function gotoDMSadmin(){
	MM_goToURL('parent','Admin/Login.php');return document.MM_returnValue;
}
//End of Link to Admin

//Projects Display Dropdown
function selectpage(str,val){
	document.getElementById('dispnum').value=val;
	document.getElementById('selectnum').value=str
	tmt_formManager('former','submit()');
}
function turnoffnumbertable(){
	document.getElementById('Recnumbers').className="hidden";
}
function showNav(str){
	document.getElementById('Records_Info').innerHTML=str
}
//Endof Projects Display Dropdown
//Gallery Functions
function changeOutImage(imgname,width,height){
	 checkAssociation(imgname);
	 checkWindowSize(height);
     document.getElementById('preview_image').src=("Gallery/"+imgname);
	 document.getElementById('preview_image').width=width
	 document.getElementById('preview_image').height=height
}
function changeCat(str){
	if(!str){
		alert("No Category Selected!");
		return false;
	}
	MM_goToURL('parent',str);return document.MM_returnValue
}
function checkWindowSize(height){
	HM_UserAgent = navigator.userAgent;
    HM_IsSafari = (HM_UserAgent.indexOf("Safari")!=-1);
    HM_IsFireFox = (HM_UserAgent.indexOf("Firefox")!=-1);
	HM_IsIE = (HM_UserAgent.indexOf("MSIE")!=-1);
	if((height>410)&&(HM_IsIE)){
	    resizeTo(765,850)
	}
	if((height<410)&&(HM_IsIE)){
	    resizeTo(765,750)
	}
	if((height>410)&&(HM_IsSafari)){
	    resizeTo(759,790)
	}
	if((height<410)&&(HM_IsSafari)){
	    resizeTo(759,710)
	}
	if((height>410)&&(HM_IsFireFox)){
	    resizeTo(759,830)
	}
	if((height<410)&&(HM_IsFireFox)){
	    resizeTo(759,750)
	}
}
function checkAssociation(str){
	var ass=parent.document.getElementById('association').value
	if(ass=="Overburden Disposal Area"){
		parent.document.getElementById('blowuplink').href=("Belmont_Quarry_Visuals/"+str);
	}
}
//End of Gallery Functions
//Contact Us
function contactUs(){
	var whoToContact=document.getElementById('Recipient_Selection')
	if(whoToContact.value=="undefined"){
		whoToContact.selectedIndex=0;
	}
	var contactsArray=new Array();
	contactsArray['Cust']="Customer_Services@winaggs.co.nz";
	contactsArray['Daven']="DavenB@winaggs.co.nz";
	contactsArray['General']="susanp@winaggs.co.nz";
	contactsArray['TKQ']="threekings@winaggs.co.nz";
	contactsArray['HUN']="hunua@winaggs.co.nz";
	contactsArray['Brian']="brian@cobussen.biz";
	var recipient=contactsArray[whoToContact.value];
	document.getElementById('Recipient').value=recipient;
	tmt_formAction('Contact_Form','Mail.php');
    tmt_formManager('Contact_Form','submit()')
}
//End of Contact Us
//Customer Services
function showOnMap(str){
if(str=="Northland"){
	MM_swapImage('Map_Default','','images/Northland.gif',1);
}
if(str=="Auckland"){
	MM_swapImage('Map_Default','','images/Auckland.gif',1);
}
if(str=="Central North Island"){
	MM_swapImage('Map_Default','','images/Central.gif',1);
}
if(str=="Lower North Island"){
	MM_swapImage('Map_Default','','images/Lower.gif',1);
}
if(str=="South Island"){
	MM_swapImage('Map_Default','','images/South.gif',1);
}
}
//Contact Accounts
function contactWiggs(contactname){
	if(contactname=="Daven"){
		document.location.href='mailto:DavenB@winaggs.co.nz';
	}
	if(contactname=="Judith"){
		document.location.href='mailto:Juditd@winaggs.co.nz';
	}
}
//Endof Contact Accounts
//Sponsorship Application
function showmoney(str){
	document.getElementById('requestedvalue').value=str
	var a = "organisation,postal,contact_person,phone,Email,application_reason,requested,donation_value,donation_use";
	document.getElementById('monetaryone').className="";
	document.getElementById('monetarytwo').className="";
	document.getElementById('productone').className="hidden";
	document.getElementById('producttwo').className="hidden";
	document.getElementById('product_type').value="";
	document.getElementById('product_use').value="";
	document.getElementById('Require').value=a;
	document.getElementById('EmailTemplate').value="Application_Monetary_Template.htm"
	self.location.href="#bottom";
}
function showproduct(str){
	document.getElementById('requestedvalue').value=str
	var a = "organisation,postal,contact_person,phone,Email,application_reason,requested,product_type,product_use";
	document.getElementById('monetaryone').className="hidden";
	document.getElementById('monetarytwo').className="hidden";
	document.getElementById('productone').className="";
	document.getElementById('producttwo').className="";
	document.getElementById('donation_value').value="";
	document.getElementById('donation_use').value="";
	document.getElementById('Require').value=a
	document.getElementById('EmailTemplate').value="Application_Product_Template.htm"
	self.location.href="#bottom";
}
function doapplication(){
	tmt_formAction('former','Application.php');
	tmt_formManager('former','submit()')
}
function checkrequested(){
	var rq = document.former.requestedvalue.value
	if(rq=="Monetary donation"){
		showmoney("Monetary donation")
	}
	if(rq=="Winstone Aggregates product"){
		showproduct("Winstone Aggregates product")
	}else{
		return false;
	}
}
//Endof Sponsorship Application
//Product functions
function toggleInfo(str){
	var selectedTR=document.getElementById(str).className;
	var productsArray=new Array('Roading_Aggregates','Concrete_Aggregates','Specialised_Aggregates');
	for (var i=0;i<productsArray.length;i++) {
		targetTR=productsArray[i];
		document.getElementById(targetTR).className="hidden";
    }
	if(selectedTR=="hidden"){
	document.getElementById(str).className="";
	}
	if(selectedTR==""){
	document.getElementById(str).className="hidden";
	document.getElementById('About').focus();
	}
}
//End of Product functions
//DMS Login Functions
function setLoginValue(str){
	document.getElementById('Logged_In').value=str;
}
function turnOnRegistration(){
	document.getElementById('Login_Table').className="hidden";
	document.getElementById('Registration_Update_Table').className="hidden";
	document.getElementById('Remove_Table').className="hidden";
	document.getElementById('Registration_Table').className="";
	document.title="Document Management System Registration";
	//increaseLoginPopupSize();
}
function removeRegistration(){
	document.getElementById('Login_Table').className="hidden";
	document.getElementById('Registration_Update_Table').className="hidden";
	document.getElementById('Registration_Table').className="hidden";
	document.getElementById('Remove_Table').className="";
	document.title="Remove Details from DMS";
}
function updateRegistration(){
	document.getElementById('Login_Table').className="hidden";
	document.getElementById('Remove_Table').className="hidden";
	document.getElementById('Registration_Table').className="hidden";
	document.getElementById('Registration_Update_Table').className="";
	document.title="Update DMS Profile";
}
function validateRegistration(){  
   prepareValidation = setTimeout("initialisevalidation()", 2000);
}
function initialisevalidation(){
   tmt_formManager('Former','submit()');
}
function chkDMSLogin(str){  
   var xmlHttp;
   try 
    {   
	xmlHttp=new XMLHttpRequest();    
	}
    catch (e) 
    {   
	try 
	{      
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
	}
    catch (e)
    {      
	try
    {        
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
	}
    catch (e)
    {        
	alert("Your browser does not support AJAX!");        
	return false;       
	}      
	}    
	}
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
    {
	RSP=xmlHttp.responseText;
	ONUMS=RSP.split("|");
	ONUM=ONUMS[0];
	if(ONUM=="No Record"){
		alert("Currently we have no record of this email address. Please re-enter your email address.");
		popupwindow.focus();
		return false;
	}
	if(ONUM=="pending"){
		alert("Your registration has not yet been validated. Please click on the link sent in the email titled 'Document Management System Registration Validation' to validate your registration.");
		popupwindow.window.close();
		return false;
	}
	if(ONUM=="validated"){
		var user=ONUMS[1];
		var Fname=ONUMS[2];
		var Lname=ONUMS[3];
		beginDMSSession(user,Fname,Lname);
	}
    }
	}
	var url="DMS_Registration_Check.php?Email="+str;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}

function beginDMSSession(user,Fname,Lname){  
   var xmlHttp;
   try 
    {   
	xmlHttp=new XMLHttpRequest();    
	}
    catch (e) 
    {   
	try 
	{      
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
	}
    catch (e)
    {      
	try
    {        
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
	}
    catch (e)
    {        
	alert("Your browser does not support AJAX!");        
	return false;       
	}      
	}    
	}
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
    {
	ONUM=xmlHttp.responseText;
	var loggedIn=document.getElementById('Logged_In');
	loggedIn.value=user;
	popupwindow.window.close();
	navigate_external('DMS/index.php');
    }
	}
	var url="DMS_Session_Start.php?user="+user+"&firstname="+Fname+"&lastname="+Lname;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}

function removeDMSLogin(str){  
   var xmlHttp;
   try 
    {   
	xmlHttp=new XMLHttpRequest();    
	}
    catch (e) 
    {   
	try 
	{      
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
	}
    catch (e)
    {      
	try
    {        
	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
	}
    catch (e)
    {        
	alert("Your browser does not support AJAX!");        
	return false;       
	}      
	}    
	}
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
    {
	ONUM=xmlHttp.responseText;
	if(ONUM=="done"){
		returnmessage="Your details have sucessfully been removed from the DMS database.\nYou may now close this window.";
		alert(returnmessage);
		return false;
	}
	if(ONUM=="not done"){
		returnmessage="We seem to have no record of that email address.\nPlease try another email address and try again or contact Winstone Aggregates.";
		alert(returnmessage);
		return false;
	}
    }
	}
	var url="DMS_Registration_Remove.php?Email="+str;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}
//Endof DMS Login Functions
//Gallery hide scroller
function turnOffScroll(){
	document.getElementById('GalleryScroller').innerHTML="<strong>Click on a thumbnail to enlarge</strong>";
}
//Endof Gallery hide scroller
//Search Functions
function cleartxtfield(id){
	id.value=""
}
function checkData(){
	for(var i=0;i<document.form_search.sw.value.length;i++){
		if (document.form_search.sw.value.charAt(i)!=" "){
			return true;
			}
		}
		return false;
}
function holdSearch(){
	//tmt_formManager('form_search','submit()')
	alert('The site is currently being indexed. Please try again later.');
	return false;
}
//Endof Search Functions