function ShowSwap(_image,_div){
    var x = document.getElementById(_div);
    x.src = _image;
    $(".jqzoom").attr("href", "" + _image.replace('large','xl') + "");
}

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	
}

//IMAGE ROLLOVER

function rolloverInit(){
	var x=document.getElementsByTagName("img");
    for (var i=0;i<x.length;i++){
	    if (x[i].className.indexOf('rollover')>-1){
	        x[i].onmouseover = function() {
	            this.src = this.src.replace('/off/','/roll/')
	        }
	        x[i].onmouseout = function() {
	            this.src = this.src.replace('/roll/','/off/')
	        }
	    }
	}
}

function spidermenus(triggerhandle, menuhandle) {

    var x = document.getElementsByTagName("div");
    for (var i = 0; i < x.length; i++) {
        if (x[i].id.indexOf(triggerhandle) > -1) {

            //VARIABLES
            var element = document.getElementById(x[i].id);
            var theid = element.id.replace(triggerhandle, '');
            var thetrigger = document.getElementById(triggerhandle + theid);

            //OVER
            thetrigger.onmouseover = function() {
                document.getElementById(this.id.replace('trigger', '')).style.display = "block";
                var navimg = this.id.replace('menutrigger', '');
                document.getElementById('nav' + navimg).src = document.getElementById('nav' + navimg).src.replace('/off/', '/roll/');
            };

            //OUT
            thetrigger.onmouseout = function() {
                document.getElementById(this.id.replace('trigger', '')).style.display = "none";
                var navimg = this.id.replace('menutrigger', '');
                document.getElementById('nav' + navimg).src = document.getElementById('nav' + navimg).src.replace('/roll/', '/off/');
            };
        }
    }
}

function galleryrollover(){
	var x=document.getElementsByTagName("img");
    for (var i=0;i<x.length;i++){
	    if (x[i].className.indexOf('gallerythumb')>-1){
	        x[i].onmouseover = function() {
	            this.style.borderColor = 'white';
	        }
	        x[i].onmouseout = function() {
	            this.style.borderColor = '#48596a';
	        }
	    }
	}

}

//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;
			}
	}
	
function arethesame(condition1,condition2){
	if (condition1 == condition2) {
	    return true;
	} else {
	    return false;
	}
}

function spiderfriend(formname,messageid,indicatorid) {
	//VALIDATE REQUIRED
	if(validateform(formname,'yellow','white')){	
	
		//EMAIL IS VALID?
		var friendemailfrom = document.getElementById("friendemailfrom").value;	
		var friendemailto = document.getElementById("friendemailto").value;

		if(!validEmail(friendemailfrom)){
			document.getElementById("friendemailfrom").style.background = "white"; 
			document.getElementById(messageid).innerHTML = 'Invalid Email';
			if (document.getElementById(messageid).style.display == "none"){
					//Effect.Appear(messageid,'blind');
					document.getElementById(messageid).style.display = "block";
					} else {
					//Effect.Shake(messageid);
					document.getElementById(messageid).style.display = "block";
					}
			} else {
			document.getElementById(messageid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			
//            $.ajax({
//                type: "POST",
//                contentType: "application/json; charset=utf-8",
//                url: "/ajax/handlers.asmx/EmailToFriend",

//                //data: $('#' + formname).serialize(),
//                data: '{"fname":}',
//                //dataType: "json",
//                success: function(msg) {
//                alert('booooooooooooom!');

//                }
//            });

            $.post('sc_emailpagetofriend.ashx', $('#' + formname).serialize(), function(data) {
			    document.getElementById(messageid).style.display = "block";
			    document.getElementById(messageid).innerHTML = "Email Sent!";
			    document.getElementById(indicatorid).style.display = "none"; 
            })
			}
	}
}

function spidercomment(formname,messageid,indicatorid) {

	//VALIDATE REQUIRED
	if(validateform(formname,'yellow','white')){	
	
		//EMAIL IS VALID?
		var questionsemail = document.getElementById("questionsemail").value;	

		if(!validEmail(questionsemail)){
			document.getElementById("questionsemail").style.background = "white"; 
			document.getElementById(messageid).innerHTML = 'Invalid Email';
			if (document.getElementById(messageid).style.display == "none"){
					//Effect.Appear(messageid,'blind');
					document.getElementById(messageid).style.display = "block";
					} else {
					//Effect.Shake(messageid);
					document.getElementById(messageid).style.display = "block";
					}
			} else {
			document.getElementById(messageid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			
            $.post('sc_questionsaboutthispage.ashx', $('#' + formname).serialize(), function(data) {
			    document.getElementById(messageid).style.display = "block";
			    document.getElementById(messageid).innerHTML = "Email Sent!";
			    document.getElementById(indicatorid).style.display = "none"; 
            })
                			
			}
	}
}

function clearfield(id){
    if (document.getElementById(id).value == 'Enter Keyword') {
        document.getElementById(id).value = ""
    } else {
    }
}

function droplink(){
    $('.droplink').mouseover(function() {
        var thecatid = $(this).attr('name');
        $('.menuright' + thecatid).css('display', 'none');
        var theid = this.id.replace('droplink', '');
        dropitem = 'dropitem' + theid;
        $('#' + dropitem).css('display', 'block');
    });
    
}

//function ie6() {
//    if (navigator.userAgent.indexOf('IE') > -1) {
//        $('.menutrigger,.menu1,.droplink,.menu1 ul li').mouseenter(function() {
//           
//            $('#s1').cycle('pause');
//            $('#s1,.homebigpic').css('position', 'static');
//            //alert(navigator.userAgent);
//        });
//        $('.menutrigger,.menu1').mouseout(function() {
//            $('#s1').cycle('resume');
//            $('#s1').css({ 'position': 'relative' });
//            $('.homebigpic').css({ 'position': 'absolute' });
//        });
//    }
//}

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 checkorderstatus(formname, messageid, indicatorid) {

    //VALIDATE REQUIRED
    if (validateform(formname, 'yellow', 'white')) {

        //EMAIL IS VALID?
        var orderemail = document.getElementById("orderemail").value;

        if (!validEmail(orderemail)) {
            document.getElementById("orderemail").style.background = "white";
            document.getElementById(messageid).innerHTML = 'Invalid Email';
            if (document.getElementById(messageid).style.display == "none") {
                //Effect.Appear(messageid,'blind');
                document.getElementById(messageid).style.display = "block";
            } else {
                //Effect.Shake(messageid);
                document.getElementById(messageid).style.display = "block";
            }
        } else {
            document.getElementById(messageid).style.display = "none";
            document.getElementById(indicatorid).style.display = "block";

            $.post('/ajax/orderstatus.aspx', $('#' + formname).serialize(), function(data) {
                $('#' + indicatorid + '').css('display', 'none');
                $('#' + messageid + '').css('display', 'block');
                $('#' + messageid + '').html(data);
            })

        }
    }
}


window.onload = masterloader;

function masterloader(){
    droplink();
	rolloverInit();
    spidermenus('menutrigger','menu');
    galleryrollover();
    //ie6();
}