window.onerror = HandleError
function HandleError(){
	return true;
}


var TechOpen;
function SearchLevelOne(event){
	if(TechOpen){
		CloseTechnicalRecords();
	}
	data='';
	$.post("TechnicalSearch.php",$("#TechnicalDataForm").serialize(),
	function(data) { 
	if(!data){
		return false
	}
	dataRetreived=data.split("|");
	dataRetreived.pop();
    document.getElementById('LevelTwo').length=0;
	AddItem('Select Type','','LevelTwo')
	for (var i=0;i<dataRetreived.length;i++) {
		currentdata=dataRetreived[i];
	    AddItem(currentdata,currentdata,'LevelTwo')
	   }
 });
}
function AddItem(Text,Value,fieldTarget){
	var optionbox=fieldTarget;
    var opt = document.createElement("option");
    document.getElementById(optionbox).options.add(opt);       
    opt.text = Text;        
    opt.value = Value; 
}
function PopulateTechnicalItems(event){
	var LevelOneSelected=document.getElementById('LevelOne').value;
	var LevelTwoSelected=document.getElementById('LevelTwo').value;
	PullTechnicalRecords(LevelOneSelected,LevelTwoSelected);
	document.getElementById('TechnicalRecordsHeading').innerHTML='';
	LoadTechnicalRecords(LevelOneSelected,LevelTwoSelected)
	$('.TechnicalRecordsHeading').css({ "background-image" : "url(images/ajax-loader.gif)" });
	$('.TechnicalRecordsHeading').css({ "background-repeat" : "no-repeat" });
	$('.TechnicalRecordsHeading').css({ "background-position" : "right top" });
}
function LoadTechnicalRecords(LevelOneSelected,LevelTwoSelected){
    $('.TechnicalLibraryRecords').slideDown({
    duration:400,
    complete:function(){
	document.getElementById('TechnicalRecordsHeading').innerHTML=LevelTwoSelected;
    TechOpen='Yes';
	
    }
 }); 
}
function CloseTechnicalRecords(){
    $('.TechnicalLibraryRecords').slideUp({
    duration:400,
    complete:function(){
	document.getElementById('TechnicalRecordsHeading').innerHTML='';
	document.getElementById('TechnicalRecordsContainer').innerHTML='';
	$('.TechnicalRecordsHeading').css({ "background-image" : "url(images/ajax-loader.gif))" });
	$('.TechnicalRecordsHeading').css({ "background-repeat" : "no-repeat" });
	$('.TechnicalRecordsHeading').css({ "background-position" : "right top" });
	TechOpen='';
    }
 }); 
}

function PullTechnicalRecords(LevelOneSelected,LevelTwoSelected){
$.ajax({ 
   type: "POST", 
   url: "TechnicalRecordRetreiver.php?TopLevel="+LevelOneSelected+"&LevelTwo="+LevelTwoSelected, 
   success: function(msg){ 
   document.getElementById('TechnicalRecordsContainer').innerHTML=msg;
	LoadStandardFancy();
	LoadVideoFancy();
	LoaderTimer=setInterval('ReloadHeadingStyle()', 500);
    } 
   });
}
function ReloadHeadingStyle(){
	$('.TechnicalRecordsHeading').css({ "background-image" : "url(images/CustomDivide.png)" });
	$('.TechnicalRecordsHeading').css({ "background-repeat" : "repeat-x" });
	$('.TechnicalRecordsHeading').css({ "background-position" : "center bottom" });
	clearInterval(LoaderTimer)
}
function LoadStandardFancy(){
$(".FancyLiterature, #StandardLink a").click(function() {
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}
var ReloadMenu;
function LoadVideoFancy() {
$(".video, #youtubeVideo a").click(function() {
	$.fancybox({
	'padding'		: 0,
	'autoScale'		: false,
	'transitionIn'	: 'none',
	'transitionOut'	: 'none',
	'width'			: 640,
	'height'		: 385,
	'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	'type'			: 'swf',
	'swf'			: {
	'wmode'				: 'transparent',
	'allowfullscreen'	: 'true',
	'titleShow'         : false
	}
	});

	return false;
 });
}
function LoadPriceBookFancy() {
$(".FancyPriceBook, #PriceBookRecord a").click(function() {
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}
function LoadFancyProject() {
$(".ProjectLightBox, #ProjectPopupLink a").click(function() {
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}
function LoadFancyNews() {
$(".NewsLightBox, #NewsPopupLink a").click(function() {
	$.fancybox({
	'height'		    : 400,
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'auto',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}

function LoadFancyLiterature() {
$(".FancyLiterature, #ProductLiteratureDoc a").click(function() {
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}
function LaunchLatestPriceBook(URL){
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : URL
	});
}
function LaunchLatestProject(URL){
	$.fancybox({
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : URL
	});
}
function LaunchApplications(){
	$.fancybox({
	'height'		    : 400,
	'width'             : 785,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'no',
	'titleShow'         : false,
	'href'			    : 'PopupApplications.php'
	});
}
function LaunchMiniApplications(App,HT){
	$('#HM_Menu30').css({ "visibility" : "hidden" });
	BC_swapClassRestore();
	$.fancybox({
	'height'		    : HT,
	'width'             : 418,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'no',
	'titleShow'         : false,
	'href'			    : 'PopupApplicationSearch.php?Application='+App
	});
}
function LaunchProduct(RecId,Application){
	if(!RecId){
		//alert('Product category not in system yet')
		//return false;
	}
	MM_goToURL('parent','SearchProducts.php?ProductClass='+RecId+'&Application='+Application);
	return document.MM_returnValue
	parent.$.fancybox.close()
}
function LaunchFBCareers(){
    $.fancybox({ 
	'height'		    : '90%',
	'width'             : 1050,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'href'              : 'http://www.fbcareers.com',
	'scrolling'         : 'yes'
	});
}
function LaunchPrivacy(){
    $.fancybox({ 
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 15,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'href'              : 'Privacy_Policy.php',
	'scrolling'         : 'yes'
	});
}
function LaunchLegal(){
    $.fancybox({ 
	'height'		    : '90%',
	'width'             : 1003,
	'padding'           : 15,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'href'              : 'Legal.php',
	'scrolling'         : 'yes'
	});
}

function LoadFancyTechTeam() {
$(".TechTeamLightBox, #TechTeamPopupLink a").click(function() {
	$.fancybox({
	'height'		    : 400,
	'width'             : 500,
	'padding'           : 12,
	'margin'            : 0,
	'autoScale'			: true,
	'autoDimensions'	: true,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'type'				: 'iframe',
	'scrolling'         : 'yes',
	'titleShow'         : false,
	'href'			    : this.href
	});
	return false;
});
}
function FireOffPassword() {
	tmt_formManager('former','submit()')
}
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 calmenutop(imgid){
	var TT = findObj(imgid);
	if(!TT){
		return 10;
	}
	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)
	if(!LL){
		return 10;
	}
	var xPos = eval(LL).offsetLeft;
	var tempEl = eval(LL).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

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 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 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 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 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 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 CheckEntry(){
	var RequiredFields=new Array('CustProjName','Address','City','PostCode','InstallDate','Product','Colour','Application','Size');
	var RequiredCount=0;
	for (var i=0;i<RequiredFields.length;i++) {
		var fieldValue=document.getElementById(RequiredFields[i]).value
		if(!fieldValue){
			document.getElementById(RequiredFields[i]).style.backgroundColor="#FFC6C6";
			RequiredCount++;
		}else{
			document.getElementById(RequiredFields[i]).style.backgroundColor="#FFFFFF";
		}
	}
	if(RequiredCount>0){
		alert('The Following Field(s) are Required!');
		return false;
	}else{
	    tmt_formManager('former','submit()')
	}
}
function navigate_external(str){
	MM_openBrWindow(str,'','top=0,left=0,width=1024,height=768,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}
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 NavigateToProduct(Dest,MenuId){
$.ajax({ 
   type: "POST", 
   url: "SaveMenuCookie.php?MenuId="+MenuId, 
   success: function(msg){ 
   AuxMenu=setInterval( function() { RenewCookie(Dest,MenuId); }, 1000 ); 
   } 
 });
}
function RenewCookie(Dest,MenuId){
	clearInterval(AuxMenu)
$.ajax({ 
   type: "POST", 
   url: "SaveMenuCookie.php?MenuId="+MenuId, 
   success: function(msg){ 
   navigate(Dest)
   } 
 });
}
function SaveCookie(MenuId){
$.ajax({ 
   type: "POST", 
   url: "SaveMenuCookie.php?MenuId="+MenuId, 
   success: function(msg){ 
   alert(msg)
   } 
 });
}

function navigate(str){
	MM_goToURL('parent',str);return document.MM_returnValue
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  popup=window.open(theURL,winName,features);
}
function PassToEmail(str){
	document.getElementById('Email').value=str;
}
function PassToProject(str){
	document.getElementById('Project').value=str;
}
function CheckContactForm(){
	var requiredCount=0;
	var requiredFields=new Array('Firstname','Lastname','Email','Location','Message');
	var requiredFieldNames=new Array('First Name','Lastname','Email','Location','Message');
	var EmailEntered=document.getElementById('Email').value;
	var TermsAgree=document.getElementById('Terms');
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredFields[i]).style.backgroundColor="#bfd5e9";
			requiredCount++;
		}else{
			document.getElementById(requiredFields[i]).style.backgroundColor="#FFFFFF";
		}
	}
	
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
		return false;
	}else{
	   CheckEmailAddress(EmailEntered)
	}
}
function CheckSubscriptionForm(){
	alert('go')
	var requiredCount=0;
	var requiredFields=new Array('Firstname','Lastname','Email');
	var requiredFieldNames=new Array('First Name','Lastname','Email');
	var EmailEntered=document.getElementById('Email').value;
	var TermsAgree=document.getElementById('Terms');
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredFields[i]).style.backgroundColor="#bfd5e9";
			requiredCount++;
		}else{
			document.getElementById(requiredFields[i]).style.backgroundColor="#FFFFFF";
		}
	}
	
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
		return false;
	}else{
	   CheckEmailAddress(EmailEntered)
	}
}

function CheckEmailAddress(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid Email Address");
		   document.getElementById('Email').style.backgroundColor="#92C94A";
		   document.getElementById('Email').focus();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid Email Address");
		   document.getElementById('Email').style.backgroundColor="#92C94A";
		   document.getElementById('Email').focus();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid Email Address");
		    document.getElementById('Email').style.backgroundColor="#92C94A";
		    document.getElementById('Email').focus();
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid Email Address");
		    document.getElementById('Email').style.backgroundColor="#92C94A";
		    document.getElementById('Email').focus();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid Email Address");
		    document.getElementById('Email').style.backgroundColor="#92C94A";
		    document.getElementById('Email').focus();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid Email Address");
		    document.getElementById('Email').style.backgroundColor="#92C94A";
		    document.getElementById('Email').focus();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid Email Address");
		    document.getElementById('Email').style.backgroundColor="#92C94A";
		    document.getElementById('Email').focus();
		    return false;
		 }
		 document.getElementById('Email').style.backgroundColor="#FFFFFF";
	     tmt_formManager('former','submit()')
}
function toggledetails(str){
	var currentstate=document.getElementById(str).className;
	if(currentstate=='RecordDisplayResultsOff'){
		document.getElementById(str).className='RecordDisplayResultsOn';
	}else{
		document.getElementById(str).className='RecordDisplayResultsOff';
	}
}
function LoginUser(){
	tmt_formManager('former','submit()')
}
function LoadUser(){
	user=getCookie('SurfaceEntryLog')
	if(user){
		document.getElementById('login').value=user;
	}
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
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 reposmenus(){
	newheight=getHeight();
	if(newheight!=currentheight){
	var curloc = document.location.href
    MM_goToURL('parent',curloc); 
	return document.MM_returnValue;
	}
}
function ReloadPage(){
	var curloc = document.location.href
    MM_goToURL('parent',curloc); 
	return document.MM_returnValue;
}
function setCookie(c_name,value,exdays){
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}
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){
	document.getElementById('LocationSearch').innerHTML='Locations';
	page="Location_DB_Details.php#";
	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;
}
function gotoadmin(){
	MM_goToURL('parent','Administration/Login.php');return document.MM_returnValue
}
var DivCreateStart;
function SearchProductName(event){
	startheight=0;
	//var container=document.getElementById('SearchConstruct');
	data='';
	$.post("ProductSearch.php",$("#SearchForm").serialize(),
	function(data) { 
	if(!data){
		return false
	}
	var Containers = document.getElementById('SearchToolContainer');
	var Appendage=document.getElementById('SearchToolContainer');
	document.getElementById('SearchToolContainer').innerHTML='';
	PostLeft=calmenuleft('SearchStr');
	PostTop=calmenutop('SearchStr');
	document.getElementById('SearchToolContainer').style.left=PostLeft+"px";
	document.getElementById('SearchToolContainer').style.top=eval(PostTop+2)+"px";
	
	var divTag = document.createElement("div");
	divTag.id = "SearchConstruct"; 
	divTag.setAttribute("left",PostLeft+"px");
	DropDownWidth=eval(190)
	divTag.style.width=DropDownWidth+'px';
	divTag.style.width='100%';
	divTag.className ="dynamicDiv"; 
	Appendage.appendChild(divTag);
	divTag.innerHTML='';
    dataRetreived=data.split("|");
	dataRetreived.pop();
	for (var i=0;i<dataRetreived.length;i++) {
		currentdata=dataRetreived[i];
		dataSplit=currentdata.split("~");
	    divTag.innerHTML+="<span onclick='PassToProductName(this.innerHTML,"+dataSplit[1]+")' style='width:100%' class='SearchParas'>"+dataSplit[0]+"</span>";
	   }
    });
}
function CloseDownSearch(){
	$('html').click(function() {  //Hide the menus if visible  
	 timer=setTimeout("CloseDownSearchBox()",500);
	}); 
}
function CloseDownSearchBox(){
	var container=document.getElementById('SearchToolContainer');
	if(container){
		document.getElementById('SearchToolContainer').innerHTML='';
		$('#SearchConstruct').css({ "visibility" : "hidden" });
		clearTimeout(timer)
	}else{
		document.getElementById('SearchToolSearchContainer').innerHTML='';
		$('#SearchConstruct').css({ "visibility" : "hidden" });
		clearTimeout(timer)
	}
}
function PassToProductName(str,Recid){
	document.getElementById('SearchStr').value=str;
	navigate('SearchProducts.php?id='+Recid);
}

