$(function() {
	$('input.i-input').focus(function(){
		if( $(this).attr('value') == $(this).attr('title') )
		{
			$(this).attr('value','');
		}
	});
	$('input.i-input').blur(function(){
		if( !$(this).attr('value') )
		{
			$(this).attr('value',$(this).attr('title'));
		}
	});
	$('form.i-emailform').submit(function(){
		e = $('input.i-input', $(this));

		if((e.attr('value')==null)||(e.attr('value')=="")){
        		alert("Please Enter your Email!")
        		e.focus();
        		return false
    		}
		if(echeck(e.attr('value'))==false){
        		e.value=""
        		e.focus()
        		return false
    		}
	});
	//OpenLP
	//$('#helpbox div.marker span').click(function(){window.open('http://server.iad.liveperson.net/hc/47786206/?cmd=file&file=visitorWantsToChat&site=47786206&referrer='+document.location,'chat47786206','width=472,height=320')});
	$('#additems .badd').click(function(){$('#additems').submit();})
	$('#ziprecalc').click(function(){$('#frm1').submit(); return false;});
	$('#promocode').click(function(){actionUpdate(); return false;});

	$('#content .scrollbox .updel .update').click(function(){actionUpdate(); return false;});
	
	$('#content .cart .btchout').click(function(){actionCheckout();return false;});
	
	$('#frm .istrok').click(function(){$('#frm').submit();return false;});
	
	//$('#frm2 .line a').click(function(){alert('Lightbox!');return false;});
	
	$('#moredetails .hg').css({'visibility':'collapse','height':'3px'});
	
	/*
	var bufHeight = $('#moredetails').height();
	$('#moredetails .title2').click(function(){
		if($(this).parent().height()>18)
		{
			$('.incon',$(this).parent()).hide()
			$(this).parent().animate({height:"18px"}, 300, "swing");
		}
		else
		{
			$(this).parent().animate({height:bufHeight+"px"}, 300, "swing", $('.incon',$(this).parent()).show());
		}
	})
	*/
	
	function mdreposition()
	{
		/*
		if($('#content').width()<=1000)
		{
			$('#moredetails').css({'margin-top':'-40px','display':'inline-block','width':'365px'})
		}
		else
		{
			$('#moredetails').css({'margin-top':'10px','display':'inline-block','width':'300px'})
		}
		*/
		$('.saveline').prependTo($('#content'));
		$('.saveline').fadeIn("slow");
	}
	
	mdreposition();
	
	//$(".icart .button a").append("<em></em>");
	$(".icart .button").hover(function() {
		$(this).find("em").animate({opacity: "show", top: "-70"}, "fast");
		var title = $(this).attr("title");
	   $(this).find("em").text(title);
	}, function() {
		$(this).find("em").animate({opacity: "hide", top: "-80"}, "fast");
	});
	
	//$(window).resize(function(){mdreposition()});

});


function echeck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail!")
        return false
    }
    return true
}

function setCaptionFromFlash(t)
{
	$("#flashbox .caption").text(t);
}

function actionUpdate()
{
	var frm = $('#frm');
	var frm2 = $('#frm2');
			
	frm.attr('action','templates/update_basket_init.asp');
			
	var promocode_to = $("input[@name='promocode']", frm);
	var promocode_from = $("input[@name='promocode']", frm2);
			
	promocode_to.val(promocode_from.val());

	frm.submit();
}

function actionCheckout()
{
	var frm = $('#frm');
	frm.attr('action','templates/checkout_init.asp');
	frm.submit();
}
