

$(document).ready(function(){
    
    $('#modalFormfileFeature input').live('keypress',function(e){
        
        if(e.which == 13 || e.which == 10){
            //$('form#login').submit();
            
            submitModalForm(siteUrl + 'request-brochure/file-feature-email', true, 'modalFormfileFeature');
               
            e.preventDefault();
            return false; 
        }
    });
    
    $('#modalFormrequestBrochure input').live('keypress',function(e){
        
        if(e.which == 13){
            //$('form#login').submit();
            
            submitModalForm(siteUrl + 'request-brochure/request-brochure', true, 'modalFormrequestBrochure');
               
            e.preventDefault();
            return false; 
        }
    });
    
    //chat link                    
    $('#liveChatLink').html('<span id="lpButDivID-1264596803959"></span>'+
                            '<script type="text/javascript" charset="UTF-8" '+
                            'src="http://service.liveperson.net/hc/40116674/?cmd=mTagRepstate&site=40116674&buttonID=12&divID=lpButDivID-1264596803959&bt=3&c=1" />'); 
    
    
   $('#chatLink').click(function(){
		
		$("#modal1").modal({
				//closeHTML: '<div class="floatRight"><img src="http://86.124.55.40:90/CUES2/private/cristi/public/images/mycues/default/layouts/main/boxes/mb_more.jpg" alt="" />&nbsp;&nbsp;<img src="http://86.124.55.40:90/CUES2/private/cristi/public/images/mycues/default/layouts/main/boxes/mb_close.jpg" alt="" /><div class="clrBth"></div></div>',
				position: ["15%", "40%"],
				overlayId: 'contactOverlay',
				opacity:61
			});

	});
	
	$('#mwClose').click(function(){
		$.modal.close();
	});
	var state = $('div#tabBar').attr('class');
	
	if(state == 'loggedOn') {menuState = ''}
	else {menuState = 'login/'} 
	$('div#tabBar a').hover(function(){
		var i=  $(this).find('img:first');
		if( i.attr('src').indexOf('_sel') < 0 )
		i.attr('src', siteUrl+'images/mycues/default/layouts/main/menu_tabs/'+menuState+''+ i.attr('id') +'_hover.png')
	},
	function(){
		var i=  $(this).find('img:first');
		if( i.attr('src').indexOf('_sel') < 0 )
		i.attr('src', siteUrl+'images/mycues/default/layouts/main/menu_tabs/'+menuState+''+ i.attr('id') +'.png')
	});
	
	//form window
    //openFormWnd();
    $('span[class*=formWindowPlaceholder]').each(function(){
        $(this).css('color', '#fff');
        str = $(this).attr('class').split('-');
        if(str.length > 1){
            $(this).parent().click(function(){
                openFormWnd($(this).attr('class').split('-')[1]);
                return false;
            });
        }
    });
    
    $('a[class*=formWindowPlaceholder]').each(function(){
        $(this).css('color', '#fff');
        str = $(this).attr('class').split('-');
        if(str.length > 1){
            $(this).click(function(){
                openFormWnd($(this).attr('class').split('-')[1]);
                return false;
            });
        }
    });

    $('a[id*=formWindowPlaceholder]').each(function(){
        $(this).css('color', '#fff');
        str = $(this).attr('id').split('-');
        if(str.length > 1){
            $(this).click(function(){
                openFormWnd($(this).attr('id').split('-')[1]);
                return false;
            });
        }
    });

    $('span[id*=formWindowPlaceholder]').each(function(){
        $(this).css('color', '#fff');
        str = $(this).attr('id').split('-');
        if(str.length > 1){
            $(this).click(function(){
                openFormWnd($(this).attr('id').split('-')[1]);
                return false;
            });
        }
    });

    //login redirect
    $('#loginLink').click(function(){
        Set_Cookie('beforeLogin2', document.location.href, 1, '/');
    });
	return true;
 });

 /* $(window).ready(function () {
  $('div.sliderGallery').each(function () {
    var ul = $('ul', this);
    var productWidth = ul.innerWidth() - $(this).outerWidth();

    var slider = $('.slider', this).slider({ 
      handle: '.handle',
      minValue: 0, 
      maxValue: productWidth, 
      slide: function (ev, ui) {
        ul.css('left', '-' + ui.value + 'px');
      }, 
      stop: function (ev, ui) {
        ul.animate({ 'left' : '-' + ui.value + 'px' }, 500, 'linear');
      }
    });
  });
});
 */

function Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function parseServerJSON(data)
{
    return eval("("+data+")");
}

function formatCurrency(num) 
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}

