﻿var hoverCss1 = 'transparent url(/images/menubg_spec.gif) repeat-x scroll 0 0';
var hoverCss2 = 'transparent url(/images/menubg.gif) repeat-x scroll 0 0';
$(document).ready(function(){
	$('#menu > ul > li > ul').each(function(){
			$(this).hover(function(){$(this).parent().children('a').css({'background':hoverCss1});}, function(){$(this).parent().children('a').css({'background':hoverCss2});$(this).hide();});});
	$('#menu > ul > li > a').hover(function(){if ($(this).attr('class') != 'clearance') $(this).css({'background':hoverCss1});$('#menu > ul > li > ul').hide();$(this).parent().children('ul').show();}, function(){if ($(this).attr('class') != 'clearance') $(this).css({'background':hoverCss2});});
});
/**
 * AJAX : get price, form, price_list and so on...
 * @param	string	code		product code
 * @param	string	description	product description
 * @param	string	type		type of return value
 */
function get_form(code, description, type, codes) {
    var url = '/get_form.php';
	var back_url = encodeURIComponent(location.href);
	if (code != '') {
		$.get(url, {"code":code, "description":description, "type":type, "back_url":back_url},
			function(data){
				$('#span_' + code + '_' + type).html(data);
			}
		);	
	} else {
		var dataStr = "codes=" + codes + "&description=" + description + "&type=" + type + "&back_url=" + back_url;
			dataStr += $('#volt').length != 0 ? '&volt=' + $('#volt').val() : '';
			dataStr += $('#capacity').length != 0 ? '&capacity=' + $('#capacity').val() : '';
			dataStr += $('#color').length != 0 ? '&color=' + $('#color').val() : '';
			if ($('label:contains("Layout")').length != 0) {
				dataStr += '&layout=' + $('label:contains("Layout")').parent().text().replace('Layout:', '');
			}
		$.ajax({
			   type: "GET",
			   url:url,
			   cache:false,
			   data:dataStr,
			   success:function(data){
				$('#span_' + type).html(data);
			   }		
		});
	}
}
function change_price(code, description, codes) {
	get_form(code, description, 'price', codes);
	get_form(code, description, 'form', codes);
}
function del_error_qty_number(obj) {
    var qty = obj.value;
    var reg = /\d/;
    for (var i = 0; i < qty.length; i++) {
        if (!reg.test(qty.charAt(i))) {
            qty = qty.substr(0, i);
        }
    }
	qty = parseInt(qty) >= 1 ? qty : 1;
	obj.value = qty;
}
function bookmark(title, url){
	// Firefox
	if (window.sidebar && !document.all) {
		window.sidebar.addPanel(title, url, "");
	// Opera
	} else if(window.opera && window.print) {
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	// IE
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	}
}

function subscribe() {
	var email = $('#newsletter > input:first').val();
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (email.length > 0 && reg.test(email)) {
		var url = '/subscribe.php';
		$.get(url, {"email":encodeURIComponent(email)},
			function(data){
				alert(data);
			}
		);
	} else {
		alert('Please enter a Validated email.');
		$('#newsletter > input:first').focus();
	}
}
