/**************************************************
	jQuery Tooltips
**************************************************/
 
$(document).ready(function() {   
	$('a, span, div, p, dt, h3, input, img').tooltip({									 
		track: true,
		delay: 0,
		showURL: false
	});
});
  
/**************************************************
	jQuery ZEBRA Tables (table class="zebra")
**************************************************/

$(document).ready(function(){
  $("table.zebra tr:nth-child(even)").addClass("even");
  $("table.zebra tr:nth-child(odd)").addClass("odd");
  $("table.zebra-grey tr:nth-child(even)").addClass("even");
  $("table.zebra-grey tr:nth-child(odd)").addClass("odd");
});


/**************************************************
	jQuery Toggler
**************************************************/

$(document).ready(function() {
		$('.toggled').hide();
          $('.toggler').click(function() {
               if ($(this).next('.toggled').is(":hidden"))
               {
                    $(this).addClass("active");
					$(this).next('.toggled').slideDown("fast");
               } else {
				    $(this).removeClass("active");
                    $(this).next('.toggled').slideUp("fast");
               }
          });
     });

/**************************************************
	jQuery Colorbox Modal Window
**************************************************/

$(document).ready(function(){
	$(".modalsublink1").colorbox({iframe:true});
	$(".modallink1").colorbox({width:"960px", height:"340px", inline:true, href:"#modalbox1"});
	$(".modallink2").colorbox({width:"960px", height:"720px", inline:true, href:"#modalbox2"});	
});

/**************************************************
	jQuery Form Fields
**************************************************/

$(document).ready(function() {
    $('input[type="text"],input[type="password"],textarea').addClass("idleField");
	$('input[type="text"],input[type="password"],textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
    });
    $('input[type="text"],input[type="password"],textarea').blur(function() {
    	$(this).removeClass("focusField").addClass("idleField");
    });
});

/**************************************************
	Sliding Anchor
**************************************************/

$(document).ready(function() {
$('a.slide').slide();
});

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'400');
}


/**************************************************
	Exchange Services Error Notifications
**************************************************/

$(document).ready(function(){
       
$("#blackberrynotice").css("display","none"); // Inline notices vs popups - not used
$("#softwarenotice").css("display","none");  // Inline notices vs popups - not used


$("#tableconfigoptions select").change(function(){
												
	var $EAccounts = 0;
	var $BAccounts = 0;
	var $Licenses = 0;
  
	var $EAccounts = $("#custfield_4").attr("selectedIndex") + 1;
	var $BAccounts = $("#custfield_7").attr("selectedIndex");
	var $Licenses = $("#custfield_9").attr("selectedIndex");

	//alert( $Licenses );
	//alert( $EAccounts + " | " + $BAccounts + " | " + $Licenses );
							  	
	if ( ( $EAccounts < $BAccounts ) && ( ( $EAccounts <= $Licenses ) || ( $Licenses == 0 ) ) ) // too many bb accts
	{	
		$("#service_config_button").attr("disabled", "disabled");
		$("#custfieldwrap_4").addClass("custfielderror");
		$("#custfieldwrap_7").addClass("custfielderror");
		$("#custfieldwrap_9").removeClass("custfielderror");
		$.fn.colorbox({width:"700px", height:"260px", inline:true, href:"#modalbox3"});
	}
	else if ( $EAccounts >= $BAccounts && $EAccounts > $Licenses && $Licenses !=0 ) // too few licenses
	{     
		$("#service_config_button").attr("disabled", "disabled");
		$("#custfieldwrap_4").addClass("custfielderror");
		$("#custfieldwrap_7").removeClass("custfielderror");
		$("#custfieldwrap_9").addClass("custfielderror");
		$.fn.colorbox({width:"700px", height:"340px", inline:true, href:"#modalbox4"});
	}
	else if ( $EAccounts < $BAccounts && $EAccounts > $Licenses && $Licenses !=0 ) // too many bb accts + too few licenses
	{     
		$("#service_config_button").attr("disabled", "disabled");
		$("#custfieldwrap_4").addClass("custfielderror");
		$("#custfieldwrap_7").addClass("custfielderror");
		$("#custfieldwrap_9").addClass("custfielderror");
		$.fn.colorbox({width:"700px", height:"380px", inline:true, href:"#modalbox5"});
	}
	else if ( $EAccounts >= $BAccounts && $EAccounts <= $Licenses ) // bb ok + license ok
	{
		$("#service_config_button").removeAttr("disabled");
		$("#custfieldwrap_4").removeClass("custfielderror");
		$("#custfieldwrap_7").removeClass("custfielderror");
		$("#custfieldwrap_9").removeClass("custfielderror");
	}
	else // default to ok
	{     
		$("#service_config_button").removeAttr("disabled");
		$("#custfieldwrap_4").removeClass("custfielderror");
		$("#custfieldwrap_7").removeClass("custfielderror");
		$("#custfieldwrap_9").removeClass("custfielderror");
	}
});
});
 

/**************************************************
	jQuery Impromptu Modal Confirm Empty Cart
**************************************************/

$(function(){
		   
$('#cartempty').click(function(){	   

	var msg = '<h3>Are you sure you want to empty all items from your shopping cart?</h3>';	   
		   
	$.prompt(msg,{
			 
		buttons: { Ok: true , Cancel: false },
		prefix: 'modalconfirm', 
		opacity: 0.8,
		overlayspeed: 'fast', // "slow", "fast", number
		promptspeed: 'medium', // "slow", "fast", number
		show: 'fadeIn', // "show","fadeIn","slideDown","promptDropIn"
		top:'30%',
		focus: 1,
			 
		callback: function(v,m,f){ 
			if(v == true) {
 			window.location = 'cart.php?a=empty';
        	}
		else {
			return false; 
        	}
		}	 
			  
	//}).children('#modalconfirm').corner();
	})

	return false; 

	});
	
});

/**************************************************
	jQuery Impromptu Modal Confirm Remove Cart Item
**************************************************/


function removeItem(type,num) {

	var msg = '<h3>Are you sure you want to remove this service from your shopping cart?</h3>';	   
		   
	$.prompt(msg,{
			 
		buttons:{ Ok: true , Cancel: false },
		prefix:'modalconfirm', 
		opacity: 0.8,
		overlayspeed:'fast', // "slow", "fast", number
		promptspeed: 'medium', // "slow", "fast", number
		show: 'fadeIn', // "show","fadeIn","slideDown","promptDropIn"
		top:'30%',
		focus: 1,
			 
		callback: function(v,m,f){ 
			if(v == true) {
 			window.location = 'cart.php?a=remove&r='+type+'&i='+num;
        	}
		else {
			return false; 
        	}
		}	 
			  
	//}).children('#modalconfirm').corner();
	
	})

	return false;
	
};
