/* Allows drop menu for IE 6 */

// CALLED FROM include_primary_nav.html

sfHover = function() {
	if($.browser.msie){
		var sfEls = document.getElementById("primary_nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				$('#middle').css("z-index","-1");
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				$('#middle').css("z-index","1");
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}// Drop menus inside menu headers

/***********************
	INCLUDE FUNCTIONS 
***********************/

function writePrimaryNav(){
	$.ajax({
		type: "GET",
		url: "../includes/include_primary_nav.html",
		success: function(html){
			$("#top").append(html);
			
		}
	});
}

function writeSecondaryNav(){
	loadAndWriteContent("include_secondary_nav.html","bottom");
}

function writeHeader(){
	$.ajax({
		type: "GET",
		url: "../includes/include_utility_nav.html",
		success: function(html){
			$("#top").append(html);
			writePrimaryNav();	
		}
	});
}

function writeFooter(){
	
	$.ajax({
		type: "GET",
		url: "../includes/include_secondary_nav.html",
		success: function(html){
			$("#bottom").append(html);
			completeFooter();	
		}
	});
	
}

function completeFooter(){
	
	$.ajax({
		type: "GET",
		url: "../includes/include_footer.html",
		success: function(html){
			$("#bottom").append(html);	
		}
	});
	
}

function writeMenuOptionsNav(subcat_id, item_id){
	$.ajax({
		type: "GET",
		url: "../includes/include_menu_options_nav.html",
		success: function(html){
			
			$("#right").append(html);
			toggleMenuOptionsNav(subcat_id, item_id);
			
		}
	});
}

function writeLocationNav(){
	$.ajax({
		type: "GET",
		url: "../includes/include_location_nav.html",
		success: function(html){
			$("#right").append(html);
		}
	});
}

function writeLocationTabNav(){
	$.ajax({
		type: "GET",
		url: "../includes/include_location_tab_nav.html",
		success: function(html){
			$("#tab_nav").append(html);
		}
	});
}

function writeFranchiseNav(){
	$.ajax({
		type: "GET",
		url: "../includes/include_franchise_nav.html",
		success: function(html){
			$("#right").append(html);
			
		}
	});
}

function writeFranchiseTabNav(){
	$.ajax({
		type: "GET",
		url: "../includes/include_franchise_tab_nav.html",
		success: function(html){
			$("#tab_nav").append(html);
			
		}
	});
}

function toggleMenuOptionsNav(subcat_id, item_id){
	$('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 13});
			
	$('#menu_options > ul').each(function(i){
		$(this).hide();
	});
	
	if(subcat_id){
		$('#cat_'+subcat_id).attr("className","expanded");
		$('#subcat_'+subcat_id).show();
	}
	
	if(item_id){
		$('#subcat_' + subcat_id + '_item_' + item_id + " > a").attr("className","on");
	}
}



function tabSelected(nSubTab_id, nBgPosition){
	document.getElementById(nSubTab_id).style.backgroundPosition = (nBgPosition);
}

/*added by kim ming*/
function ajax(obj,url,params)
{
	reinitializeeScroll = function(data){
		$('#pane_locator').html(data).jScrollPane({showArrows:true, scrollbarWidth: 13});
	}
	$.ajax({		
	   type: "POST",		   
	   url: url,
	   data: params,
	   success: reinitializeeScroll
	 });
}

function trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ")
	{ // Check for space at the start of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length-1, retValue.length);

	while (ch == " ")
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	return retValue;
}

function check_email(address) {
	//var emailPat = /^((\w|\.|\_)+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var emailPat = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	var matchArray = address.match(emailPat);
	if (matchArray == null)
		return false;
	else
		return true;
}