var baseURL = 'http://'+location.hostname;
var secureBaseURL = 'https://'+location.hostname;
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In MSIE, the true version is after "MSIE" in userAgent
if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
 browserName = "Microsoft Internet Explorer";
 fullVersion = nAgt.substring(verOffset+5);
}
// In Opera, the true version is after "Opera" 
else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
 browserName = "Opera";
 fullVersion = nAgt.substring(verOffset+6);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
 browserName = "Chrome";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
 browserName = "Safari";
 fullVersion = nAgt.substring(verOffset+7);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
 browserName = "Firefox";
 fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) 
{
 browserName = nAgt.substring(nameOffset,verOffset);
 fullVersion = nAgt.substring(verOffset+1);
 if (browserName.toLowerCase()==browserName.toUpperCase()) {
  browserName = navigator.appName;
 }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);
 
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
 fullVersion  = ''+parseFloat(navigator.appVersion); 
 majorVersion = parseInt(navigator.appVersion,10);
}
 
// Browser Name: browserName
// Full Version: fullVersion
// Major Version: majorVersion

var currentSelectedButton = null;
var popupAction = 0; //0=hide 1=fade in 2=leave shown
var popupId = null; //specifies for which button the popup window is showing

// Function menuBar adds a short delay from the time a user mouses over a button to when the action begins. 
// This allows the user to run the mouse across the menu (going to the E-Max button, for example) without the
// menu popup window being triggered, which would annoy the user.
function menuBar(action,id) {
	if(action == 'over'){
		// We don't want to delay the action if the user moves from an already visible popup window back to the button
		if(popupId != id) 
			window['popupTimer' + id] = setTimeout('menuBarAction("over","'+id+'")',250);
		else
		  menuBarAction('over',id);
	}else if(action == 'out'){
		menuBarAction('out',id);
		if(typeof(window['popupTimer' + id]) != 'undefined')
		  clearTimeout(window['popupTimer' + id]);
	}
}

// Function menuBarAction performs the image swaps, and popup window fadeins when a user mouses over a menu item. 
function menuBarAction(action,id)
 { 
	 if(action == "over"){
		 var pw = [];
         pw['0_width']  = '435px';
         pw['0_height'] = '255px';
         pw['1_width']  = '520px';
         pw['1_height'] = '330px';
         pw['2_width']  = '520px';
         pw['2_height'] = '450px';
         pw['3_width']  = '435px';
         pw['3_height'] = '255px';
         pw['4_width']  = '435px';
         pw['4_height'] = '310px';
         pw['5_width']  = '435px';
         pw['5_height'] = '245px';
         pw['6_width']  = '435px';
         pw['6_height'] = '245px';
         pw['7_width']  = '435px';
         pw['7_height'] = '245px';
         pw['8_width']  = '435px';
         pw['8_height'] = '245px';

         
         
         currentSelectedButton = id;
		 
		 // Swap the standard button with the mouseover button.
	     MM_swapImage('button_menu_' + id,'','/assets/images/menubar/button' + id + '-over.png',1);				
		 

         document.getElementById('popupWindow').style.width = pw[id+'_width'];
         document.getElementById('popupWindow').style.height = pw[id+'_height'];
          	
		 // Make sure all menu windows are hidden, except for the one we want to show
		 for(i=0; i<8; i++)
	    {
		   if(id == i)
		     document.getElementById('popup_content_' + i).style.display = 'block';
		   else
		     document.getElementById('popup_content_' + i).style.display = 'none';
		  }
		 
		 // If the popup window is already visible for a button (If the user moused over a button, then its window, then back up to the button)
		 // Set the popup action to simply keep the window visible. If it's not already visible, fade it in.
		 if(popupId == id)
		   popupAction = 2;
		 else
           popupAction = 1;
			 
	 }else if (action == "out"){	// Put everything back to normal
	   MM_swapImgRestore();
		 popupAction = 0;
	 }else if(action == "popup_window_over"){ //When the mouse goes from the button to the window
		 MM_swapImage('button_menu_' + currentSelectedButton,'','/assets/images/menubar/button' + currentSelectedButton + '-over.png',1);
         popupAction = 2; 
	 }else if(action == "popup_window_out"){ //Mouse leaves the popup window
         MM_swapImgRestore();
         popupAction = 0;
	 }

	 // Popup window actions. Performs the fadein and hiding of the popup. 
	 // For MSIE 6 and earlier, the fade-in does not work well, so let's just make it an instant popup 
	 if(popupAction == 0){ //Hide window
	   document.getElementById('popupWindow').style.display = 'none';
	 }else if(popupAction == 1){ // FADE IN
	   popupId = id;
		 //Move the popup window left and right. The distance depends on which button is moused over.
		 document.getElementById('popupWindow').style.left = ((482/7)*id)+'px';
		 if(browserName == "Microsoft Internet Explorer"){ //MSIE 6 and under don't behave well when alpha fading. Use an instant popup instead.
			 document.getElementById('popupWindow').style.display = 'block';
		 }else{
			 changeOpac(0, 'popupWindow');
			 document.getElementById('popupWindow').style.display = 'block';
			 menuBoxFadeIn();
             if(browserName == "Microsoft Internet Explorer")
                 document.getElementById('popupWindow').style.removeAttribute('filter');	
	   }
	 }else if(popupAction == 2){ //Leave visible
	   document.getElementById('popupWindow').style.display = 'block';
	 }
	 
	 
 }// end function

function loanTabs(group,state){
	 var loanHTML = '<a href="javascript:menuBarAction(\'business_tab\',2)" onmouseover="menuBarAction(\'business_tab\',2)" id="tab_business_loans"><img src="/assets/images/transparent_spacer.gif" alt="Business Loans" width="60" height="15" style="position:relative;top:-6px;left:10px;"/> </a><a href="javascript:menuBarAction(\'consumer_tab\',2)" onmouseover="menuBarAction(\'consumer_tab\',2)" id="tab_consumer_loans"><img src="/assets/images/transparent_spacer.gif" alt="Consumer Loans" width="115" height="15" style="position:relative;top:-6px;left:32px;"/> </a>';
   var businessHTML = '<a href="javascript:menuBarAction(\'accounts_tab\',2)" onmouseover="menuBarAction(\'accounts_tab\',2)" id="tab_business_accounts"><img src="/assets/images/transparent_spacer.gif" alt="Business Accounts" width="60" height="15" style="position:relative;top:-6px;left:10px;"/> </a><a href="javascript:menuBarAction(\'services_tab\',2)" onmouseover="menuBarAction(\'services_tab\',2)" id="tab_business_services"><img src="/assets/images/transparent_spacer.gif" alt="Business Services" width="60" height="15" style="position:relative;top:-6px;left:32px;"/> </a>';  
	 
	 if(state == 'visible'){
		 
		 if(group == 'loans_visa'){
			 loanTabs('business','hidden');
	     document.getElementById('loan_tabs_hider').innerHTML = loanHTML;
		 }else if(group == 'business'){
			 loanTabs('loans_visa','hidden');
		   document.getElementById('business_tabs_hider').innerHTML = businessHTML;
		 }
	 }else{
	   document.getElementById('loan_tabs_hider').innerHTML = ' ';
		 document.getElementById('business_tabs_hider').innerHTML = ' ';
	 }
}
	
function currentRatesTabSwap(tab){
	 if(tab == "loan"){
		 document.getElementById('current_rates_window').style.backgroundImage = 'url(/assets/images/current_rates_window_loan_tab.png)';
		 populateRates('currentRatesData','tabl_loan',true);
	 }else if(tab == "deposit"){
		 document.getElementById('current_rates_window').style.backgroundImage = 'url(/assets/images/current_rates_window_deposit_tab.png)';
		 populateRates('currentRatesData','tabl_deposit',true);
	 }
	
}


function rateTab(rateGroup) {
	if(rateGroup == 'consumer'){
		document.getElementById('left_panel').style.backgroundImage = 'url(/assets/images/rates_tab1.png)';
		document.getElementById('other_menu').style.display = 'none';
		document.getElementById('realestate_menu').style.display = 'none';
		changeOpac(0,'consumer_menu');
		document.getElementById('consumer_menu').style.display = 'block';
		opacity('consumer_menu',0,100,500);
		document.getElementById('consumer_menu').style.background = '#FFFFFF';
		populateRates('rates_data_container','tabl_autos',true);
	}else if(rateGroup == 'realestate'){
		document.getElementById('left_panel').style.backgroundImage = 'url(/assets/images/rates_tab2.png)';
		document.getElementById('other_menu').style.display = 'none';
		document.getElementById('consumer_menu').style.display = 'none';
		changeOpac(0,'realestate_menu');
		document.getElementById('realestate_menu').style.display = 'block';
		opacity('realestate_menu',0,100,500);
		document.getElementById('realestate_menu').style.background = '#FFFFFF';
		populateRates('rates_data_container','tabl_first_mortgages',true);
	}else if(rateGroup == 'other'){
		document.getElementById('left_panel').style.backgroundImage = 'url(/assets/images/rates_tab3.png)';
		document.getElementById('consumer_menu').style.display = 'none';
		document.getElementById('realestate_menu').style.display = 'none';
		changeOpac(0,'other_menu');
		document.getElementById('other_menu').style.display = 'block';
		opacity('other_menu',0,100,500);
		document.getElementById('other_menu').style.background = '#FFFFFF';
		populateRates('rates_data_container','tabl_savings_and_checking',true);
	}
}


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_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 hoverBG(action, id, foreground, background) {
  if(browserName == 'Microsoft Internet Explorer'){
   for(var i=0; i < document.getElementById(id).childNodes.length; i++)
     document.getElementById(id).childNodes[i].style.color = foreground;
  
   document.getElementById(id).style.backgroundColor = background; 

	}else{
   for(var i=1; i < document.getElementById(id).childNodes.length; i=i+2)
     document.getElementById(id).childNodes[i].style.color = foreground;

	 document.getElementById(id).style.backgroundColor = background;
  }
	if(action == 'over'){
	 document.getElementById(id).style.cursor = 'pointer';
	 //document.getElementById(id).style.fontWeight = 'bold';
	} else {
   document.getElementById(id).style.cursor = 'default';
	 //document.getElementById(id).style.fontWeight = 'normal';
	}
}

function pause(milliseconds) {
	var dt = new Date();
	while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
  
	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++){
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function menuBoxFadeIn() {
   
	 for(i=0; i <= 10; i++) {
		 if(typeof(window['timer' + i]) != 'undefined') 
		  clearTimeout(window['timer' + i]);
		 
		 window['timer' + i] = setTimeout("changeOpac(" + i*10 + ",'popupWindow')",i*25);
         document.getElementById('popupWindow').style.backgroundColor = '#ffffff';
	 }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec);
}

function isDefined(element)
{
  return (!(!(document.getElementById(element))));
}

function calcShow(calcID) //used on Financial Calculators Page
{
	document.getElementById('list_div_'+currentCalc).style.display = 'none';
	
  if(browserName == 'Microsoft Internet Explorer'){
    document.getElementById('list_div_'+calcID).style.display = 'block';
  }else{
	  changeOpac(0,'list_div_'+calcID);
	  document.getElementById('list_div_'+calcID).style.display = 'block';
	  for( i=0; i <= 10; i++ )
	    setTimeout("changeOpac("+ i*10 +",'list_div_"+calcID+"')",i*30);
	}
	currentCalc = calcID;	
}

function rotateMarketingSlides(slideIndex)
{
  if(window['marketingBannerTimer'])
    clearTimeout(window['marketingBannerTimer']); 
  
  slideContainer = document.getElementById('marketing_banner');
  
  changeOpac(0, "marketing_banner")
  slideContainer.src = '/assets/images/marketing_ads/slides/' + slides[slideIndex][2];
  
  slideContainer.style.cursor = 'pointer'; 
  slideContainer.onclick = function(){window.location.href = slides[slideIndex][4]};   
  
  
  for(i=0;i<(slides.length);i++)
    document.getElementById('marketing_indicator_' + i).src = '/assets/images/marketing_slide_indicator_off.png'; 
      
  document.getElementById('marketing_indicator_' + slideIndex).src = '/assets/images/marketing_slide_indicator_on.png';
  opacity("marketing_banner", 0, 100, 750); 
  
  
  if(slideIndex == (slides.length - 1)){
    var nextSlideIndex = 0;    
  }else{
    var nextSlideIndex = (slideIndex + 1);
  }
  
  window['marketingBannerTimer'] = setTimeout("rotateMarketingSlides(" + nextSlideIndex + ")",(slides[slideIndex][3] * 1000));
  
}




//  ######################
//  ##  AJAX functions  ##
//  ######################
function ajaxPopulate(htmlToFetch,DOMelement,fadein,params,secure) {
    var self = this;
		var xmlHttpReq = false;
    if(secure)
	  strURL = secureBaseURL+'/ajax/'+htmlToFetch;
    else
      strURL = baseURL+'/ajax/'+htmlToFetch;
          
		self.DOMelement = DOMelement;
		if(params == null)
			self.params = 'DOMelement='+DOMelement;
		else
			self.params = 'DOMelement='+DOMelement+'&'+params;
			

    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
    self.xmlHttpReq.setRequestHeader('Content-Length', self.params.length);

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
					if(fadein){
						changeOpac(0, self.DOMelement);
						document.getElementById(self.DOMelement).innerHTML = self.xmlHttpReq.responseText;
						opacity(self.DOMelement, 0, 100, 500);
					}else{
						document.getElementById(self.DOMelement).innerHTML = self.xmlHttpReq.responseText;
					}
        }
    }
    self.xmlHttpReq.send(self.params);
}

function submitAjaxForm(DOMelement,formID)
{
	var params = '';
	var theForm = document.forms[formID];
	for(var i=0; i < theForm.elements.length; i++)
	  {
			if(theForm.elements[i].type == 'checkbox'){
				if(theForm.elements[i].checked)
					params += '&'+theForm.elements[i].name+'=true';
				else
					params += '&'+theForm.elements[i].name+'=false';
			}else if(theForm.elements[i].type == 'radio'){
				if(theForm.elements[i].checked)
					params += '&'+theForm.elements[i].name+'='+encodeURIComponent(theForm.elements[i].value);
			}else{
			  params += '&'+theForm.elements[i].name+'='+encodeURIComponent(theForm.elements[i].value);
			}
		}
	ajaxPopulate('form',DOMelement,false,params,true);
}

function populateRates(divId,rateType,fadeIn)
{
  if(typeof(window['rateFetch']) != 'undefined') //Kills any timed rate requests, which will be encountered if someone clicks back and forth on the loan/rates tabs.
		  clearTimeout(window['rateFetch']);
			
	if(typeof(window['rateFetchRefresh']) != 'undefined') //Kill the 5 minute refresh timer 
		  clearTimeout(window['rateFetchRefresh']);		
	
	if(fadeIn){
		document.getElementById(divId).innerHTML = '<span style="color:#666666; font-size:14px;">Loading Rates...</span>'; 
		window['rateFetch'] = setTimeout('ajaxPopulate(\''+rateType+'\',\''+divId+'\','+fadeIn+')',500);
	}else{
		ajaxPopulate(rateType,divId,false);
	}
	
	if(isDefined('printer_link'))
		document.getElementById('printer_link').href = baseURL + '/printrates/'+rateType;
	
  ratePageTitle(rateType);
  	
	window['rateFetchRefresh'] = setTimeout('populateRates(\''+divId+'\',\''+rateType+'\',false)',300000); //5 minute rate refresh timer to ensure current no outdated rates.
}

function ratePageTitle(rateType){
  switch(rateType)
   {
      case "realestate":
            document.getElementById('title').innerHTML = 'Real Estate Rates';
            break; 
      case "tabl_other":
            document.getElementById('title').innerHTML = 'Current Rates';
            break;
      case "consumer":
            document.getElementById('title').innerHTML = 'Consumer Loan Rates';
            break;      
      case "tabl_autos":
            document.getElementById('title').innerHTML = 'Auto Loan Rates';
            break;
      case "tabl_personal":
            document.getElementById('title').innerHTML = 'Personal Loan Rates';
            break;
      case "tabl_VISA":
            document.getElementById('title').innerHTML = 'VISA Rates';
            break;
      case "tabl_VISA_student":
            document.getElementById('title').innerHTML = 'Student VISA Rates';
            break;
      case "tabl_VISA_business":
            document.getElementById('title').innerHTML = 'Business VISA Rates';
            break;            
      case "tabl_secured":
            document.getElementById('title').innerHTML = 'Secured Loan Rates';
            break;
      case "tabl_timeline":
            document.getElementById('title').innerHTML = 'Timeline Rates';
            break;
      case "tabl_first_mortgages":
            document.getElementById('title').innerHTML = 'First Mortgage Loan Rates';
            break;
      case "tabl_manufactured_homes":
            document.getElementById('title').innerHTML = 'Manufactured Home Loan Rates';
            break;
      case "tabl_home_equity":
            document.getElementById('title').innerHTML = 'Home Equity Loan Rates';
            break;
      case "tabl_heloc":
            document.getElementById('title').innerHTML = 'HELOC Rates';
            break;
      case "tabl_land_and_lot":
            document.getElementById('title').innerHTML = 'Land and Lot Loan Rates';
            break;
      case "tabl_savings_and_checking":
            document.getElementById('title').innerHTML = 'Savings and Checking Interest Rates';
            break;
      case "tabl_certificates":
            document.getElementById('title').innerHTML = 'Certificate Interest Rates';
            break;        
      case "tabl_service_rates":
            document.getElementById('title').innerHTML = 'Service Fees';
            break;        
      case "table_fx":
            document.getElementById('title').innerHTML = 'Foreign Currency Rates';
            break;        
      default:      
            document.getElementById('title').innerHTML = 'Rates';
   }
  
}


function showSeminarRSVP(id,showHide)
{
	if(showHide == 'show')	{
		document.getElementById('ajax_content_'+id).innerHTML = 'Loading Form...';
		document.getElementById('seminar_'+id).style.display = 'none';
		document.getElementById('form_seminar_'+id).style.display = 'block';
		ajaxPopulate('form',"ajax_content_"+id,true,'form_name=RSVP_seminar&seminar_id='+id,true);
	}else{
		document.getElementById('form_seminar_'+id).style.display = 'none';
		document.getElementById('seminar_'+id).style.display = 'block';
	}
}

function showForm(formName,DOMElement,extraAttribs)
{  
  document.getElementById(DOMElement).innerHTML = 'Loading Form...';
  ajaxPopulate('form',DOMElement,false,'form_name='+formName+'&'+extraAttribs,true); 
}

function scrollToTop()
{  
    var startPos = document.documentElement.scrollTop;
    var newPos = startPos;
    var timer = 0;
    var incCounter = 0;
    
    for(i=25;i>=0;i--) 
    {  
      newPos = i*(startPos/25);
      timer = timer + incCounter; 
      setTimeout("scroll(0,"+newPos+")",timer);
      incCounter++;
    }
}

function showScamAlert(alertID,DOMElement)
{
  document.getElementById(DOMElement).style.display = 'block';
  document.getElementById(DOMElement).innerHTML = 'Loading Form...';
  ajaxPopulate('fraud',DOMElement,true,'alertID='+alertID);
}

function calcChars(textareaID)
 {
   textarea = document.getElementById(textareaID);
   document.getElementById('charsRemaining').innerHTML = (499 - textarea.value.length);
  
 }
function swapRepoImage(imageId)
 {
   imgObject = document.getElementById(imageId); 
   currentImageSize = imgObject.src.substring(imgObject.src.lastIndexOf("_")+1,imgObject.src.lastIndexOf("."));
   currentRepoId = imgObject.src.substring(imgObject.src.lastIndexOf("/")+1,imgObject.src.lastIndexOf("_"));

   if(currentImageSize == 'small'){
      imgObject.src='/assets/images/repos/'+currentRepoId+'_large.jpg';
      imgObject.style.width = '480px';
      imgObject.style.height = '200px';
   }else{
      imgObject.src='/assets/images/repos/'+currentRepoId+'_small.jpg';
      imgObject.style.width = '240px';
      imgObject.style.height = '100px'; 
   }
   
 } 
 
function showHideElement(element) {
  var ddDisplayState = document.getElementById('hidden_'+element).style.display;
  if(ddDisplayState == 'none' || ddDisplayState == ''){
    document.getElementById('hidden_'+element).style.display = 'block';
    document.getElementById(element).src = "/assets/images/minus.png";
  }else{
    document.getElementById('hidden_'+element).style.display = 'none';
    document.getElementById(element).src = "/assets/images/plus.png";
  }
}

function textBoxStyle() { 
  var inputs = document.getElementsByTagName('INPUT'); 
  for (var i=0;i<inputs.length;i++) { 
   if (inputs[i].type.toLowerCase() == 'text') { 
    inputs[i].className = 'textboxes'; 
   } 
  }
 }

function charCount(formField, max, min, outputElem){
 var count = document.getElementById(formField).value.length;
 document.getElementById(outputElem).innerHTML = count;
 
 if(count < min || count > max)
    document.getElementById(outputElem).style.color = '#990000';
 else
    document.getElementById(outputElem).style.color = '#009900';
 
}

function wordCount (formField, max, min, outputElem) {

        var this_field = document.getElementById(formField);
        var char_count = this_field.value.length;
        var fullStr = this_field.value + " ";
        var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
        var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
        var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
        var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
        var splitString = cleanedStr.split(" ");
        var count = splitString.length -1;
        if (fullStr.length <2) {
         count = 0;
        }
        
        document.getElementById(outputElem).innerHTML = count;
 
        if(count < min || count > max)
           document.getElementById(outputElem).style.color = '#990000';
        else
           document.getElementById(outputElem).style.color = '#009900';
    
}
  

