
// JavaScript Document

function gotoPage(pg) {
window.location = pg;
}

function openPage(pg) {
newWin = window.open(pg,"print");
if (typeof newWin != "object") {
	gotoPage(pg);
	}
}

function checkZip(zipVal) {
var zipRE = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
//zipVal = document.getElementById(obj).value;
isValid = zipRE.test(zipVal);

if (isValid == false) {
	alert("Zipcode is invalid, please try again.");
	return false;
	}
}

function deleteRecord(frm,nm,act) {
var agree = confirm("Are you sure you wish to permanently delete the following:\n\n\t" + nm + "?");
if (agree) {
	if (act != "") {
		window.location = act;
		}
	if (frm != "pageForm") {
		return true;
		}
	}
else
	{
	return false ;	
	}
}

function printResults() {
window.print();	
}

function previewPage(formName) {
populateRTField(formName);
document.forms[formName].target = "previewWindow";
document.getElementById(formName).action = "/process.cfm?task=main.pagePreview";
	document.getElementById(formName).submit();
}
function resetFormAction(formName) {
if (document.getElementById(formName).action != window.location) {
	document.getElementById(formName).target = "_self";
	document.getElementById(formName).action = window.location;
	}
}

function stripString(val) {
val = val.toLowerCase();
reSplit = /\W/;
splitStr = val.split(reSplit);
str = splitStr.join("-");
while (str.indexOf("--") != -1) {
	str = str.replace("--","-");
	}
return str.toLowerCase();
}

function createURL(val) {
retUrl = stripString(val);
return retUrl;
}

function previewURL(urlObj) {
var urlValue = $(urlObj).val();
if (urlValue != "") {
	$.Boxen.open(this, {urlAttribute: null, url:urlValue, modal:true});
	}
}

function updateMenu(val,idVal) {
url = "process.cfm?task=menus.update&sortOrder=" + val + "&menuId=" + idVal;
makeServerCall(url);
}
function deleteMenu(parentId,subId) {
url = "process.cfm?task=menus.delete&parentMenuItemId=" + parentId + "&subMenuItemId=" + subId;
makeServerCall(url);
}
function makeServerCall(url) {
$.ajax({
	type: "GET",
	url: url,
	success: function(){ return true }
	});
}
var returnData = "";
function getServerData(url,objId,type) {
$.get(
	url, 
	function(data) {
		$(objId).html(data);
	});
}


function checkCKEditorField() {
for ( instance in CKEDITOR.instances ) {
	fieldVal = CKEDITOR.instances[instance].getData();
	fieldVal = jQuery.trim(fieldVal.replace("<br />",""));
	if (fieldVal != "<br />" && fieldVal != "") {
		CKEDITOR.instances[instance].updateElement();
		}
	}
}

function populateRTField(formName) {
var fieldVal = "";
if (formName == "pageForm") {
	resetFormAction(formName);
	}
checkCKEditorField();
}


$(document).ready(function() {
//On Hover Over
function megaHoverOver(){
	//$(this).find('.sub').css('display:block');
   $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

       //$(this).find(".sub").css({'width' :biggestRow}); //Set width
	   $(this).find(".sub").css({'width' :'758px'}); //Set width
	   //$(this).find(".regular").css({'width' :'300px'}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
       $(this).find(".sub").css({'width' :'758px'}); //Set Width
	  // $(this).find(".regular").css({'width' :'300px'}); //Set Width
		// $(this).find(".sub").css({'width' : rowWidth}); //Set Width
    }
	
	//*************MY ADJUSTMENTS***********************
	$(this).find(".regular").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

	//*************END MY ADJUSTMENTS***********************
	
}


//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
  
  //*************MY ADJUSTMENTS***********************
  $(this).find(".regular").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
  //*************END MY ADJUSTMENTS***********************
  
}

//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 0, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 0, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul.nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul.nav li .regular").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul.nav li").hoverIntent(config); //Trigger Hover intent with custom configurations

//clear form fields
$("#searchTerm,#contactName,#contactEmail,#website,#comment,#emailAddress,#comments,#companyName,#contactTitle,#phone").focus(function(srcc) {
	if ($(this).val() == $(this)[0].title)  {
		$(this).val("");
		}
	});
$("#searchTerm,#contactName,#contactEmail,#website,#comment,#emailAddress,#comments,#companyName,#contactTitle,#phone").blur(function() {
	if ($(this).val() == "")  {
		$(this).val($(this)[0].title);
		}
	});
$("#searchTerm,#contactName,#contactEmail,#website,#comment,#emailAddress,#comments,#companyName,#contactTitle,#phone").blur(); 

});
