/* Global
 * ------------------------------------------------------------- */
function setupButtons() {
	// Share with a friend button
	setupRollOver( "btnShare", "btnShare", "images/btn_sharewithfriend_over.gif", "images/btn_sharewithfriend.gif" );
	// Join the Cranbbery Club Button
	setupRollOver( "btnJoin", "btnJoin", "images/btn_joincranberryclub_over.gif", "images/btn_joincranberryclub.gif" );
	// Coupon button
	setupRollOver( "btnCouponHotSpot", "btnCoupon", "images/btn_coupon_over.gif", "images/btn_coupon.gif" );
	// Recipes button
	setupRollOver( "btnRecipesHotSpot", "btnBottomPlanks", "images/btn_seesomerecipes_over.jpg", "images/btn_bottomplanks.jpg" );
	// Sweepstakes button
	setupRollOver( "btnSweepstakesHotSpot", "btnBottomPlanks", "images/btn_entersweepstakes_over.jpg", "images/btn_bottomplanks.jpg" );
	// Products button
	setupRollOver( "btnProductsSignHotSpot", "btnProductsBottles", "images/btn_products_bottles_over.jpg", "images/btn_products_bottles.jpg" );
	setupRollOver( "btnProductsBottlesHotSpot", "btnProductsBottles", "images/btn_products_bottles_over.jpg", "images/btn_products_bottles.jpg" );
}


/* Utility Functions 
 * ------------------------------------------------------------- */

// returns an element based on it's id
function $(x) {
  if (document.getElementById) return document.getElementById(x);
    else if (document.all) return document.all[x];
    else if (document.layers) return document.layers[x];
    else return null;
}

// changes the image
function roll(img_id, img_src) {
   $(img_id).src = img_src;
}

// sets up the rollover states for the a button
function setupRollOver( btnId, imgId, overState, outState){
	$(btnId).style.cursor 	= "pointer";
	$(btnId).onmouseover	= function(){ roll( imgId, overState ) };
	$(btnId).onmouseout		= function(){ roll( imgId, outState ) };
}

function IsValidEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	
	 return true					
}

function Swap(obj, removeRed, noHook) {
	var imgId = obj.id+"Img";
	if($(imgId).src.indexOf('red_') != -1 || removeRed) 
	{
		if(!badForm || removeRed) {
		  $(imgId).src = $(imgId).src.replace('red_', '');
		}
	}
	else 
	{
		$(imgId).src = $(imgId).src.replace('form_', 'form_red_');
		if(noHook == null) { badForm = true; }
	}
}


