// JavaScript Document

$(function() {

    //country,region selection
    $("select.updatecountry").change(function() {
    
        var form;
        var inputid;

        form = $(this).parents('form:first');
        inputid = $(this).attr("id").replace("country", "subaction");

        $("input[id=" + inputid + "]", form).val("Update Country");

        form.submit();

    });

});
          

function MouseOverButton(){
	$(".button").mouseover(function(){
	   $(this).css("background-color","#e36711")
	   $(this).css("border","1px solid #e36711")
	});
    $(".button").mouseout(function(){
	   $(this).css("background-color","#545454")
	   $(this).css("border","1px solid #545454")
    });
}
 
function ToggleShow(total,number,top,video,news,content)
{
	$("#" + top).fadeIn('slow')
    $("#" + video).addClass("current")
	$("#" + news).addClass("current")
	$("#" + content).removeClass("nocurrent")
	$("#" + content ).addClass("current");
			
	for (i=1; i<=total; i++){
		if (i==number){
        $("#thmb_image_" + number).addClass("current")
		}else{
			$("#thmb_image_"+i).removeClass("current")
		}
		if ("top_image_"+i != top){
		    $("#top_image_"+i).fadeOut('slow')
		}
		if ("video_"+i != video){
		   $("#video_"+i).removeClass("current")
		}
		if ("news_"+i != news){
		    $("#news_"+i).removeClass("current")
		}
		if ("content_"+i != content){
		    $("#content_"+i).removeClass("current")
			$("#content_" + i ).addClass("nocurrent");
		}	
	}
}

var miniBasketTimer = null;
var miniBasketOpen = false;

var showBasket = function() {
	$("#show_hide_basket_button").removeClass('expand_button').addClass('hide_button');
	$("#top_basket_mini_layer").slideDown('slow', function() {
		miniBasketOpen = true;
	});
};
var hideBasket = function() {
	$("#show_hide_basket_button").removeClass('hide_button').addClass('expand_button');
	$("#top_basket_mini_layer").slideUp('slow', function() {
		miniBasketOpen = false;
	});
};

function showHideBasket() {
	if ($("#top_basket_mini_layer").is(':hidden')) {
		showBasket();
	}
	else if ($("#top_basket_mini_layer").is(':visible')) {
		hideBasket();
	}
}

function show_menu(obj_id){
    update_submenu_width(obj_id)
    $("#a_" + obj_id  ).addClass("hover")
    document.getElementById("sub_"+obj_id).style.display="block";		
}
function hide_menu(obj_id){
    $("#a_" + obj_id ).removeClass("hover")
    document.getElementById("sub_"+obj_id).style.display="none";
    $("#a_"+obj_id).css("bottom","0")
}
				
function update_submenu_width(obj_id){
    var max_chars = 0
    var width = 0
    var temp
    
    for (i=1;i<=$('#sub_'+obj_id+' li').size(); i++){
	    temp =$('#sub_'+obj_id+' li a.item_'+i).html()
	    if (temp.length > max_chars){
		    max_chars = temp.length;
		}					
    }
    width = max_chars * 7
    
    if (width < $("#a_"+obj_id).width() +10){
	    width = $("#a_"+obj_id).width() +10
	}
    document.getElementById("sub_"+obj_id).style.width= width + "px"
    //$("#a_"+obj_id).css("bottom","-1px")
}
				
function showImage(imgName, imgNumber)
{
    var largeimage = document.getElementById('largeimage');
    if (largeimage != null)
    {
        if (imgNumber == '0'){
            largeimage.src = '/Images/Product/Default/large/' + imgName;
          }
        else{
            largeimage.src = '/Images/Product/Alternative/large/' + imgName;
        }
    }
    var i;  
    for ( i=0 ; i < 4 ; i++ ){
        if ("smallimg-" + i == "smallimg-" + imgNumber){ 
         document.getElementById("smallimg-" + imgNumber).className="current";
        }
        else{
            document.getElementById("smallimg-" + i).className="";
        }
    }
}
                
function ShowHideEmailFriendForm()
{
    if ($("#email-a-friend").css("display")=='none')
    {
        $("#email-a-friend").slideDown('slow');
        document.getElementById("displayform").value = "yes";
    }
    else
    {
        $("#email-a-friend").slideUp('slow');
        document.getElementById("displayform").value = "";
        }
}
	             
function SelectFormat(productid){
    document.frm_shopping.basket_product.value = productid;
}
	             
function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}
                
function verify_shopping()
{   
    if (document.getElementById("mapcenter") != null){
        if (document.getElementById("mapcenter").value == "") {
            document.getElementById("customerror").style.display = "";
            return false
        }
        else{
            document.getElementById("customerror").style.display = "none";
        }
    }
    if (document.getElementById("modelname") != null){
        if (document.getElementById("modelname").value == "") {
            document.getElementById("customerror").style.display = "";
            return false
        }
        else{
            document.getElementById("customerror").style.display = "none";
        }
    }
    if (document.frm_shopping.map_type != null){
        var i
        var isChecked = false
        for (i=0;i<document.frm_shopping.map_type.length;i++){
            if (document.frm_shopping.map_type[i].checked==true){
                isChecked=true
                break //exit for loop, as target acquired.
            }
        }
        if (isChecked == false) {
            document.getElementById("variationerror").style.display = "";
            return false
        }
        else{
            document.getElementById("variationerror").style.display = "none";
        }
    }
//                    if (IsNumeric(document.frm_shopping.basket_quantity.value) == false) {
//                        document.getElementById("quantityerror").style.display = "";
//                        return false
//                    }
//                    else{
//                        document.getElementById("quantityerror").style.display = "none";
//                    }                   
    return true
}
                
function validate(data)
{
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~_"; 
    //var iChars = "*"; 
    
    var count =0
    for (var i = 0; i < data.length; i++) {
    if (iChars.indexOf(data.charAt(i)) != -1) {
        count = count + 1
      //alert ("Your string has special characters. \nThese are not allowed.");  	
    }  	
  }
  if (count == data.length)
  {
    alert ("Your string has special characters. \nThese are not allowed.");  	
    return false;
  }
  if (data == "Search...")
  {
    alert ("Please enter a searh term to start the search.");  	
    return false;
  }
  return true;
}

