function checkvalue(val) {
    if (val.indexOf('$') > -1 || val.indexOf('.') > -1) {
        alert('Enter only numbers; no dollar signs or commas. Enter only rounded dollar amounts (100, not 100.50).');
    }
}

function ShowSwap(_image,_div){
    var x = document.getElementById(_div);
    x.src = _image
}

function showmenu(themenu){
	if (document.getElementById(themenu).style.display == "none"){
		document.getElementById(themenu).style.display = "block"
	} else {
		document.getElementById(themenu).style.display = "none"
	}
}

function loaddiv(divid,ajaxpage,tab,handle){
	//TABS
	var x=document.getElementsByTagName("img");
	for (var i=0;i<x.length;i++){
		if (x[i].id.indexOf(handle)>-1){
			var element = document.getElementById(x[i].id);
			if (element.id == tab){
				element.src = element.src.replace('/off/','/on/')
			} else {
				element.onmouseover = tabover;
				element.onclick = tabclick; 
				element.onmouseout = tabout; 
				element.src = element.src.replace('/on/','/off/')
			}
		}
	}
	
	//AJAX REQUEST
	new Ajax.Request(ajaxpage, {
	method: "get",
	onComplete: function(transport) { 
		document.getElementById(divid).innerHTML = transport.responseText;
		}//-onSuccess
		}//-request arguments
		);// new ajax request	
}


//UPDATE CART
function updatecart(formname){
    new Ajax.Request('/sc_addtocart.ashx', {
	method: "post",
	parameters: Form.serialize(document.forms[formname]),
    onSuccess: function(transport) {
        var resp = transport.responseText.split("^");
	    document.getElementById("sc_minicart_subtotalwrapper").innerHTML = '$' + resp[1];
			}//-onSuccess
	    }//-request arguments
    );// new ajax request
}

//ADD TO CART
function addtoshoppingcart(formname,messageid){ 
    var Digital=new Date()
    var seconds=Digital.getSeconds()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()
    new Ajax.Request('/sc_addtocart.ashx?refresh=' + seconds + hours + minutes, {
	method: "post",
	parameters: Form.serialize(document.forms[formname]),
    onSuccess: function(transport,formname) { 	
            document.getElementById(messageid).style.display = 'block';
            document.getElementById(messageid).innerHTML = 'Added!';
	        var t = setTimeout("Effect.Fade('" + messageid + "');",1000);	
	        
	        refreshcart('refreshcart');    
	         
			}//-onSuccess
	    }//-request arguments
    );// new ajax request
}

//REFRESH CART
function refreshcart(divid){
    var Digital=new Date()
    var seconds=Digital.getSeconds()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()
    new Ajax.Request('/ajax/loadcart.aspx?refresh=' + new Date().getTime(), {
	    method: "get",
	    onSuccess: function(transport) { 
		    document.getElementById(divid).innerHTML = transport.responseText;
		    }//-onSuccess
		    }//-request arguments
		    );// new ajax request
}

//DELETE FROM CART
function remitem(cartrow,cartitemid){
	Effect.Fade(cartrow);
	
	//AJAX POST
	new Ajax.Request('/sc_deletecartitem.ashx?id=' + cartitemid, {
	method: "get",
	onComplete: function(transport) { 
        var resp = transport.responseText.split("^");
	    document.getElementById("sc_minicart_subtotalwrapper").innerHTML = '$' + resp[1];
		}//-onSuccess
		}//-request arguments
		);// new ajax request
}


//VALIDATION
function validEmail(email) {
			var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
			return re.test(email); 
		}
		
//VALIDATION
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
		
//VALIDATION
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
		
//VALIDATION
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
		
//VALIDATION
function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/14/07
	switch(elm.type){
	case "text":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

//VALIDATION
function validateform(formname,color1,color2){
	//last updated on 9/27/07
	//index of is mo betta
	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		if (x.elements[i].className.indexOf('required')>-1) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = color1;
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = color2; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}

//IMAGE ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
	if (navigator.appName == "Netscape"){
		if (document.images[i].hasAttribute("name")){ 
				if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
					setupRollover(document.images[i]);
				}
		}
	} else
		if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
			setupRollover(document.images[i]);
		}
	}
}

//IMAGE ROLLOVER
//Last Update August 1, 2008
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	//alert(thisImage.id);
	thisImage.outImage.id = thisImage.id;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.id = thisImage.id
	thisImage.overImage.src = thisImage.src.replace('/off/','/roll/')
	thisImage.onmouseover = rollOver;
}

//IMAGE ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//IMAGE ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

function spiderform(formname, validateid, successid, indicatorid, ajaxpage) {

    //VALIDATE REQUIRED
    if (validateform(formname, '#ffff00', '#ffff00')) {
        //alert(formname);
        //EMAIL IS VALID?
        var email = document.getElementById("email").value;
        if (!validEmail(email)) {
            document.getElementById("email").style.background = "white";
            document.getElementById(validateid).innerHTML = 'Invalid Email';
            if (document.getElementById(validateid).style.display == "none") {
                Effect.Appear(validateid, 'appear');
            } else {
                Effect.Shake(validateid);
            }
        } else {
            document.getElementById(validateid).style.display = "none";
            document.getElementById(indicatorid).style.display = "block";
            //AJAX POST
            new Ajax.Request(ajaxpage, {
                method: "post",
                parameters: Form.serialize(document.forms[formname]),
                onComplete: function(transport) {
                    document.getElementById(indicatorid).style.display = "none";
                    document.getElementById(successid).style.display = "block";
                    document.getElementById(successid).innerHTML = transport.responseText;

                } //-onSuccess
}//-request arguments
			); // new ajax request	

                //document.form.formname.submit();	
            }
        }
    }

window.onload = masterloader;

function masterloader(){
	rolloverInit();

}