/*--------------------------------------------------------------------------
 *
 *  JavaScript Functions
 *
/*--------------------------------------------------------------------------*/

function init(){
	
}

function fnValidateForm(voWhichForm) {
	var lsRequired = voWhichForm._required.value;
	var laRequired = lsRequired.split(",");
	var lsMsg="";
	var lnWhichone = -1;
	var lsMsg="";
	var lnWhichone = -1;
	var i = 1;
	for (a=0; a<voWhichForm.elements.length; a++) {
		if (lsRequired.indexOf(voWhichForm.elements[a].name) != -1) {
			if(voWhichForm.elements[a].value==""){
				if ((lnWhichone == -1 )&&(lsMsg=="")) {
					lnWhichone = a;
				} // end if
				if (lsMsg==""){
					lsMsg = "Oops. You seem to have left out some required information.\nPlease fill in the field(s):\n";
				}
				lsMsg += "   " + (i++) + ".  " + replaceCharacters(voWhichForm.elements[a].name,'_',' ')  + "\n";
				//break;
			} // end if
		} // end if
	} // end for
	if (lsMsg == "") {
		return;
	}
	voWhichForm.elements[lnWhichone].focus();
	alert(lsMsg);
	return false;
}

function  fnValidateNumeric( vsString ) {
	var loRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	return loRegExp.test(vsString);
}

function replaceCharacters( vsSource, vsMatchPattern, vsReplaceString ) {
/************************************************
DESCRIPTION: Removes characters from a source string
  based upon matches of the supplied pattern and replaces with something else.

PARAMETERS:
  vsSource - source string
  vsMatchPattern - pattern to replace
  strReplaceString - replacement characters

RETURNS: String modified with characters matching search pattern removed

USAGE:  strNoSpaces = replaceCharacters( ' sfdf  dfd', '\s*', '')
*************************************************/
 var loRegExp =  new RegExp( vsMatchPattern, 'gi' );

 //replace passed pattern matches with replacement string
  return vsSource.replace(loRegExp,vsReplaceString);
}

function fnFillSelect(vsFormName, vsSelectName, vaValues, vaOptions) {
	var x = vaOptions;
	var y = vaValues;
	for(var i=0;i<x.length;i++) {
		fnAddOption(vsFormName,vsSelectName,x[i],y[i]);
	}
}

function fnAddOption(p_FormName,p_SelectName,p_OptionText,p_OptionValue){
	
	document.forms[p_FormName].elements[p_SelectName].options[document.forms[p_FormName].elements[p_SelectName].length] = new Option(p_OptionText,p_OptionValue);
}


function fnJumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}


// This function inserts the necessary scripts for a module to work
// Available modules
//	lightbox
//	prototype
//	calendar
function fnInsertScript(vaModules, vsPathToRoot) {
	for (var i=0;i<vaModules.length;i++){
		switch (vaModules[i]) {
		   case 'lightbox' : 
		   	fnLoadCss(vsPathToRoot+"_css/lightbox/lightbox.css");
		   	fnLoadScript(vsPathToRoot+"_js/lightbox/showroom.js");
		   	fnLoadScript(vsPathToRoot+"_js/prototype.js");
		   	fnLoadScript(vsPathToRoot+"_js/lightbox/scriptaculous.js?load=effects");
		   	fnLoadScript(vsPathToRoot+"_js/lightbox.js");
		   	break;
		   case 'prototype' : 
		   	fnLoadScript(vsPathToRoot+"_js/prototype.js");
		   	break;
		   case 'calendar' : 
		   	fnLoadCss(vsPathToRoot+"_css/calendar/xc2_default.css");
		   	fnLoadScript(vsPathToRoot+"_js/calendar/xc2_default.js");
		   	fnLoadScript(vsPathToRoot+"_js/calendar/script/xc2_inpage.js");
		   	break;
		} // end switch
	}// end for
}







function fnLoadScript(vsUrl) {
	document.write('<scr'+'ipt type="text\/javascript" src="'+vsUrl+'"><\/scr'+'ipt>');
}

function fnLoadCss(vsUrl) {
	document.write('<li'+'nk rel="stylesheet" href="'+vsUrl+'" type="text\/css" media="screen" \/>');
}

function embedFlash(ls_filename,ls_objectid,ls_flashvars,w,h) {

document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+w+'" HEIGHT="'+h+'" id="'+ls_objectid+'" ALIGN="">');
	document.write('<PARAM NAME=movie VALUE="'+ls_filename+'"> <PARAM NAME=FlashVars VALUE="'+ls_flashvars+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>');
	document.write('<EMBED src="'+ls_filename+'" FlashVars="'+ls_flashvars+'" quality=high bgcolor=#FFFFFF  WIDTH="'+w+'" HEIGHT="'+h+'" NAME="'+ls_objectid+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
	document.write('</OBJECT>');
}
