/* auto created by Fireworks for metal pill buttons Januar 11, 2008 */
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;
}
/* Functions that swaps down images. */
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

/* Functions that handle preload. */
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];}}
}

  /*CHECK AND HANDLE FOR DEFAULT TEXT IN PASSWORD AND EMAIL-->*/
      
    function manageLoginInputDefaultText(box) {
      //var objModalLoginWindow = document.getElementById('modalLoginWindow');    
      //  alert(objModalLoginWindow);
              if (box == 'txtEmail') {
             
                  if (document.getElementById('txtPassword').value != '') { 
                      document.getElementById('txtPassword').className = 'loginBlankBox';  
                      
                  } else {
                      document.getElementById('txtPassword').className = 'loginBlankBox';
                      
                  }
             if (document.getElementById('txtEmail').value == 'Email address') { 
                      document.getElementById('txtPassword').className = 'loginPassword';
                      document.getElementById('txtEmail').value = '';   
                     return true;
                  }
             
              if (document.getElementById('txtEmail').value == '') {        
                      document.getElementById('txtEmail').value = 'Email address'; 
                  }
             }
             
               if (document.getElementById('txtPassword').value == '') { 
                 
                     document.getElementById('txtPassword').className = 'loginPassword';  
                    
                     }   
                 
              
            
                
                /*user clicks the password box*/
                if (box == 'txtPassword') {  
               
                  if (document.getElementById('txtPassword').value == '') { 
                 
                     document.getElementById('txtPassword').className = 'loginBlankBox';  
                    
                     }   
                 
                   if (document.getElementById('txtPassword').value != '') {   
                          document.getElementById('txtPassword').className = 'loginBlankBox';  
                      }  
                      if (document.getElementById('txtEmail').value == '') {   
                          document.getElementById('txtEmail').value = 'Email address'; 
                      }  else {
                                            
                      }  
                    }
                   }
                 
/*end login form handeling*/  

/* Handles the quequing and pausing in our mailing forms */	
function doMailingChoice(stChoice, msg) {
    
    if (stChoice == 'queue') {
        if (!confirm(msg)) {
            return false;
        }
    }
    
    var elemAction = document.getElementById('mailaction');
    elemAction.value = stChoice;

    try {
        document.send.onsubmit();
        }
    catch(e){}
    
    var sendForm = $('send');

    // Should hide the buttons
    
    // might want to let the user know we are processing this
    sendForm.set('send', {async : false, 
                            onSuccess: function(response, xml){             
                                alert(messageStringFromXMLResponse(xml));
                                window.location.replace(window.location);
                               },         
                               onFailure: function(response){      
                                   alert(errorStringFromXMLResponse(response));
                               } });

    sendForm.send();
    
    return false;
    
}


function errorStringFromXMLResponse(response)
{
    var stRet = '';
    if (response.responseXML != null) {
        var msgNodes = response.responseXML.getElementsByTagName('error');
        var iMax = msgNodes.length;
        if (iMax > 0) {
               msg = '';
               for (var i = 0 ; i < iMax ; i++) {
                   if (msg != '') {
                       msg += '<br />';
                }
                   stRet += msgNodes[i].firstChild.nodeValue;
            }
        }
    }

    return stRet;
    
}

function messageStringFromXMLResponse(response)
{
    var stRet = '';
    if (response != null) {
        var msgNodes = response.getElementsByTagName('message');
        var iMax = msgNodes.length;
        if (iMax > 0) {
               msg = '';
               for (var i = 0 ; i < iMax ; i++) {
                   if (msg != '') {
                       msg += '<br />';
                }
                   stRet += msgNodes[i].firstChild.nodeValue;
            }
        }
    }

    return stRet;
    
}

//form submission
// param1 the form you want to submit
// param2 the url to the file on the server (can contain querystring) all form values will get added to qs as well
// param3 the div to hide parameter is what will be hidden when the http result comes back
// param4 divToShow is the name of the div that will show the http results.
// param5 (if present) is the name of the mocha window to close if a 'Close' is returned

var xmlReq = null;; 
function ajaxSubmit(form, file, divToHide, divToShow, mwid) 
{      

	//tag on elements from the form onto the querystring
	var formElementsQS = $(form).toQueryString();
	//alert(formElementsQS);
	//attach any form values to the querystring
	file = file + '&' + formElementsQS;
	xmlReq = getXML(file);
    xmlReq.onreadystatechange=function()
    {
	    if(xmlReq.readyState==4)
	      {
      		  //hide the form
      		  var mainDiv = document.getElementById(divToHide);
      		 if (mainDiv) {
      	 		mainDiv.style.display = "none";
			 }  
	         //alert('all good');
	         // alert(xmlReq.responseText);
	          
	          var HTTPResponseDiv = document.getElementById(divToShow);
	          if (HTTPResponseDiv) {
	          		var st = xmlReq.responseText;
	          		if (mwid && st == 'Close') {
	          			closeMochaWindowRefreshParent(mwid);
					} else {
          				HTTPResponseDiv.innerHTML = xmlReq.responseText;
					}
			  }
	         // alert(joinSuccessDiv.innerHTML);
			  }
	    }
} 

//
// Submits the URL and replaces the results in divToShow. 
// hides divToHide when it successfully returns
function urlGetReplace(url, divToHide, divToShow) 
{      

    xmlReq = getXML(url);
    xmlReq.onreadystatechange=function()
    {
        if(xmlReq.readyState==4)
          {
                //hide the form
                var mainDiv = document.getElementById(divToHide);
               if (mainDiv) {
                   mainDiv.style.display = "none";
             }  
             //alert('all good');
             // alert(xmlReq.responseText);
              
              var HTTPResponseDiv = document.getElementById(divToShow);
              if (HTTPResponseDiv) {
                var htmlNode = xmlReq.responseXML.getElementsByTagName('message');
                var stHTMLText;
                if (htmlNode[0].textContent != undefined) {
                    stHTMLText = htmlNode[0].textContent;
                } else {
                    stHTMLText = htmlNode[0].text;
                }
                  var st = xmlReq.responseText;
                  HTTPResponseDiv.innerHTML = stHTMLText;
              }
             // alert(joinSuccessDiv.innerHTML);
              }
        }
} 

//returns an xmlHttpRequest object (AjAX)
function getXML(file) 

{ 
	var xmlHttp = null 
	if (typeof window.ActiveXObject != 'undefined' ) 
   { 
   		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		//doc.onreadystatechange = displayState; 
   } 
   else 

   { 
   		xmlHttp = new XMLHttpRequest(); 
		
   } 
   	xmlHttp.open( "GET", file, true ); 
   	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
   	xmlHttp.send(null); 
   	return xmlHttp; 

}

function refreshParent() {
	window.location.reload(true);
}
function closeMochaWindow(windowID) {
    //default id mocha gives to div
   document.mochaDesktop.closeWindow($(windowID));
}

function closeMochaWindowRefreshParent(windowID) {
     document.mochaDesktop.closeWindow($(windowID));
     window.location.reload(true);
}

function loadModal() {
	alert('hello');	
	}

          
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'width=360,height=375,left=240,top=180,resizable=1,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0');");
}

function selectCheckBox(obj) {
	var elemParent = obj.parentNode;
	
	var inputList = elemParent.getElementsByTagName('INPUT');
	
	if (inputList != null && inputList[0] != null) {
		if (inputList[0].checked) {
			inputList[0].checked = false;
		} else {
			inputList[0].checked = true;
		}
	}

}

// Function to initialize the form submit buttons
// Written for mootools 1.2.4
function initFormSubmit(stNameForm, stNameSubmitAjax, stNameFormDiv, stNameSubmitButton, stNamePostBack)
{
//return;

	formSubmitEl = document.getElement('form#' + stNameForm + " #" + stNameSubmitAjax);
	if(formSubmitEl){
	  formSubmitEl.addEvent('click', function(){
	  	submitAjaxItem(stNameForm, stNameFormDiv, stNamePostBack);
		});
	}
  nonAjaxSubmit = $(stNameSubmitButton);
  if (nonAjaxSubmit) {
	nonAjaxSubmit.style.display = 'none';
  }
  
  objAjaxSubmit = $(stNameSubmitAjax);
  if (objAjaxSubmit) {
  	objAjaxSubmit.style.display='inline';
  }

}

// This is designed for mootools 1.2.4
function submitAjaxItem(stNameForm, stNameReplace, stNamePostBack) 
{
	// Clear the postback value
	var postback = $(stNamePostBack);
	if (postback) {
		postback.value=0;
	}
	var url = window.location.pathname;
	var form = $(stNameForm);
	// TO DO Perhaps we need to have something show up while we're processing
	form.set('send', {
	       onSuccess: function(responsetxt, responseXML){             
				// Replace text with respose
				var htmlNode = responseXML.getElementsByTagName('message');
                var stHTMLText;
                if (htmlNode[0].textContent != undefined) {
                    stHTMLText = htmlNode[0].textContent;
                } else {
                    stHTMLText = htmlNode[0].text;
                }
				$(stNameReplace).innerHTML = stHTMLText;
       			},         
	       onFailure: function(response){     
	       		// TO DO - Display an error - this is either from someone spoofing or a system problem.
	       } 
	    });
	form.send();
	
	return false;
}

// This is designed for mootools 1.2.4
/*
 * Provides for a rotation between divs
 *
 * stDivBase - base name of the divs that hold the text being rotated
 * idStart - Starting id
 * idMax - Max id (assumption is we start at 0)
 * msDelay - millisecond delay between items
 */
function startRotation(stDivBase, idStart, idMax, msDelay)
{
    setTimeout('displayRotatedItem("' + stDivBase + '", ' + idStart + ', ' + idMax + ', ' + msDelay + ')', msDelay );
}

function displayRotatedItem(stDivBase, idStart, idMax, msDelay)
{
    var stItem = stDivBase + idStart;
    
    var dispItem = $(stItem);
    
    if (dispItem) {
        dispItem.style.display = 'none';
    }
    
    idStart++;
    if (idStart >= idMax) {
        idStart = 0;
    }   

    var stNewItem = stDivBase + idStart;
    
    var dispNewItem = $(stNewItem);
    if (dispNewItem) {
        dispNewItem.style.display='block';
    }
 
    setTimeout('displayRotatedItem("' + stDivBase + '", ' + idStart + ', ' + idMax + ', ' + msDelay + ')', msDelay);
}

function SWFPlay(stMovieName, objHide) 
{
    var movieObj = getFlashMovieObject(stMovieName);
    
    if (movieObj != null) {
        movieObj.Play();
    }

    	if (objHide != null) {
		objHide.style.display = 'none';
	}
    
}


/* From http://www.permadi.com/tutorial/flashGetObject/ */
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }     
}    
 
// Initial code from http://www.xfunda.com/index.php?option=com_content&view=article&id=55&catid=40:javascript&Itemid=75
var g_gt_type = -1;
var g_itv_gt = 0;

function goto_top_timer() 
{
    var y = g_gt_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
    var moveby = 15; // This controls how quickly we scroll

    y -= Math.ceil(y * moveby / 100);
    if (y < 0)
        y = 0;

    if (g_gt_type == 1)
        document.documentElement.scrollTop = y;
    else
        document.body.scrollTop = y;

    if (y == 0) {
        clearInterval(g_itv_gt);
        g_itv_gt = 0;
    }
}

function goto_top() 
{
    if (g_itv_gt == 0) {
        if (document.documentElement && document.documentElement.scrollTop)
            g_gt_type = 1;
        else if (document.body && document.body.scrollTop)
            g_gt_type = 2;
        else
            g_gt_type = 0;

        if (g_gt_type > 0) {
            g_itv_gt = setInterval('goto_top_timer()', 25);
        }
    }
}

