

var BOOST = {
	
	init : function(){
    
    tablecloth();
    
    //zebra stripes
	  $('table tbody tr:odd').addClass('odd');  

    // set up the color boxes
		$('div.color-white-boxes dd').hide();
	  
		$('div.color-white-boxes dt').click(function(){
			if ($(this).hasClass('expanded')) {
				$(this).removeClass('expanded').next().slideUp('fast');
			}
			else{
				$(this).addClass('expanded').next().slideDown('fast');	
			}
		});
		
		// view plan details
		$('div.unlimited_view_plan_details a').click( function(){
		    
		    if ($(this).hasClass('on'))
		        $(this).removeClass('on');
		    else{
		        $(this).addClass('on');
		        setOmnitureForDetailPage();
		    }
		        
			$('div.rates-overlay').slideToggle();
			return false; // dont follow # link
		});
		
		$('div.rates-overlay a.close').click( function(){
			$('div.rates-overlay').slideUp(); 
			$('div.unlimited_view_plan_details a').removeClass('on');
			return false;
		});
		
		
	    // plan feature and highlights
		$('div.item_list dd').hide();
	  
		$('div.item_list dt').click(function(){
			if ($(this).hasClass('expanded')) {
				$(this).removeClass('expanded').next().slideUp('fast');
			}
			else{
				$(this).addClass('expanded').next().slideDown('fast');	
			}
		});
		
		
		// phone info toggles
		$('.also-available.swapc290-on img').click( function(){ $('.swapc290-on').hide(); $('.swapc290-off').show();      });
		$('.also-available.swapc290-off img').click( function(){ $('.swapc290-off').hide(); $('.swapc290-on').show();      });
		
		// map overlay things
		
		$('.payasugo_coverageMap').click( function(){  viewNationalMap(); setOmnitureForMapPage();  document.location.href="#"; } );
		$('.btnCloseMap img').click( function(){ 		  $('.zipOverlay').hide(); 		} );
		$('#btnNationalMap img').click( viewNationalMap );
		
		$('#unlimitedDetail div.coverageMap').click (viewRegionalMap );
		$('div.coverageMap_pp').click ( function(){  viewRegionalMap();  setOmnitureForMapPage(); document.location.href="#"; } );
		
	
	
	    $('.color-white-boxes dt').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });
	    $('.item_list dt').hover( function(){  $(this).addClass('hovered'); }, function(){ $(this).removeClass('hovered');  });
	} // end of init()	
		
};



/******************/
/* image toogle */
/******************/

 function startmenu()
  {
	for (var k=0; k < 4; k++) {
		if (document.getElementById("menu" + k) != null) {
			document.getElementById("menu" + k).style.display = "none";
		}
		if (document.getElementById("pic" + k) != null) {
			document.getElementById("pic" + k).style.display = "none";
		}
		if (document.getElementById("hideDiv" + k) != null) {
			document.getElementById("hideDiv" + k).style.display = "block";
		}
	}
  }

  function menu0func()
  {
  	if(document.getElementById("menu0").style.display == "none")
  	{
  		startmenu();
  		document.getElementById("menu0").style.display = "block";
		document.getElementById("pic0").style.display = "block";
		document.getElementById("hideDiv0").style.display = "none";
  	}
	
	else 
  	{
  		startmenu();
		document.getElementById("hideDiv0").style.display = "block";
  	}
  	
  }
  
  function menu1func()
  {
  	if( document.getElementById("menu1").style.display == "none")
  	{
  		startmenu();
  		document.getElementById("menu1").style.display = "block";
  		document.getElementById("pic1").style.display = "block";
  		document.getElementById("hideDiv1").style.display = "none";
  	}
	
	  else 
  	{
  		startmenu();
		  document.getElementById("hideDiv1").style.display = "block";
  	}
  	
  }
  
  function menu2func()
  {
  
  	if(document.getElementById("menu2").style.display == "none")
  	{
  		startmenu();
  		document.getElementById("menu2").style.display = "block";
		document.getElementById("pic2").style.display = "block";
		document.getElementById("hideDiv2").style.display = "none";
  	}
	
	else
  	{
  		startmenu();
		document.getElementById("hideDiv2").style.display = "block";
  	}
	
  }
  

/*****
* Ajax Methods
*/




function getPlans(){
    var zipCode = $get('zipCode').value;
   //set the cookie if it already does not exits
   //check if the cookie exits and has the same value
   var cookieValue = getCookie("ZipCode");
   if(cookieValue == zipCode){
    //cookie is already there dont do anything
   }else{
    //set cookie
    setCookie( "ZipCode" ,zipCode, 365); 
   }
    
   
    ZipCodeWebService.GetPlans(zipCode, onSuccess);
}

function onSuccess(result){
   
   resultPlan = result;
   Sys.Debug.trace(result);
   showPlans(result);
}

/*
* This is the email notification stub call the function with zipcode and email
*/
function saveEmail(){
    EmailWebService.SaveEmail(zipcode, email);
}

function showPlans(result){
    
    var zipcode = $get('zipCode').value;
    var regionName;
    if(result.length>0){
        for(var x=0; x<3; x++){
            $get("plan_"+x+"_Description").innerHTML = result[x].Plan.Description;
            $get("plan_"+x+"_Price").innerHTML = "$"+result[x].Cost;
            $get("Table_Plan_"+x+"_Desc").innerHTML = result[x].Plan.Description;
            $get("Table_Plan_"+x+"_Price").innerHTML = "$"+result[x].Cost;
            
            if (result[x].ExtendedHomeCallingCost == 0){
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="N/A";
            }
            else{
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="$"+ result[x].ExtendedHomeCallingCost+"/Month";
            }
            
        }
        
        session.mapImg = result[0].CoverageArea.ImageCode;
        session.regionName = result[0].CoverageArea.CoverageAreaName;
        if(result[0].CoverageArea.ExtendedCoverageArea != null){
            session.mapExtendedImg = result[0].CoverageArea.ExtendedCoverageArea.ImageCode;
         }else{
            $get('btnExtendedMap').style.display="none";
         }
     
        $get('ZipCodeContainer').style.display = "none";
        $get('coverageArea').innerHTML = result[0].CoverageArea.CoverageAreaName;
        $get('priceContainer').style.display = '';
        regionName = result[0].CoverageArea.CoverageAreaName;
      
    }else{
        //show the email textbox and call the emailnotificationweb service
        
            //var pos = $('#Plan_0_Compare').offset();
            //if (pos.left && pos.top)
            //  $('#EmailContainer').css({ left: pos.left, top: pos.top  });
            $('#EmailContainer').show();

            
            for(var x=0; x<3; x++){
                 //$get("Table_Plan_"+x+"_Desc").innerHTML = "Zipcode Needed";
                 $get("Table_Plan_"+x+"_Price").innerHTML = " ";
                 $get("Plan_"+x+"_ExtendedCalling").innerHTML = " ";
            }
            regionName = "Region Unavailable";
    }
    
    //Omniture implementation
    
     setOmnitureForZip(zipcode, regionName);
    
}



function changeZip(){
    $get('priceContainer').style.display = "none";  
    $get('ZipCodeContainer').style.display = "";
    $get('EmailContainer').style.display = "none";
    $get('ThankYouDiv').style.display = "none";
    setCookie( "ZipCode" ,'', 365); 
    
}
    
 /*
 * function to create a javascript cookie
 * source:http://www.w3schools.com/js/js_cookies.asp
 */
 function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
 
 /*
 *function to retrive a cookie
 * source: http://www.w3schools.com/js/js_cookies.asp 
 */
function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
          c_start=document.cookie.indexOf(c_name + "=")
          if (c_start!=-1)
            { 
                c_start=c_start + c_name.length+1 
                c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            } 
      }
    return ""
}

/*
* checks for cookies and zipcode if the user had entered it in last one year
* if yes sets the cookie value else does nothing
*/

function unLimitedOnLoad(){
   var zipCode = $get('zipCode');
  
   /*
   * Check of the cookie exists,
   * If yes read from the cookie and make the ajax call
   * 
   */
    var cookieValue = getCookie("ZipCode");
    //check if the cookie value exists
    if(cookieValue){
        zipCode.value = cookieValue;
        //ZipCodeWebService.GetPlans(zipCode, onSuccess);
        getPlans();
   }else{
        setOmnitureForNoZip();
   }
    
}


function setOmnitureForZip(zipcode, regionName){
    
    //clear the variables
       void(s.t());
    s.pageName = "Unlimited with Zip - Plan Detail";
    s.channel ="Shop";
    s.prop2 = "Browse Plans Section";
    s.events = "event13";
    s.prop5 =  zipcode;
    s.evar18 = regionName;

    var s_code=s.t();
    if(s_code)document.write(s_code); 
    
    Sys.Debug.trace(s);
}

function setOmnitureForNoZip(){
 /*SiteCatalyst Variables */
    //clear the variables
    void(s.t());
    //set the values
    s.pageName = "Unlimited Plan";
    s.channel ="Shop";
    s.prop2 = "Browse Plans Section";
    s.events = "event13";

    var s_code=s.t();
    if(s_code)document.write(s_code);

    //Sys.Debug.trace(s);

}



function compareOnLoad(){
    var cookieValue = getCookie("ZipCode");
    
    if(cookieValue){
       //$('#ZipCodeContainer').html('Loading...');
        ZipCodeWebService.GetPlans(cookieValue, onCompareSuccess);   
    }else{
        var pos = $('#Plan_0_Compare').offset();
        $('#enter-zip').css({ left: pos.left, top: pos.top  });
        $('#enter-zip').show();
        $('#EmailContainer').hide();
        
        //Omniture code
        s.pageName = "Compare All Plans";
        s.channel = "Shop";
        s.prop2 = "Browse Plans Section";
        s.events = "event13";
        
        //Omniture code do not alter
        var s_code=s.t();
        if(s_code)document.write(s_code);

    }

}

function submitEmail(){
    var emailValue = $get('email').value;
    var zipCode = $get('zipCode').value;
    EmailNotificationWebService.SaveEmail(emailValue, zipCode, emailSubmitSuccess);  
}

function emailSubmitSuccess(result){
   if(result){
    $get('ThankYouDiv').style.display ="";
    $get('EmailContainer').style.display = "none";
    $get('ZipCodeContainer').style.display="none";
   }
}

function onCompareSuccess(result){
    if(result.length>0){
        for(var x=0; x<3; x++){
            $get("Plan_"+x+"_Compare").innerHTML = "<div>" + result[x].Plan.Description+"</div><span>"+ "$"+ result[x].Cost+"/</span>Month";
            
            if (result[x].ExtendedHomeCallingCost == 0){
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="N/A";
            }
            else{
                $get("Plan_"+x+"_ExtendedCalling").innerHTML ="$"+ result[x].ExtendedHomeCallingCost+" Month";
            }
        } 
          $get('enter-zip').style.display= "none";
    }else{
        //$get('enter-zip').style.display= "";
        //Show the Email Div
        
        var pos = $('#Plan_0_Compare').offset(); // we want to position Email Container on top of Plan 0
        if (pos.left && pos.top)
            $('#EmailContainer').css({ left: pos.left, top: pos.top  });
            
        $get('EmailContainer').style.display = "";
    }
    
     //Omniture code
            
            //clear the variables
            
            void(s.t());
            
            s.pageName = "Compare All Plans with zip";
            s.channel = "Shop";
            s.prop2 = "Browse Plans Section";
            s.events = "event13";
            s.prop5 =  zipcode;
            s.evar18 = regionName;
            
            //Omniture code do not alter
            var s_code=s.t();
            if(s_code)document.write(s_code);
  }

function compareSubmitZipCode(){
    var zipCode = $get('zip-code').value;
    
    if (zipCode=='Enter Zip') {
        alert('Please enter a valid Zip code');
    }
    else {
        //make the Ajax Call
        ZipCodeWebService.GetPlans(zipCode, onCompareSuccess);
    }    
}

function compareSubmitEmail(){
    var zipCode = $get('zip-code').value;
    var email = $get('email').value;
    
    if (email=='Email') {
        alert('Please enter a valid email address');
    }
    else {
        EmailWebService.SaveEmail(zipCode, email, comeback);
    }
}



function planHubOnLoad(){

    //read from the cookie and put the value in the textbox
    var zipCode = $get('ZipCode');
     var cookieValue = getCookie("ZipCode");
    //check if the cookie value exists
    if(cookieValue){
        zipCode.value = cookieValue;
   }
}

function planHubSubmit(){
    var zipCode = $get('ZipCode').value
    //var cookieValue = getCookie("ZipCode");
    
    if (zipCode=='Enter Zip') {
        alert('Please enter a valid Zip code');
    }
    else {
        //rewrite the cookie
        setCookie( "ZipCode" ,zipCode, 365);    
        document.location.href = "unlimited.aspx";
    }
}





// map viewing script from boostmobile.com

function viewNationalMap(){
	//$('#headerFlash').css({visibility,'hidden'});
	$('#stateMap').hide();
	$('#nationalMap').show();
	//	doc.tracking.sendSClickHit('viewNationalMap');
}

function viewStateMap( state, stateName ){
	var img = $('#stateMapImg').attr('src','http://plans.boostmobile.com/images/maps/BSMB_' + state + '_WEB.gif');
	$('span#stateName').html(stateName);
	//$('#headerFlash').css({visibility,'hidden'});
	$('#stateMap').show();
	$('#nationalMap').hide();
}




    // temporary variable.
		var session = {mapImg: 'SCA', regionName : 'Californiaaaa', mapExtendedImg: '' }
		
		
function viewRegionalMap(evt){

	//if(! session.zip)	$('zipChecker2').show();
	
	
	// after zip check in submitZip;
	  /*
		if(session.mapImg == null) {
			// if zip set on page 2 and then return to page 1 to view map
			// get mapImg and regionName from ajax call
			session.checkAvailability(session.zip,1);
			return;
		}		
		*/
		
		
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '761';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_regional/BSMB_" + session.mapImg + "_WEB.gif')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_regional/BSMB_' + session.mapImg + '_WEB.gif';


		var regionName = $('#unlRegionName').html(session.regionName);
		//displayUnlimitedPrice();
		$('#zipChecker2').hide();
		//doc.dhtml.toggleVisibilityById('headerFlash','hidden');
		$('#unlimitedMap').show();
		$('#emailSubmitWrap').hide();
		//$('#btnViewNationalMap').css({visibility:'visible'});


		//doc.tracking.sendSClickHit('viewRegionalMap');

}

function viewRegionalNationalMap(){
    //$('#btnViewNationalMap').css({visibility:'hidden'});
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '461';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_national/BSMB_NAT_" + session.mapImg + "_WEB.png')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_national/BSMB_NAT_' + session.mapImg + '_WEB.gif';
		//img.src = doc.utils.baseURL +'images/maps/unl_regional/BSMB_NAT_WEB.gif';
		//img.style.backgroundImage = "url('" + doc.utils.baseURL +"images/maps/unl_regional/BSMB_NAT_WEB.gif')";
		$('#unlRegionName').html(session.regionName);
		//regionName.innerHTML = 'National';
}



function viewExtendedMap(){
    //$('#btnViewNationalMap').css({visibility:'hidden'});
		var img = document.getElementById('unlMapImg');
		img.width  = '696';
		img.height = '761';
		img.style.backgroundImage = "url('http://plans.boostmobile.com/images/maps/unl_extended/BSMB_EXT_" + session.mapExtendedImg + "_WEB.png')";
		img.src = 'http://plans.boostmobile.com/images/maps/unl_extended/BSMB_EXT_' + session.mapExtendedImg + '_WEB.gif';
		//img.src = doc.utils.baseURL +'images/maps/unl_regional/BSMB_NAT_WEB.gif';
		//img.style.backgroundImage = "url('" + doc.utils.baseURL +"images/maps/unl_regional/BSMB_NAT_WEB.gif')";
		$('#unlRegionName').html(session.regionName);
		//regionName.innerHTML = 'National';
}



function closeMap( evt ){
	var btn = doc.dhtml.getTargetId(evt);	
	btn = btn.toLowerCase();
	var openedMap = ((btn.indexOf('national') > -1) ? 'national' : (btn.indexOf('state') > -1) ? 'state' : 'unlimited') + 'Map';
	doc.dhtml.toggleDisplayById(openedMap,'none');

}





// cache background images!
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

