/*
 * Tooltip script
 * powered by jQuery (http://www.jquery.com)
 *
 * written by Alen Grakalic (http://cssglobe.com)
 *
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.tooltip = function(){
	/* CONFIG */
		xOffset = 10;
		yOffset = 20;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("img.tooltip").hover(function(e){
        $("#tooltip").remove();
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });
	$("img.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

function recalc_submit(){
	document.cart.update_cart.value = "true";
	document.cart.submit();
}

function reset_cart() {
	document.cart.reset.value = true;
	document.cart.submit();
}

function isValidEmail (email)
{
    return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function check_data(){
		if ((document.reg.fio.value != "") &&(document.reg.phone.value != "") && (document.reg.address.value != ""))
		{
			if (isValidEmail (document.reg.email.value))
			{
				return true;
			}else{
            	alert ("Проверьте правильность заполнения адреса электронной почты!");
            	return false;
			}

		}else{
        	alert("Не все необходимые поля заполненны!");
        	return false;
		}
}

function check_data_reg(){
	if ((document.reg.login.value != "") &&
	(document.reg.pass1.value != "") &&
	(document.reg.pass2.value != "") &&
	(document.reg.fio.value != "") &&
	(document.reg.phone.value != "")){
		if (isValidEmail (document.reg.email.value)){
			if (document.reg.pass2.value == document.reg.pass1.value){
            	return true;
			}else{
            	alert ("Не совпадают введенные вами пароли!");
        		return false;
			}
		}else{
        	alert ("Проверьте правильность заполнения адреса электронной почты!");
        	return false;
		}

	}else{
    	alert("Не все необходимые поля заполненны!");
    	return false;
	}
}

function check() {
	if (isValidEmail (document.subscribe.semail.value)){
			return true;
		}else{
			alert('Не верный email адрес!');
			return false;
		}
}

function check_nal (){
    if(document.zakaz.credit.checked)
        document.zakaz.oplata[1].checked=true;
    else
        document.zakaz.oplata[0].checked=true;
    }
    function calculate_price(){

    var valuta;
    var cena;
    var counter;
    counter = parseInt(document.zakaz.counter.value);
    if(isNaN(counter)) counter = 0;
    cena = parseFloat("{{$arr.price_left}}");

    valuta = document.zakaz.price.value.substring(document.zakaz.price.value.length-4,document.zakaz.price.value.length);
    document.zakaz.price.value = parseFloat((cena*counter),10)+" "+valuta;

    }
function check_sub(){
    if (document.zakaz.fiz_lico[0].checked==true){

        if ((document.zakaz.fio.value!='')&&(document.zakaz.address.value!='')){
            return true;
        }else{
            alert ('{{#alert_submit#}}');
            return false;
        }
    }else{
         if ((document.zakaz.fio.value!='')&&(document.zakaz.address.value!='')
            &&(document.zakaz.org.value!='')&&(document.zakaz.inn.value!='')&&
            (document.zakaz.edrpou.value!='')&&(document.zakaz.address.value!='')&&
            (document.zakaz.svv.value!='')&&(document.zakaz.fax.value!='')
            )
            {
            return true;
        }else{
            alert ('{{#alert_submit#}}');
            return false;
        }
    }
}
function open_input(){
    if (document.zakaz.fiz_lico[0].checked){
        document.zakaz.org.disabled = true;
        document.zakaz.inn.disabled = true;
        document.zakaz.edrpou.disabled = true;
        document.zakaz.svv.disabled = true;
        document.zakaz.address1.disabled = true;
        document.zakaz.fax.disabled = true;
    }else{
        document.zakaz.org.disabled = false;
        document.zakaz.inn.disabled = false;
        document.zakaz.edrpou.disabled = false;
        document.zakaz.svv.disabled = false;
        document.zakaz.address1.disabled = false;
        document.zakaz.fax.disabled = false;

    }

}

// starting the script on page load
$(document).ready(function(){

	tooltip();

	$("#status *").tooltip({
        track: true,
        delay: 100,
        opacity: 0.85
        });

    $("#tab > ul").tabs();

    $('#preview a').lightBox();
    $('a.lightbox').lightBox();
});
