var listMenu = new FSMenu('listMenu', true, 'visibility', 'visible', 'hidden');

listMenu.cssLitClass = 'highlighted';

function animClipDown(ref, counter)
{
 var cP = Math.pow(Math.sin(Math.PI*counter/200),0.75);
 ref.style.clip = (counter==100 ?
  ((window.opera || navigator.userAgent.indexOf('KHTML') > -1) ? '':
   'rect(auto, auto, auto, auto)') :
   'rect(0, ' + ref.offsetWidth + 'px, '+(ref.offsetHeight*cP)+'px, 0)');
};

function animFade(ref, counter)
{
    var f = ref.filters, done = (counter==100);
    if (f)
    {
        if (!done && ref.style.filter.indexOf("alpha") == -1)
            ref.style.filter += ' alpha(opacity=' + counter + ')';
        else if (f.length && f.alpha) with (f.alpha)
        {
            if (done) enabled = false;
            else { opacity = counter; enabled=true }
        }
    }
    else
        ref.style.opacity = ref.style.MozOpacity = counter/100.1;
};

listMenu.animations[listMenu.animations.length] = animFade;
listMenu.animations[listMenu.animations.length] = animClipDown;
listMenu.animSpeed = 50;

var arrow = null;
if (document.createElement && document.documentElement)
{
    arrow = document.createElement('span');
    arrow.appendChild(document.createTextNode('>'));
    arrow.className = 'subind';
}

addEvent(window, 'load', new Function('listMenu.activateMenu("listMenuRoot", arrow)'));

function doMenu(obj,state,hasChild)
{
	var arMenuBtn = [null,'home','courses','services','faq','contact','locations','instructors'];
	var menuHdrId = obj.className.substring(obj.className.length-1);
	
	if (state)
	{
		obj.style.background = 'url('+JSPATH+'images/'+JSNAME+'/bttn_' + arMenuBtn[menuHdrId] + '_up.gif) no-repeat top left';
		//if (! obj.src.match(/_up\.gif$/i))
		//	obj.src = obj.src.replace(/\.gif$/i,'_up.gif');		
	}
	else
	{
		obj.style.background = 'url('+JSPATH+'images/'+JSNAME+'/bttn_' + arMenuBtn[menuHdrId] + '.gif) no-repeat top left';			
		//obj.src = obj.src.replace(/_up\.gif$/i,'.gif');
	}	
}

function validateContactForm()
{
    var arFlds = [['txtName','name',true],['txtEmail','email',true],['txtPhone','phone',true],
				  ['txtRequest','textarea',true]];

     return validateForm(arFlds);

}

function validateEmail(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}
function validatePhoneNumber(phoneNumber)
{
  var reg = /\d{3}-\d{3}-\d{4}$/;
  return reg.test(phoneNumber);
}

function validateLoginPage()
{
    var arFlds = [['usr','username',true],['pass','password',true]];

     return validateForm(arFlds);
}

function valBlogCommentEntry()
{
    var arFlds = [['txtName','name',true],['txtEmail','email',true],['txtWebsite','link',false],
				  ['txtComment','textarea',true]];

   return validateForm(arFlds);
}
function validateForm(arFlds)
{
    var returnType = true;    
    ErrorPopups = new Array(); // reset error flags

    for (var i = 0; i < arFlds.length; i++)
    {
        if (! valFields(arFlds[i]))
            returnType = false;
    }
    
    if (!returnType)
        initErrorDialogs();
    else
		doNoInjection();

    return returnType;
}

/**
 * Append the class number to the links, this is so the package select page can work.
 */
function appendVariablesToAllLinks(pkgName)
{
	for(i=0; i < document.links.length; i++)
	{	
		var thisLink = document.links[i];
		var thisLinkHref =  new String(thisLink.href);
		if(thisLinkHref.indexOf("pkgsel.php") != -1)	
		{
			thisLink.href = thisLink.href + "?pkg=" + pkgName;
			
		}
	}

}

//this was used before packages.php became a part of the real via include
//perpetuate the get query string in the packages class
//this will allow the CMS to add links, and then the redirect to packages page will work.
function appendQueryStringToAllLinks()
{
	var qs = querySt();
	for(i=0; i < document.links.length; i++)
	{	
		var thisLink = document.links[i];
		var thisLinkHref =  new String(thisLink.href);
		if(thisLinkHref.indexOf("pkgsel.php") != -1)	
		{
			thisLink.href = thisLink.href + "?" + qs;
		}
	}
}
/**
 * Get the query string (GET) and parse into usable form.
 * Found function from the net.
 */
function querySt() {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	var queryString = "";
	for (i=0;i<gy.length;i++) 
	{
		ft = new String(gy[i].split("="));
		ft = ft.replace(",", "=");
		queryString = queryString + ft + "&";					
	}
	queryString = new String(queryString);
	queryString = queryString.substring(0, queryString.lastIndexOf("&"));
	return queryString;
}
//page functions
function setFormAction(actionName)
{
    //set the correct action
   var hiddenAction = document.getElementById("FORM_ACTION");
   
   hiddenAction.value = actionName;   
}

function courseSearchSelectChange()
{
    setFormAction('CourseCategoryChoice');
    var thisForm = document.forms[0];
    thisForm.submit();
}

function replyTo(id,name)
{
	docObj('hdnReplyToId').value = id;
	
	if (0 == id)
		name = CurrentPostTitle;
	
	docObj('h3Reply').innerHTML = 'Reply to "' + name + '"';
	
	if (window.location.href.indexOf('#') != -1)
	{
		var arRefParts = window.location.href.split('#');
		window.location = arRefParts[0]+'#reply';
	}
	else
		window.location=window.location+'#reply';
}
