//Prep Page
function preparePage(){
MM_preloadImages('images/DefaultButtons.gif','images/AboutButton.gif','images/CompButton.gif','images/ContactButton.gif','images/HomeButton.gif','images/RegistrationButton.gif','images/GalleryButton.gif','images/HP_Map_Part.gif')
}
//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 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(){
	newwidth=getWidth();
	if(newwidth!=currentwidth){
	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 = 10;
    MM_openBrWindow(url,'','top='+top+',left='+left+',width='+w+',height='+h)
}
function launchScrollingpopup(url,w,h){
	var width=w, height=h;
    var left = (screen.width/2) - width/2;
	var top = 10;
    MM_openBrWindow(url,'','top='+top+',left='+left+',width='+w+',height='+h+',scrollbars=yes,resizable=yes')
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  popupwindow=window.open(theURL,winName,features);
}
function close_window() {
    popupwindow.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
//Contact us functions
function contactKickstart(){
	document.location.href='mailto:KickStart.Breakfast@fonterra.com';
}
function ContactUs(){  
   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)
    {
	Status= xmlHttp.responseText;
	if(Status!="Go Ahead"){
		alert(Status);
		return false;
	}else{
		CheckContactUsFields();
    }
	}
    }
	var EmailVal=document.getElementById('Email').value
	var url="CheckReplyEmail.php?Email="+EmailVal;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}
function CheckContactUsFields(){
	var requiredCount=0;
	var requiredRows=new Array('FullNameRow','EmailRow','EnquiryRow');
	var requiredFields=new Array('Name','Email','Enquiry');
	for (var i=0;i<requiredFields.length;i++) {
		var fieldValue=document.getElementById(requiredFields[i]).value
		if(!fieldValue){
			document.getElementById(requiredRows[i]).style.backgroundColor="#E66A37";
			requiredCount++;
		}else{
			document.getElementById(requiredRows[i]).style.backgroundColor="#B3E2F6";
		}
	}
	if(requiredCount>0){
		alert('The Following Field(s) are Required');
	}else{
		tmt_formAction('ContactForm','Mail.php')
		tmt_formManager('ContactForm','submit()');
	}
}
//Newsletter Subscription
function subscribetoNews(){
	var a = document.getElementById('mode').value
	if(a=="Subscribe"){
	document.getElementById('Recipient').value="noreply@csppacific.co.nz";
	tmt_formAction('former','Mail.php');
	tmt_formManager('former','submit()');
	return false;
	}
	if(a=="Update"){
	tmt_formAction('former','Subscription_Update.php');
	tmt_formManager('former','submit()');
	return false;
	}else{
	tmt_formAction('former','Newsletter_Unsubscribe.php');
	tmt_formManager('former','submit()')
	}
}
//End of Newsletter Subscription
//End of Contact Us functions
//News Registration
function unsubscribe(){
	launchpopup('Popup_Unsubscribe.php',400,210)
}
function dosubdetails(){
	var a = document.getElementById('Email').value
	findsubdetails(a,'std')
}
function updatesubscribe(){
	launchpopup('Popup_Update.php',400,210)
}
function updatesubdetails(){
	var a = document.getElementById('Email').value
	findsubdetails(a,'update')
}
//Endof News Registration
//Regional Map
function showParticipants(str) {
	if(Status=="Logged In"){
		popuppage=("Popup_Members_Participation.php?region="+str);
		winwidth=900;
		winheight=600;
	}else{
		popuppage=("Popup_Participation.php?region="+str);
		winwidth=650;
		winheight=500;
	}
	var popupPages=new Array('Registration','RegistrationB','RegistrationC','index');
	var currentpage=window.location.toString();
	var desemone=currentpage.split("/");
	var lastslash=desemone[desemone.length-1];
	var desemtwo=lastslash.split(".");
	popup=in_array(desemtwo[0], popupPages);
	if(popup==true){
			launchpopup(popuppage,winwidth,winheight);
	}else{
	url="Participation.php?region="+str
	MM_goToURL('parent',url);return document.MM_returnValue
	}
	var currentpage=""
}
function changePopupRegion(str){
	url="Popup_Members_Participation.php?region="+str
	MM_goToURL('parent',url);return document.MM_returnValue
}
function changeRegion(str){
	url="Popup_Participation.php?region="+str
	MM_goToURL('parent',url);return document.MM_returnValue
}
function changeRegionMembers(str){
	url="Members_Participation.php?region="+str
	MM_goToURL('parent',url);return document.MM_returnValue
}
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 retreiveRegionalCount(str){
	participants=regionalCount[str];
	return participants;
}
function checkLoginStatus(){  
   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)
    {
	Status= xmlHttp.responseText;
	
    }
    }
	var url="LoginStatus.php";
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);  
}
//Hide Show details in Participation
function viewDetails(tableID,spanID,masterID){
	var targetTable=document.getElementById(tableID);
	var masterRow=document.getElementById(masterID);
	var targetHref=document.getElementById(spanID);
	if(targetTable.className=="hidden"){
		masterRow.style.backgroundColor="#E66A37";
		targetTable.className="";
		targetHref.innerHTML="Hide Details";
	}else{
		masterRow.style.backgroundColor="#B3E2F6";
		targetTable.className="hidden";
		targetHref.innerHTML="View Details";
	}
}
function displayPasswordProps() {
	document.getElementById('EmailRow').className="display";
}
function RecoverPassword(){  
   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)
    {
	Status= xmlHttp.responseText;
	alert(Status);
	if(Status!="Sorry we have no record of that email address"){
		document.getElementById('EmailRow').className="hidden";
	}
    }
    }
	var Coordinator=document.getElementById('EmailAddress').value
	var url="PasswordRecoverMailer.php?email="+Coordinator;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}
function CookieVote(){  
   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)
    {
	Status= xmlHttp.responseText;
	}
    }
	var url="SetVoteCookie.php";
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);  
}
//Gallery Nav
function changeCat(str){
	if(!str){
		alert("No Category Selected!");
		return false;
	}
	MM_goToURL('parent',str);return document.MM_returnValue
}
function displayGalleryImage(imgsrc,imgwidth,imgheight){
	document.getElementById('PreviewImageContainer').width=imgwidth;
	document.getElementById('PreviewImageContainer').height=imgheight;
	document.getElementById('PreviewImageContainer').style.backgroundImage="url("+imgsrc+")";
	document.getElementById('PreviewImage').className="display";
	document.getElementById('closehidepanel').className="display";
	document.getElementById('GalleryTable').className="hidden";
}
function hideGalleryImage(){
	document.getElementById('PreviewImage').className="hidden";
	document.getElementById('GalleryTable').className="display";
	document.getElementById('closehidepanel').className="hidden";
}
//Blink
function doBlink() {
	var BlinkTags=document.getElementById("Blinker");
	if(BlinkTags.className=="hidden"){
		BlinkTags.className="display";
	}else{
		BlinkTags.className="hidden";
	} 
}
function startBlink() {
  setInterval("doBlink()",1000)
}
