
var loaded=false;

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++)
     {
         d.MM_p[i]=new Image(); 
         d.MM_p[i].src=a[i];
     }
     
     loaded = true;
     changeTabs();
  } 
}

function MM_swapImgRestore() { //v3.0
  var a=MM_swapImgRestore.arguments;
  if (loaded && document.MM_tmp!=null)
  {
     a[0].src = document.MM_tmp.src;
  }
}

function MM_findObj(n) { 
  var i,img;
   
  for(i=0;i<document.MM_p.length;i++)
  {
    img = document.MM_p[i];
    if (img.src.search(n) > -1)
    {
      return img;
    }    
  }
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; 
  
  if (loaded)
  {
  
	  document.MM_tmp = new Image();      
	
	  if (MM_findObj(a[0]) != null)  
	  {
		 document.MM_tmp.src = a[1].src;
		 a[1].src = MM_findObj(a[0]).src;
	  }
  }
}

function preloadWrapper()
{
  MM_preloadImages('http://www.pmi.org/SiteCollectionImages/my-pmi_over.gif','http://www.pmi.org/SiteCollectionImages/membership_over.gif','http://www.pmi.org/SiteCollectionImages/about-us_over.gif','http://www.pmi.org/SiteCollectionImages/career-dev_over.gif','http://www.pmi.org/SiteCollectionImages/get-involved_over.gif','http://www.pmi.org/SiteCollectionImages/resources_over.gif','http://www.pmi.org/SiteCollectionImages/bus-solutions_over.gif','http://www.pmi.org/SiteCollectionImages/marketplace_over.gif');
}
//CLS: changeTabs() changes the sub-site tabs so that the current sub-site the user is reading is
//changed to a brown color.  This applies for all but the MyPMI tab [which directs to a login/personalization page], when MyPMI
//is clicked we detect this through a querystring mod so that way the MyPMI tab "sticks" when it's clicked.
function changeTabs()
{
  var currentURL;  //The current site URL
  currentURL = location.href;	
  
  currentArray = currentURL.split('/');
  
  if(currentArray.length > 3)
  {
	 currentURL = currentArray[3];
  } else
  {
	  return;
  }
  
 
  //MyPMI
	  if (currentURL.search('MyPMI') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/my-pmi_off.gif', 'http://www.pmi.org/SiteCollectionImages/my-pmi_on.gif');
  }
  
  //Membership
	  if (currentURL.search('Membership') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/membership_off.gif', 'http://www.pmi.org/SiteCollectionImages/membership_on.gif');
  }

  //AboutUs
  if (currentURL.search('AboutUs') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/about-us_off.gif', 'http://www.pmi.org/SiteCollectionImages/about-us_on.gif');
  }
  
  //CareerDevelopment
  if (currentURL.search('CareerDevelopment') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/career-dev_off.gif', 'http://www.pmi.org/SiteCollectionImages/career-dev_on.gif');    
  }
  
  //GetInvolved
  if (currentURL.search('GetInvolved') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/get-involved_off.gif', 'http://www.pmi.org/SiteCollectionImages/get-involved_on.gif');
  }  
  
  //Resources
  if (currentURL.search('Resources') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/resources_off.gif', 'http://www.pmi.org/SiteCollectionImages/resources_on.gif');
  }
  
  //BusinessSolutions
  if (currentURL.search('BusinessSolutions') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/bus-solutions_off.gif', 'http://www.pmi.org/SiteCollectionImages/bus-solutions_on.gif');
  }
  
  //Marketplace
  if (currentURL.search('Marketplace') > -1)
  {
    replaceOriginalImage('http://www.pmi.org/SiteCollectionImages/marketplace_off.gif', 'http://www.pmi.org/SiteCollectionImages/marketplace_on.gif');
  }
}
//CLS: This is a quick way to swap out an undesired image with a new one.  Any images that use
//the original source href will be changed to the new source href value
function replaceOriginalImage(oldSrc, newSrc)
{
  for (var i=0;i<document.images.length;i++)
  {
    if (document.images[i].src.search(oldSrc) > -1)
    {
      document.images[i].src = newSrc;
    }
  }
}

//CLS: Sharepoint loves to put the entire page on a form, but this interferes with the Sharepoint Delegate control
//where the small search box is pointing to a seperate Javascript method to send its parameters to the search
//engine.   Here, we will locate the code-generated Javascript and invoke it.
function OnPressedEnterKeyInSearch(obj, keyCode)
{
  //One of the links on this page is titled "Go Search", and this is the link to the javascript code for
  //searches.
  var goSearchLink;
  var i;
  
  if (keyCode == 13)
  {
	  for (i=0; i<document.links.length; i++)
	  {
	    if (document.links[i].title == "Go Search")
	    {
	      goSearchLink = document.links[i].href;
	      break;
	    }
	  }	 
	  
      eval(goSearchLink);	
  }
}

function PmiFormOnSubmit()
{
	return _spFormOnSubmitWrapper();
}
function PmiFormOnSubmitOverHttps()
{
	var submitFlag = document.getElementById('PmiSubmitFlag');
	if (submitFlag)
	{
		if (submitFlag.value == 'LOGIN')
		{
			if (location.protocol == 'http:')
				theForm.action = location.href.replace(location.protocol, 'https:');
		}
	}
	return _spFormOnSubmitWrapper();
}

function PmiFormOnKeyPress(event)
{
	if (event && event.keyCode && event.keyCode == 13 && event.srcElement.id)
	{
		var submitFlag = document.getElementById('PmiSubmitFlag');
		if (submitFlag == null)
			return;
		
		if (event.srcElement.id.indexOf('USERIDEDIT') >= 0 || event.srcElement.id.indexOf('PASSWORDEDIT') >= 0)
		{
			submitFlag.value='LOGIN';
			if (theForm.onsubmit())
			    theForm.submit();
		}
		else
		{
			submitFlag.value='0';
		}
	}
}

function SignInOnClick()
{
    var submitFlag = document.getElementById('PmiSubmitFlag'); 
    if (submitFlag == null) 
        return;
    
    submitFlag.value='LOGIN';
    if (theForm.onsubmit()) 
        theForm.submit();
}

function patchSearch()
{

	var ddlSearchDiv = document.getElementById('PmiBasicSearchBox');

	if (ddlSearchDiv == null)
		return;

	var children = ddlSearchDiv.getElementsByTagName('select');

	if (children == null)
		return;

	var ddlSearch = children[0];

	if (ddlSearch == null || ddlSearch.options == null || ddlSearch.length == 0)
		return;

	if (ddlSearch.options[0].text.substring(0,10).toLowerCase() == "this site:")
		ddlSearch.remove(0);
}


