﻿jQuery(function($){
	if ($.browser.msie) { //if IE
		if ($.browser.version <= 6) { //if IE6
			$('#companyNav>li>ul>li')
				.mouseover(function(){$(this).addClass('hover');})
				.mouseout(function(){$(this).removeClass('hover');});
			
			$('#companyNav>li>')
				.mouseover(function(){$(this).addClass('hover');})
				.mouseout(function(){$(this).removeClass('hover');});
				
			$('#companyNav>li>ul>li>ul').bgiframe();
			
			$('#userNav>li')
				.mouseover(function(){$(this).addClass('hover');})
				.mouseout(function(){$(this).removeClass('hover');});
			$('#userNav>li>ul').bgiframe();
		}
	}
   
   $('#home').find('.OS').find('.imagineColectie').siblings('label').addClass('hasPhoto');
   
   
   Cufon.replace('#rightNewsletter h3', {
		hover: true
	});
	
	Cufon.replace('#rightNewsletter p', {
		hover: true
	});
	
	Cufon.replace('#headerBanenrs p', {
		hover: true
	});
	
	Cufon.replace('#rightBanners a', {
		hover: true
	});
	
	Cufon.replace('#leftHome .bottomLink a', {
		hover: true
	});
	
	Cufon.replace('.pageDestinatii #destinatii h3', {
		hover: true
	});
	
	Cufon.replace('.product .links span');
	Cufon.replace('h1');
	
	//Empty on Focus
	$('#newsletter').emptyOnFocus();
	$('#headerSearch').emptyOnFocus();
	
	$('#companyNav li.children li:last-child a').css('border-bottom','0');
	

	
	$('#topRight.homepage .oferte_speciale').click(function(){
		$(this).css({'background':'url(/i/bgTabSpan.jpg) repeat-x 0 0', 'border':'1px solid #DCD9D1', 'border-bottom':'0', 'color':'#64A53F'})
		$('#topRight.homepage .destinatii').css({'color':'#ffffff', 'background':'#8DD022'})
		$('#rightHome #destinatii').hide();
		$('#rightHome #oferte_speciale').show();
	});
	
	$('#topRight.homepage .destinatii').click(function(){
		$(this).css({'background':'url(/i/bgTabSpan.jpg) repeat-x 0 0', 'border':'1px solid #DCD9D1', 'border-bottom':'0', 'color':'#64A53F'})
		$('#topRight.homepage .oferte_speciale').css({'color':'#ffffff', 'background':'#8DD022'})
		$('#rightHome #oferte_speciale').hide();
		$('#rightHome #destinatii').show();
	});
	
	$('.itemBottom .more').click(function(){
		$(this).parent().parent().find('.item').show();
		$(this).hide();
		$(this).parent().find('.less').show();
	});
	
	$('.itemBottom .less').click(function(){
		$(this).parent().parent().find('.hide').hide();
		$(this).hide();
		$(this).parent().find('.more').show();
	});
	
	$('.pageDestinatii .oferte_speciale').click(function(){
		window.location.href='/oferte-speciale.aspx';
	});
	
	$('.pageDestinatii .destinatii').click(function(){
		window.location.href='/destinatii-2011.aspx';
	});
	
	var aboutNav = $('#companyNav');
	var children = aboutNav.find('li>ul>li');
	
	//Setting children classes
	if (children.length >= 1) {
	    children.parent().parent().addClass('children');
	} 
	
	var active = aboutNav.find('li.active');
	active.parents('li').addClass('active');
	
	//Removing the empty ul tags
	aboutNav.find('li').not('.children').find('>ul').remove();
	
	
	//var wid = $('#companyNav').width();
	//$('#companyNav').css('width',wid);
	
	$('#list.Clip-Eximtur .listItem').each(function(listCount){
		if (listCount % 2 == 1){
			$(this).addClass('aRight');
		}
	});
	
	$('#companyNav li.children').hoverIntent(
		function(){
			$(this).find('ul').show();
			$(this).addClass('hover');
		},
		function(){
			$(this).find('ul').hide();
			$(this).removeClass('hover');
		}
	);
	
	
	$('#companyNav li.children').hover(
		function(){
			$(this).find('>a').css('background','#fff url(/i/topArrowHover.gif) no-repeat right 9px');
			$(this).find('>a').css('color','#1D62C8');
			},
		function(){
			$(this).find('>a').css('background','url(/i/topArrow.gif) no-repeat right 9px');
			$(this).find('>a').css('color','#C5E9FE');
			}			
	);
	
		
 });

function SendSubscriber()
{
    var txEmail = document.getElementById("txEmail").value;  
    var error = "";
        
    if (isNotEmpty(txEmail))
    {
        if (isNotEmpty(txEmail) && !isEmail(txEmail))
        {
            error += getJSPH("Contact_EmailValid");
        }        
    }
    else
    {
        error += getJSPH("Contact_CompletatiEmail");
    }
        
    if (error.length > 0) 
    {
        error = getJSPH("Contact_RemediatiProblemele") + error;
        alert(error);
    }
    else
    {
        document.location.href='/confirmareInscriere.aspx?sEmail='+txEmail;
    }
}

function SendUnsubscriber()
{
    var txEmail = document.getElementById("txEmail").value;  
    var error = "";
        
    if (isNotEmpty(txEmail))
    {
        if (isNotEmpty(txEmail) && !isEmail(txEmail))
        {
            error += getJSPH("Contact_EmailValid");
        }        
    }
    else
    {
        error += getJSPH("Contact_CompletatiEmail");
    }
        
    if (error.length > 0) 
    {
        error = getJSPH("Contact_RemediatiProblemele") + error;
        alert(error);
    }
    else
    {
        document.location.href='/confirmareInscriere.aspx?uEmail='+txEmail;
    }
}

function isNotEmpty(val)
{
  return ((trim(val)).length>0);
}

function isEmail(val)
{
    if (!isNotEmpty(val)) {
        return true;
    }
	else {
	    var m = val.match(/\w+[.]?\w*@\w+[.]\w+/g);
	    return ((m!=null)&&(m.length>0));
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function trimiteNewsletter() {
    (function ($) {
        var email = $('#Footer_txNewsletter').val();
        if (!isValidEmail(email)) {
            alert('Vă rugăm să introduceţi o adresă de email validă.');
        } else {
            var result = Footer.RegisterSubscriber(email).value;
            $('#newsletterInfo').empty().html("<p>" + result + "</p>" );
        }
    })(jQuery)
}

function executeOnEnter(e, f) {
    if ((window.event && window.event.keyCode == 13) || e.keyCode == 13)
        eval(f);
}
