/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
var TickerDisplay;
function setTickerSession(divID,myTicker) {
	var myDate=new Date();
	myDate=new Date(myDate+3600000);
	if (TickerDisplay == 1) {
		document.cookie = 'tickerSession=hide';
		TickerDisplay = 0;
	}
	else {
		document.cookie = 'tickerSession=show';
		TickerDisplay = 1;
		rotatequote();
	}
}

function rotatequote()
{
if(jQuery('#BottomHeaderAd').is (':visible') && jQuery('#DropdownBig').children (':hidden').length > 0){
      shiftOpacity('quotetext',500,1);
      t=setTimeout("showNext()",1000);
}
}

function showNext()
{
if(jQuery('#BottomHeaderAd').is (':visible') && jQuery('#DropdownBig').children (':hidden').length > 0){
      thequote = myquotes.shift(); //Pull the top one
      myquotes.push(thequote); //And add it back to the end
      document.getElementById('quotetext').innerHTML = thequote;
      shiftOpacity('quotetext',500,0);
      t=setTimeout("rotatequote()",5000);
}
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


//Begin LightWindow display functions

function showAddlImage(imgName,imgPath,imgW,imgH) {
  var url = '/getDynamicImage.aspx?h='+imgH+'&w='+imgW+'&path='+imgPath;
  myLightWindow.activateWindow({
    href: url,
    title: imgName,
    width: imgW,
    height: imgH
	});
}

function showEmailTerms() {
		myLightWindow.activateWindow({
    href: '/EMAILtermsandconditions.asp',
	  type: "page",
    title: 'Email Terms and Conditions',
    width: 400,
    height: 350
	});
}

function showSMSTerms() {
		myLightWindow.activateWindow({
    href: '/SMStermsandconditions.asp',
	  type: "page",
    title: 'SMS Terms and Conditions',
    width: 400,
    height: 350
	});
}

function showTextThisTerms() {
		myLightWindow.activateWindow({
    href: '/TEXTTHIStermsandconditions.asp',
	  type: "page",
    title: 'TEXT THIS Terms and Conditions',
    width: 400,
    height: 350
	});
}

function showEmailThisTerms() {
		myLightWindow.activateWindow({
    href: '/EMAILTHIStermsandconditions.asp',
	  type: "page",
    title: 'EMAIL THIS Terms and Conditions',
    width: 400,
    height: 350
	});
}

function showSMSAjax(Phone) {
	
	  var mobileNum = Phone.val();
		var formURL = '/SMSajax.asp?mobile=' + mobileNum;

		if ((mobileNum==null)||(mobileNum=="")){
			alert("Please Enter your Mobile Phone Number");
			Phone.focus()
		}
		if (checkInternationalPhone(mobileNum)==false){
			alert("Please Enter a Valid Mobile Phone Number");
			Phone.value="Enter Mobile #";
			Phone.focus()
		} else {
		  myLightWindow.activateWindow({
        href: formURL,
	      type: "external",
        title: 'Text Message SIGN-UP',
        width: 500,
        height: 500,
        iframeEmbed: true
	    });
	  }
}

function showTextThisAjax(Phone,productID) {
	
	  var mobileNum = Phone.val();
		var formURL = '/TEXTTHISajax.asp?mobile=' + mobileNum;
		formURL += '&prodid='+productID;

		if ((mobileNum==null)||(mobileNum=="")||(mobileNum=="Enter Mobile #")){
			alert("Please Enter your Mobile Phone Number");
			Phone.focus()
		}
		if (checkInternationalPhone(mobileNum)==false){
			alert("Please Enter a Valid Mobile Phone Number");
			Phone.value="Enter Mobile #";
			Phone.focus()
		} else {
		  myLightWindow.activateWindow({
        href: formURL,
	      type: "external",
        title: 'TEXT THIS Hotline/Product',
        width: 500,
        height: 500,
        iframeEmbed: true
	    });
	  }
}

function showEmailThisAjax(Email,productID) {
	
	  var strEmail = Email.val();
		var formURL = '/emailtofriend.asp?yourid=' + strEmail;
		formURL += '&id='+productID;

		if ((strEmail==null)||(strEmail=="")||(strEmail=="Email Address")){
			alert("Please Enter an Email Address");
			Phone.focus()
		}
		if (true==false){
			alert("Please Enter a Valid Email Address");
			Email.value="Email Address";
			Email.focus()
		} else {
		  myLightWindow.activateWindow({
        href: formURL,
	      type: "external",
        title: 'EMAIL THIS Hotline/Product',
        width: 500,
        height: 500,
        iframeEmbed: true
	    });
	  }
}

function showCommentForm(productID,imgPath) {
	  var url = '/productcommentajax.asp?id='+productID+'&imgPath='+imgPath;
		myLightWindow.activateWindow({
    href: url,	  
    title: 'Leave a Comment',
    width: 490,
    height: 515,
    type: 'external'
	});
}

function validateSMS(fName) {
	
	var postURL;
	var fObj = jQuery('#' + fName);
	
	if(fName=='fSMS'){
	  postURL = "/submitCellPhoneOnly.asp?email="
	} else if(fName=='fTextThis'){
	  postURL = "/submitTextThis.asp?email="
	} else { postURL = '#' }
	
	postURL += "&cell=" + jQuery('#mobileNum').val();

	if(jQuery('#over16').is(':checked')){
		postURL += "&checkbox=1";
		var myForm = document.getElementById(fName);
		myForm.action = postURL;
		myForm.submit();	
	
	} else {
		alert('Sorry. You must be at least 16 years old.');		
	}
}

//Rollover effect for category tree

var catHoverCurrent='';
var catHoverLocked=false;

function catHoverOn(id) {
  if ($(id + '_Inner').hasClassName('HiddenSubNav')) $(id + '_Inner').hide().removeClassName('HiddenSubNav');
	if ((!$(id + '_Inner').visible()) && (catHoverCurrent!=id) && (!catHoverLocked)) {
		catHoverCurrent=id;
		catHoverLocked=true;
		$('GlanceMenu').childElements().each(function(e) {
			var id=$(e).id;
			if ($(id + '_Inner').visible()) {
				new Effect.SlideUp(id + '_Inner', {
					duration: 0.9,
					transition: Effect.Transitions.sinoidal
				});
			}
		});

		new Effect.SlideDown(id + '_Inner', {
			duration: 0.9,
			transition: Effect.Transitions.sinoidal,
			afterFinish: function() {
				catHoverLocked=false;
			}
		});
	}
}

function catHoverOff(id) {
	//setTimeout("catHoverOffTest('" + id + "');", 100);
}

function catHoverOffTest(id) {
}


//LightWindow for AJAX popup windows

var myLightWindow = null;

function lightwindowInit() {
  myLightWindow = new lightwindow();
}

//Product Page Options Handling

function setOption(optValue, changePrice) {
	$('options').value = $('option_' + optValue).value;
	
	if (changePrice) 
	{
		if ($('option_' + optValue + '_extra')) 
		{
			var offset = $('option_' + optValue + '_extra').value;
    	if (parseFloat(offset) >= 0)
    	{
    		var newList = parseFloat($('StorePriceX').value) + parseFloat(offset);
    		var newPrice = parseFloat($('StorePrice').value) + parseFloat(offset);
    	
    		if ($('StorePriceX')) { $('StorePriceX').innerHTML = '$' + formatCurrency(newList); }    	
    		(newPrice > 0) ? $('StorePrice').innerHTML = '$' + formatCurrency(newPrice) : $('StorePrice').innerHTML = 'FREE!';
  		}
  	}
  }
}
// jQuery functions and other initializations go here...

jQuery(document).ready(function() {
	  if (lightwindowInit) lightwindowInit();
		jQuery("#HomeCrossSell").multipleElementsCycle({
			showCount: 4
		});
		jQuery("#CrossSellProduct").multipleElementsCycle({
			showCount: 3
		});
	});


jQuery(document).ready(function () {
    jQuery('#slideshow').cycle({
        delay: 0,
        speed: 1000,
		timeout: 31000,  
        next: '#slidenext',
        prev: '#slideprev',
        pager: '#slideshownav',
        pagerAnchorBuilder: function (idx, slide) {
            // return sel string for existing anchor
            return '#slideshownav li:eq(' + (idx) + ') a';
        }
    });
});


<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
//window.open(URL,null,"height=200,width=400,status=yes,toolbar=yes,menubar=yes,location=yes");
}
// End -->

