﻿//Event.observe(window, 'load', init, false);
// init is called from applicationLoadHandler in master page

function init() {
  var roll_over_element; 
  
  // rollovers for the back and next buttons
  if( $$('.backAndNext').size() > 0 ) {
    new Rollover($$('.backAndNext')[0].id, {suffixSeperator: '-', rolloverSuffix: 'over', selectedSuffix: ''});
  }
        
  // rollovers for the page rank yes/no links
  //if( $('YesNo') ) {
  //  new Rollover('YesNo', {suffixSeperator: '-', rolloverSuffix: 'over', selectedSuffix: ''});
  //}
  
  // rollovers for the low/high bandwidth buttons
  if( $('PlayerUI') ) {
    new Rollover('PlayerUI', {suffixSeperator: '-', rolloverSuffix: 'over', selectedSuffix: ''});
  }
  
  // rollover for the "go" button on the search
  if( $('Search') ) {
    new Rollover('Search', {suffixSeperator: '-', rolloverSuffix: 'over', selectedSuffix: ''});
  }
  
  // rollover for the "go" button on the search
  if( $('autocomplete') ) {
    new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "/Ajax/keywords.aspx", {paramName: "value", minChars: 1, frequency: 0.4});
  }
  
  // handles hiding/showing the accordion style content lists
  var ccls = $$('.collapsingContentList');
   
  if(ccls.size() > 0) {
  
    // hide all
    $$('.collapsingContentList .content').each( function(contentDiv) {
      contentDiv.hide();    
    });
    
    ccls.each(function(element){
      element.observe('click', function(event) {
      
        var e = Event.element(event);
        
        // show/hide the content
        if(e.hasClassName('toggle')) {
          e.next().toggle();   
        }
        
        // assign class of active to the parent if currently inactive
        // visa versa if currently active
        if(e.up().hasClassName('active')) {
          e.up().removeClassName('active'); 
        } else {
          e.up().addClassName('active'); 
        }
        
      });  
    });
  }
  
}

function cl(inp, val) {
  if (inp.value == val) {
    inp.value = "";
  }    
}

function fl(inp, val) {
  if (inp.value == "") {
    inp.value = val;
  }
}

function clickButton(e, buttonid){
  var evt = e ? e : window.event;
  var bt = $(buttonid);
  if (bt){
    if (evt.keyCode == 13){
      bt.click();
      return false;
    }
  }
}

function print_preview() {
	// Print the page
	window.print();
}

function submitZipCode(zipcode){
    if(isValidZipcode(zipcode)){
        setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$txtZipCode\',\'\')', 0);
    }
}

// Check that a US zip code is valid
function isValidZipcode(zipcode) {
 
   if (!(zipcode.length == 5 || zipcode.length == 9 || zipcode.length == 10)) {
     return false;
   }
   
   if ((zipcode.length == 5 || zipcode.length == 9) && !isNumeric(zipcode)) {
     return false;
   }
   
   if (zipcode.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/) == -1) {
    return false;
   }
   
   return true;
}

// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
   if (string.search) {
      if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
   }
   return true;
}

// Remove all spaces from a string
function removeSpaces(string) {   
   var newString = '';
   for (var i = 0; i < string.length; i++) {
      if (string.charAt(i) != ' ') newString += string.charAt(i);
   }
   return newString;
}

function bookmark(){

  //if (window.external) {
  //  window.external.AddFavorite(window.location.href,document.title);
  //} 
  //else if (window.sidebar) {
  //  window.sidebar.addPanel(document.title,window.location.href,"");
  //} 
  //else {
  //  alert("Press CTRL-D or CTRL-T to bookmark this page");
  //}
  
  var ua=navigator.userAgent.toLowerCase();
  var isKonq=(ua.indexOf('konqueror')!=-1);
  var isMac=(ua.indexOf('mac')!=-1);
  var isFirefox = (ua.indexOf('firefox')!=-1)
  var isSafari=(ua.indexOf('webkit')!=-1);
  var isIE =(ua.indexOf('msie')!=-1);
  var buttonStr=isMac?'Command/Cmd':'CTRL';

  if(window.external && isIE) {
      window.external.AddFavorite(window.location.href, document.title); // IE/Win
  } 
  else if(window.sidebar && isFirefox) {
      window.sidebar.addPanel(document.title,window.location.href,""); // firefox
  } 
  else if(isKonq) {
    alert('You need to press CTRL + B to bookmark this page.');
  } 
  else if(window.opera) {
    void(0); // do nothing here (Opera 7+)
  } 
  else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
    alert('You need to press '+buttonStr+' + D to bookmark this page.');
  } 
  else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
    alert('You need to press Command/Cmd + D to bookmark this page.');    
  } 
  else {
    alert('In order to bookmark this page you need to do so manually '+
      'through your browser.');
  }
    
}

function loadSWF(bandwidth, videoSrc, imageSrc, captionSrc) {
	var swf = new SWFObject("/swf/testimonialsPlayer.swf", "reversemortgage", "458", "357", "8.0.0.0", "#FFFFFF");
	swf.addVariable("bandwidth", bandwidth);
	swf.addVariable("videoSrc", videoSrc);
	swf.addVariable("imageSrc", imageSrc);
	swf.addVariable("captionSrc", captionSrc);
	swf.write("flashcontent");
}
/* fire a DART tag for a link */
function linkDART(code, href, newWindow) {
	var tag_url = window.location.protocol + "//fls.doubleclick.net/activityi;" + code + ";num="+Math.floor(Math.random()*999999);
	if (document.getElementById("DCLK_FLDiv")) {
		var flDiv=document.getElementById("DCLK_FLDiv");
	}
	else {
		var flDiv=document.body.appendChild(document.createElement("div"));flDiv.id="DCLK_FLDiv";flDiv.style.display="none";
	}
	var DCLK_FLIframe=document.createElement("iframe");
	DCLK_FLIframe.id="DCLK_FLIframe_"+Math.floor(Math.random()*999999);
	DCLK_FLIframe.src=tag_url;
	flDiv.appendChild(DCLK_FLIframe);
	if (! newWindow) {
		setTimeout("window.location.href = '" + href + "';", 1000);
		return false;
	}
	return true;
}
