
var testaIndex = 0;
var userTestaCnt = 0;
var crossFadeIsActive = false;

function SR_OpenPopup( url )
{
	features = 'resizable=no,toolbar=no,location=no,width=400,height=430,directories=no,status=no,scrollbars=yes,menubar=no';

	popupWin = window.open( url, 'getsugar', features );
	if ( popupWin )
	{
		popupWin.focus();
	}
}
		
		
function checkOrder( form, label )
{
    var returnValue = true;
    var optionsItem = form.option;
        	
    if ( optionsItem )
    {
   		var optionValue = optionsItem[optionsItem.selectedIndex].value;
		    		
    	if (optionValue == "")
    	{
    		if (label == "")
    			label = "Color/Size";
    		
        	alert( "Please choose a " + label + " before selecting this item." );
        	returnValue = false;
        }
        else
        {
        	form.action += "/" + optionValue;
        }
    }
    
    return returnValue;
}



function InitRotatingText()
{
	rotateTimer = setInterval( "doTextEffect()", 8000);
}

function doTextEffect()
{
	var textBlock = document.getElementById( 'commentsBlock' );
	if ( textBlock )
	{
		var e = new Effect.BlindDown(textBlock,
									{duration: 1.0,
									afterFinish: setNewText() });
	}
}


function doTextEffect2()
{
	var textBlock = document.getElementById( 'commentsBlock' );
	if ( textBlock )
	{
		var e = new Effect.SlideDown(textBlock,
									{duration: 1.0,
									afterFinish: setNewText() });
									
	}
}

function setNewText()
{
	var textBlock = document.getElementById( 'commentsBlock' );
	if ( textBlock && userTestaCnt > 0 )
	{
		testaIndex++;
		if ( testaIndex >= userTestaCnt )
			testaIndex = 0;
		textBlock.innerHTML = userTestamonial[testaIndex];
	}
}

// Show / Hide Div Layer Function

function toggleDiv(block, image) {

  if (document.getElementById) {
    findBlock = document.getElementById(block);
    if (image != "") { findImage = document.getElementById(image); }
  } else if (document.all) {
    findBlock = eval("document.all."+block);
    if (image != "") { findImage = eval("document.all."+image); }
  }

  if (!findBlock) return;

  if (findBlock.style.display.indexOf("none") >=0) {
    findBlock.style.display = "";
    if (image != "") { findImage.setAttribute("src", "images/widget-minus.png"); }
  }
  else if (findBlock.style.display == "") {
    findBlock.style.display = "none";
    if (image != "") { findImage.setAttribute("src", "images/widget-plus.png"); }
  }
}

function displayDiv( block, showIt )
{
  if (document.getElementById) {
    findBlock = document.getElementById(block);
  } else if (document.all) {
    findBlock = eval("document.all."+block);
  }

  if (!findBlock) return;

  if ( showIt )
  {
		findBlock.style.display = "";
  }
  else
  {
		findBlock.style.display = "none";
  }
}




// SWAP IMAGE FUNCTION for MinInfo
// (C) 2005 Panic, Inc. / Cabel Sasser
//
// Cross-fade between the two images, and swap out the thumbnail with the highlighted thumbnail

function swapImage(divID, imageID, imageToSwap) {

  globalDivID = divID;
  globalImageID = imageID;

  if (document.getElementById(imageID).src.indexOf(eval(imageToSwap+".src")) == -1) {

  	// Set the background image to the currently displaying image
        // This is now done on HTML render and when fade is complete
  	
  	
  	
  	document.getElementById(divID).style.backgroundImage = "url(" + document.getElementById(imageID).src + ")";
  
  	// Set the top image to invisible
  	setOpacity(0, imageID);

  	// Set the top image to the target image
  	document.getElementById(imageID).src = eval(imageToSwap+".src");
    
  	// Slowly fade in the top image back to visible
  	fadeElementSetup(imageID, 0, 100, 10);

  } else {

	 // alert("Already Set");

  }
}

// HIGHLIGHT image function
//
// Replaces image source with [imagename]-on.[gif]
// Undoes last image (if any).
//
// imageID = the ID of the image to replace
// modeFlag = 0 for don't highlight, 1 for highlight

function highlightImage(imageID) {
    var imageSrc = document.getElementById(imageID).src;
	if (imageSrc.indexOf("-on") != -1) {
		// alert("Already On");
	} else {
		if (typeof(lastChangedID) != "undefined") {
			// We've changed something previously.
			// Remove the "-on" from the filename and set the image back.
			var lastSrc = document.getElementById(lastChangedID).src;
   			var lastType = lastSrc.substring(lastSrc.lastIndexOf('.'), lastSrc.length);
        	var lastName = lastSrc.substring(0, lastSrc.lastIndexOf('-on'));
			document.getElementById(lastChangedID).src = lastName+lastType;
    	}
		// Now add "-on" to the changed one and set the image.
		var fileType = imageSrc.substring(imageSrc.lastIndexOf('.'), imageSrc.length);
   		var newSrc = imageSrc.replace(fileType, "-on"+fileType);
		document.getElementById(imageID).src = newSrc;
		lastChangedID = imageID;
    }
}

// FADE ITEM function
// (C) 2005 Panic, Inc.
//
// Ex: href="javascript:fadeElementSetup('testimg',100,0,10)"
// Because we can't accruately get the opacity of an item (it's always zero),
// we must force a start and an end (it can't be computed on the fly).
// So, call this as a normal function.
//
// Pass opacity values from 1 - 100.

function fadeElementSetup(theID, fdStart, fdEnd, fdSteps) {
  fadeSteps = fdSteps;
  fadeCurrent = 0;
  fadeAmount = (fdStart - fdEnd) / fadeSteps;
  
  crossFadeIsActive = true;
  
  fadeTimer = setInterval("fadeElement('"+theID+"')", 50);
}

function fadeElement(theID) {
  fadeCurrent++;
  // Set the opacity depending on if we're adding or subtracting (pos or neg)
  if (fadeAmount < 0) {
    setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);
  } else {
    setOpacity(100 - (fadeCurrent * fadeAmount), theID);
  }
  if (fadeCurrent == fadeSteps) {
  	
    // We're done, so clear
    clearInterval(fadeTimer);
	
	crossFadeIsActive = false;
	
    // Here's "mininfo" specific code, that sets the background to be prepared for the next fade
    // Set the background image to the currently displaying image
    document.getElementById(globalDivID).style.backgroundImage = "url(" + document.getElementById(globalImageID).src + ")";

  }
}

function setOpacity(opacity, theID) { 

  var object = document.getElementById(theID).style;

  // If it's 100, set it to 99 for Firefox.

  if (navigator.userAgent.indexOf("Firefox") != -1) {
    if (opacity == 100) { opacity = 99.999; } // This is majorly retarded
  }

  // Multi-browser opacity setting

  object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
  object.KhtmlOpacity = (opacity / 100);            // Safari 1.1 or lower, Konqueror
  object.MozOpacity = (opacity / 100);              // Older Mozilla+Firefox
  object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}

function validEmail( text )
{			
    if ( text == '' )
        return false;
    
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if( reg.test(text) == false )
        return false;
    var illegalChars=/[\(\)\<\>\,\;\:\\\/\"\[\]]/;
    if (text.match(illegalChars))
        return false;
    return true;
}

