/*----top tool bar dialog control-----*/
jnc(function(){ var tips, zip = jnc("#newZip"),callEle;	
		function openDialog(id){var dilogId='#'+id;	var formCall = "div"+dilogId+" form"; tips = jnc('#tips_'+id); var fName = jnc(formCall).attr("name"); var dWidth=jnc(dilogId).css('width');
		jnc(dilogId).dialog({	autoOpen: false, bgiframe: true, modal: true, width: dWidth,
			close: function() { jnc(formCall+" input").val('').removeClass('ui-state-error');	jnc(formCall+" select").val('').removeClass('ui-state-error'); tips.text(''); jnc(formCall+" textarea").val('');jnc(".ui-dialog").width(300);jnc(".ui-dialog").unmask()},
	buttons:{"Submit":function(){jnc(formCall+" input").removeClass('ui-state-error');jnc(formCall+" select").removeClass('ui-state-error');
					if(fName != 'SetZip'){
					jnc.ajax({type: "POST", dataType: "json", url: jnc(formCall).attr("action"), data: jnc(formCall).serialize(),						
						   beforeSend: function(){jnc(".ui-dialog").mask("Please wait..."); },
						   success: function(data){	jnc(".ui-dialog").unmask();
								if (data.status){
									if(data.msg!='1'){jnc(dilogId).dialog('destroy');window.location.href = data.resp;}
									else{alert(data.resp); jnc(dilogId).dialog('destroy');}																	
								}else{	tips.css({'color':'red'});}
								if(data.msg=='1'){tips.html(data.resp);}},
						   error: function(){alert('Oops! Something went wrong, please try later.'); jnc(dilogId).dialog('destroy');}
						});}else{setCouponURL(jnc('#newZip').val(),'1')}}
			} }); 
		jnc(dilogId).dialog('open'); return false; 
		}
		jnc('.openDialog').click(function(){callEle=jnc(this).attr("rel");/*if(callEle==''){alert('Dialog not set!')}*/openDialog(callEle);});
	});	

/**
 * Following code is based on Element.mask() implementation from ExtJS framework (http://extjs.com/) */
(function(jnc){
	jnc.fn.mask = function(label){this.unmask();	if(this.css("position") == "static") {this.addClass("masked-relative");	}
		this.addClass("masked");		
		var maskDiv = jnc('<div class="loadmask"></div>');
		//auto height fix for IE
		if(navigator.userAgent.toLowerCase().indexOf("msie") > -1){
			maskDiv.height(this.height() + parseInt(this.css("padding-top")) + parseInt(this.css("padding-bottom")));
			maskDiv.width(this.width() + parseInt(this.css("padding-left")) + parseInt(this.css("padding-right")));
		}
		//fix for z-index bug with selects in IE6
		if(navigator.userAgent.toLowerCase().indexOf("msie 6") > -1){this.find("select").addClass("masked-hidden");	}
		this.append(maskDiv);
		if(typeof label == "string") {
			var maskMsgDiv = jnc('<div class="loadmask-msg" style="display:none;"></div>'); maskMsgDiv.append('<div>' + label + '</div>');
			this.append(maskMsgDiv);			
			//calculate center position
			maskMsgDiv.css("top", Math.round(this.height() / 2 - (maskMsgDiv.height() - parseInt(maskMsgDiv.css("padding-top")) - parseInt(maskMsgDiv.css("padding-bottom"))) / 2)+"px");
			maskMsgDiv.css("left", Math.round(this.width() / 2 - (maskMsgDiv.width() - parseInt(maskMsgDiv.css("padding-left")) - parseInt(maskMsgDiv.css("padding-right"))) / 2)+"px");
			maskMsgDiv.show();
		}};
	/*** Removes mask from the element. */
	jnc.fn.unmask = function(label){this.find(".loadmask-msg,.loadmask").remove(); this.removeClass("masked"); this.removeClass("masked-relative");	this.find("select").removeClass("masked-hidden");};

/* =========================================================
// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/
// ========================================================= */

    jnc.fn.innerfade = function(options) {return this.each(function() {jnc.innerfade(this, options);}); };
    jnc.innerfade = function(container, options) { var settings = {'animationtype':'fade','speed':'normal','type':'sequence','timeout':     2000,'containerheight':'auto','runningclass':'innerfade','children':null};
        if (options)
            jnc.extend(settings, options);
        if (settings.children === null)
            var elements = jnc(container).children();
        else
            var elements = jnc(container).children(settings.children);
        if (elements.length > 1) {
            jnc(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                jnc(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide(); };
            if (settings.type == "sequence") {
                setTimeout(function() { jnc.innerfade.next(elements, settings, 1, 0); }, settings.timeout); jnc(elements[0]).show();
            } else if (settings.type == "random"){ var last = Math.floor ( Math.random () * ( elements.length ) );               setTimeout(function() { do { current = Math.floor ( Math.random ( ) * ( elements.length ) );} while (last == current ); jnc.innerfade.next(elements, settings, current, last); }, settings.timeout);
                jnc(elements[last]).show();} else if ( settings.type == 'random_start' ) { settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									jnc.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								jnc(elements[current]).show();
						}	else {alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');}
				} };
    jnc.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            jnc(elements[last]).slideUp(settings.speed);
            jnc(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            jnc(elements[last]).fadeOut(settings.speed);
            jnc(elements[current]).fadeIn(settings.speed, function() {removeFilter(jnc(this)[0]);});
		} else if (settings.animationtype == 'slideH') {
            jnc(elements[last]).hide();
            jnc(elements[current]).effect('slide',settings.speed);
        } else alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) { current = current + 1; last = current - 1;} 
			else { current = 0; last = elements.length - 1; }
        } else if (settings.type == "random") {last = current; while (current == last) current = Math.floor(Math.random() * elements.length); } else alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\''); setTimeout((function() {
            jnc.innerfade.next(elements, settings, current, last); }), settings.timeout); };
})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {if(element.style.removeAttribute){ element.style.removeAttribute('filter');}}

//---- onfocus hide search text ----//
function onFocusClear(id, v){ var f; var d2 = "e.g. Murfreesboro, TN"; var d1 = "e.g. Restaurant";
	if( v == "e.g. Restaurant" ){f = "#b2adad";} else { f = "#333"; }
	jnc(id).css({ color: f }).attr({ value: v }).focus(function(){
		if(jnc(this).val()== d1 || jnc(this).val()== d2){
			jnc(this).val("").css({ color: "#333" });
		}
	}).blur(function(){
		if(jnc(this).val()==""){
			//jnc(this).css({ color: f });
		}
	});
}

<!--
jnc(document).ready(function(){jnc('#hollerTicker').innerfade({	animationtype: 'slide',	speed: 750,	timeout: 5000, containerheight: '1.5em'}); jnc('#cmcUpdate').innerfade({	animationtype: 'slideH', speed: 600, timeout: 5000, containerheight: '1em'});
	//onFocusClear(jnc("#city_state_zip"), "e.g. Murfreesboro, TN");
	//onFocusClear(jnc("#query"), "e.g. Restaurant");
	});   
//-->

function validSearch()
{ //alert(jnc('#city_state_zip').val());
	if(jnc('#city_state_zip').val() == '' || jnc('#city_state_zip').val() == 'e.g. Murfreesboro, TN')
	{
		alert('Please enter search location.');
		jnc('#city_state_zip').focus();
		return false;
	}
	if(jnc('#query').val() == 'e.g. Restaurant'){jnc('#query').val('');}
		
	return true;
}