// JavaScript Document
function showTab(obj,divID)
{
	$('#'+divID).parent().children().hide();
	$(obj).parent().children().removeClass();
	$('#'+divID).slideDown();
	$(obj).addClass('current');	
}

function slideDown(divID)
{
	jQuery('div#'+divID).slideDown();
}
function slideUp(divID)
{
	jQuery('div#'+divID).slideUp();
}
function fadeIn(divID)
{
	jQuery('div#'+divID).fadeIn('fast');
}
function fadeOut(divID)
{
	jQuery('div#'+divID).fadeOut('fast');
}
function toggleDiv(divID)
{
	if(document.getElementById(divID) && document.getElementById(divID).style.display=='none')
	jQuery('div#'+divID).slideDown();
	else
	jQuery('div#'+divID).slideUp();
}
function toggleDivImg(divID)
{
	if(document.getElementById(divID) && document.getElementById(divID).style.display=='none')
	{
	
	jQuery('div#'+divID).slideDown();	 
	}	
	else
	{
	jQuery('div#'+divID).slideUp();	
	 
	}
}
function toggleDivLink(sender,divID)
{
	if(document.getElementById(divID) &&  document.getElementById(divID).style.display=='none')
	{
		jQuery('div#'+divID).slideDown();
		sender.getElementsByTagName('img')[0].src='images/TabL.png';
	}
	else
	{
		jQuery('div#'+divID).slideUp();
		sender.getElementsByTagName('img')[0].src='images/TabR.png';
	}
}
function onlyShow(divId)
{
	if(document.getElementById(divId))document.getElementById(divId).style.display="";	
}
function onlyHide(divId)
{
	if(document.getElementById(divId))document.getElementById(divId).style.display="none";	
}



function swapImg(imgID,imgSrc,imgID1,imgSrc1)
{
	if(document.getElementById(imgID).src==imgSrc)
	{
		document.getElementById(imgID).src=imgSrc;
		document.getElementById(imgID1).src=imgSrc1;
	}
	else
	{
		document.getElementById(imgID).src=imgSrc;
		document.getElementById(imgID1).src=imgSrc1;
	}
}


function swapImage(img_name,img_src) {
document[img_name].src=img_src;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function flsearcValidation(url)
{
	var stateCode_val   =$.trim($("#logo_stateCode_val").val());
	var zipCode_val   =$.trim($("#logo_zipCode_val").val());
	var zipEnteredVal = (numericsOnly(zipCode_val).length == 5);
	var redius_val = $.trim($("select#logo_redius_val").val());
	if(zipCode_val=='Enter Zip Code')
	{
	   $("#logo_zipCode_val").val('');
	}
	if(zipEnteredVal){
	  	$('#logo_instructionDiv').hide();
		$('#logo_instructionDiv').html('');
		//return true;
		window.location.href=url+'/'+zipCode_val+'/'+redius_val;		
  }else
	  if(stateCode_val!= "")
	  {
		  $('#logo_instructionDiv').hide();
			$('#logo_instructionDiv').html('');
			//return true;
			var arrdata=stateCode_val.split('-');		
			var newStr=arrdata[1].replace(" ","-");
			window.location.href=url+'/'+newStr;
		 
      }else {
		    $('#logo_instructionDiv').show();
		 	$('#logo_instructionDiv').html('Please select a state or enter a <br/>5-digit ZIP code.');
			return false; 
	  }         
}

function redirectLeftMenuPage(path){
	if(path != undefined && path != ''){
		window.location= path;
	}
}

function numericsOnly(string) {
	var array = string.split("");
	for (n = 0; n < array.length; n++)
		if (isNaN(parseInt(array[n])))
			array[n] = "";
	return array.join("");
}

function redirectPage(selectId){
	if($("#"+selectId).val()!= undefined && $("#"+selectId).val()!= ''){
		window.location= $("#"+selectId).val();
	}
}

//Expand, Collapse All
function expandCollapseAll(num,action){

	if(action == 'expand'){
		for(var e = 1 ; e < num ; e++){
			$('#a'+e).show();
		}
	}else if(action == 'collapse'){
		for(var e = 1 ; e < num ; e++){
			$('#a'+e).hide();
		}
	}
}

function openNewPopup(url)
{
window.open(url,'','menubar=0,status=0,toolbar=0,location=0,directories=0,resizable=1,scrollbars=1,height=600,width=750');	

}

function ShowVideo(url, dTitle, dWidth, dHeight, icon) {
	var iconPath="/media/images/";
	switch (icon)
	{
		case "error":
			iconPath=iconPath + "errorIcon.png";
			break;
		case "email":
			iconPath=iconPath + "emailIcon.png";
			break;
		case "video":
			iconPath=iconPath + "videoIcon.png";
			break;
	}	
	
	
	var $loading = $('<img src="/media/images/progress_bar.gif" alt="loading" class="loading">');
    $dialog = $('<div></div>');
    $dialog.append($loading.clone());
    $dialog.load(url + '#Content');
    $dialog.dialog({
        title: "<img class='absMiddle1' src ='"+ iconPath + "'/>&nbsp;" + dTitle,
        width: dWidth,
        height: dHeight,
       	zIndex: 9999,
        resizable: false,
        modal: true,
        overlay: { backgroundColor: "#000", opacity: 0.7 },        
        close: function (ev, ui) { $(this).remove();}
    });

    return false;
}


function ShowMessageDialog(msg,dTitle, icond,Height, dWidth) {
    
    var iconPath="/media/images/";
	switch (icon)
	{
		case "error":
			iconPath=iconPath + "errorIcon.png";
			break;
		case "email":
			iconPath=iconPath + "emailIcon.png";
			break;
		case "video":
			iconPath=iconPath + "videoIcon.png";
			break;
	}	
	$dialog = $('<div>'+ msg +'</div>');
    $dialog.dialog({
        title: "<img class='absMiddle1' src ='"+ iconPath + "'/>&nbsp;" + dTitle,
      	zIndex: 9999,
        resizable: false,
        modal: true,
        height: (dHeight)?dHeight:150,
        width: (dWidth)?dWidth:400,
        overlay: { backgroundColor: "#000", opacity: 0.7 },        
        close: function (ev, ui) { $(this).remove();}
    });

    return false;
    
}

function ShowHtmlMessageDialog(divId, dTitle, icon, dHeight, dWidth) {

    var iconPath = "/media/images/";
    
    
    switch (icon) {
        case "error":
            iconPath = iconPath + "errorIcon.png";
            break;
        case "email":
            iconPath = iconPath + "emailIcon.png";
            break;
        case "video":
            iconPath = iconPath + "videoIcon.png";
            break;
        default:
        	iconPath = iconPath + "transparentIcon2X24.png";
    }
    $dialog = $("#" + divId);
    $dialog.dialog({
        title: "<img class='absMiddle1' src ='" + iconPath + "'/> " + dTitle,
        zIndex: 9999,
        resizable: false,
        height: (dHeight)?dHeight:150,
        width: (dWidth)?dWidth:400,
        modal: true,
        overlay: { backgroundColor: "#000", opacity: 0.7}
        //close: function (ev, ui) { $(this).remove(); }
    });
    return false;
}

//Header Main Menu Javascript START//

	var set_state_dd = true;
	
	/* global variables - used across multiple nav functions */
	var navTimer;
	var stateFocused = false;
	var radiusFocused = false;
	var navs = ["scheduleAnAppointment", "findALocation" ];
	
	/* nav functions */
	function showScheduleAnAppointment() {
		showNav("scheduleAnAppointment");
	}
	
	function showFindALocation() {
		showNav("findALocation");
	}	
	
	/*function showmenu_4_div() {
		showNav("menu_4_div");
	}*/
	
	function startNavTimer() {
		if (!stateFocused && !radiusFocused) {
			resetNavTimer();
			navTimer = setTimeout("hideNav()", 1000);
		}
	}	
	function resetNavTimer() {
		clearTimeout(navTimer);
	}	
	function onSelectChange(object) {
		object.blur();
	}	
	function showNav(keyword) {
		for (x = 0; x < navs.length; x++) {			
			div = document.getElementById("nav_" + navs[x]);
			if (div) div.style.display = (keyword == navs[x]) ? "block" : "none";
			set_state_flag();
		}
	}	
	function hideNav() {		
		showNav("");
	}
	
	/* special case - state SELECT */
	function onStateFocus() {
		stateFocused = true;
	}
	
	function onStateBlur() {
		setTimeout("onStateBlurFinal();", 100);
	}
	
	function onStateBlurFinal() {
		stateFocused = false;
		radiusFocused = false;
	}
	
	/* special case - radius SELECT */
	function onRadiusFocus() {
		radiusFocused = true;
	}
	
	function onRadiusBlur() {
		setTimeout("onRadiusBlurFinal();", 100);
	}
	
	function onRadiusBlurFinal() {
		radiusFocused = false;
	}
	//other navigations//
	function set_state_fun(  ){
		set_state_dd = false;
		$("#nav_menu_4").addClass("topSelect");
		document.getElementById("nav_menu_4_div").style.display = 'block';
		setTimeout("set_state_flag();", 3000);	
		
	}
	function set_state_focus(){
		set_state_dd = false;
		$("#nav_menu_4").addClass("topSelect");
		document.getElementById("nav_menu_4_div").style.display = 'block';
	}
	
	function set_state_flag(){
		if(!set_state_dd){
			$("#nav_menu_4").removeClass("topSelect");
			document.getElementById("nav_menu_4_div").style.display = 'none';
		}
		set_state_dd = true;		
	}
	
	function setMenuItems(id){
		if( set_state_dd || id != 'nav_menu_4' ){
			document.getElementById("nav_scheduleAnAppointment").style.display = 'none'; 
			document.getElementById("nav_findALocation").style.display = 'none'; 
			for(var m = 1; m < 5 ; m++){
				document.getElementById("nav_menu_"+m+"_div").style.display = 'none'; 
				$("#nav_menu_"+m).removeClass("topSelect");
			}
		}
		set_state_dd = true;
		$("#"+id).addClass("topSelect");
		document.getElementById(id+"_div").style.display = 'block';		
	}

	function unsetMenuItems(id){		
		if( set_state_dd  || id != 'nav_menu_4' ){
			document.getElementById("nav_scheduleAnAppointment").style.display = 'none'; 
			document.getElementById("nav_findALocation").style.display = 'none'; 
			for(var m = 1; m < 5 ; m++){	
					document.getElementById("nav_menu_"+m+"_div").style.display = 'none'; 
					$("#nav_menu_"+m).removeClass("topSelect");
			}
		}		
	}

	function removeCookies(){
		$.cookie("AccountNumber", 0 , { path: '/', expires: -5 } );
		$.cookie("AppointmentNumber", 0 , { path: '/', expires: -5 } );
	}
	
//Header Main Menu Javascript END//
// Put the global varibale for email Validation as common place
var emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

function validSearchText(id){
	var search_q =  $("#"+id).val();
	if(search_q!='' && search_q!='Enter Keyword'){
		return true;
	}else{
		return false;
	}	
}
