/*
	Write Flash Object Into Divs
		Example:
			<div id="services-menu"></div>
			<script language="javascript">writeFlash('services-menu','services-flash','services-menu.swf','239','127','window','#FFFFFF');</script>
		// PARAMETER NOTES: wmode and bgcolor are not required
*/
function writeFlash(holderId,id,file,width,height,wmode,bgcolor) {
	var objectvar="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' id='"+id+"' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+file+"' /><param name='loop' value='false' /><param name='menu' value='false' /><param name='quality' value='high' />";
	if(bgcolor!=null){
		objectvar+="<param name='bgcolor' value='"+bgcolor+"' />";
		var embedbgcolor="bgcolor='"+bgcolor+"'";
	}
	if(wmode==null){
		wmode='transparent';	
	}
	objectvar+="<param name='wmode' value='"+wmode+"' /><embed src='"+file+"' loop='false' menu='false' quality='high' wmode='"+wmode+"' "+embedbgcolor+" width='"+width+"' height='"+height+"' id='"+id+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	document.getElementById(holderId).innerHTML = objectvar;
} 

function get(elName){
	if(document.getElementById){
		if(temp=document.getElementById(elName)){
			return temp;
		}
		else{
			return false;
		}
	}
	else{
		throw new Error("This browser does not support the function document.getElementById()");
	}
}

String.prototype.trim=function(){
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};
String.prototype.reverse=function(){
	var newStr="";
	for (i=0;i<=this.length;i++){
		newStr = this.charAt(i) + newStr;
	}
	return newStr;
}
String.prototype.replaceAll=function(needle,replacement){
	string=this;
	while(string.indexOf(needle)!=-1){
		string=string.replace(needle," ");
	}
	return string;
}	
String.prototype.toProperCase=function(){
	return this.toLowerCase().replace(/^(.)|\s(.)/g,function($1){return $1.toUpperCase();});
};
document.getElementsByClassName=function(clsName,names){
	if(typeof(clsName)=="string"){
		var retVal=new Array();
		var elements=document.getElementsByTagName("*");
		for(i=0;i<elements.length;i++){
			if(names){
				if(elements[i].className.indexOf(" ")>=0){
					var classes=elements[i].className.split(" ");
					for(var j=0;j<classes.length;j++){
						if(classes[j]==clsName){
							retVal.push(elements[i].id);
						}
					}
				}
				else if(elements[i].className==clsName){
					retVal.push(elements[i].id);
				}
			}
			else{
				if(elements[i].className.indexOf(" ")>=0){
					var classes=elements[i].className.split(" ");
					for(var j= 0;j < classes.length;j++){
						if(classes[j]==clsName){
							retVal.push(elements[i]);
						}
					}
				}
				else if(elements[i].className==clsName){
					retVal.push(elements[i]);
				}	
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByClassName() must be passed a string representation of a class name");	
	}
};
document.getElementsByAttribute=function(attribute,names){
	if(typeof(attribute)=="string"){
		var retVal = new Array();
		var elements = document.getElementsByTagName("*");
		for(i = 0;i < elements.length;i++){
			if(names==false){
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i].id+":"+elements[i].getAttribute(attribute));
				}
			}
			else{
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i].id)
				}
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByAttribute() must be passed a string representation of an attribute name");	
	}
};
Array.prototype.inArray = function (value,caseSensitive){
	for (i=0;i<this.length;i++) {
		if(!caseSensitive){
			if(this[i].toLowerCase()==value.toLowerCase()){
				return true;
			}
		}
		else{
			if(this[i]==value){
				return true;
			}
		}
	}
	return false;
};
function enforceNumeric(field,e,next,len,allowed){
	if(next && len){
		tab=true;
	}
	char=e.charCode?e.charCode:e.keyCode;
	if (char!=8&&char!=46){
		if (char<48||char>57){
			if(allowed&&allowed.length>0){
				for(i=0;i<allowed.length;i++){
					if(allowed.inArray(char)){
						if(tab===true){
							autoTab();	
						}
						return true;
					}
					else{
						return false;	
					}
				}
			}
			else{
				return false;	
			}
		}
		else{
			if(tab===true){
				autoTab();	
			}
			return true;
		}
	}
	else if(char==46){
		if(field.value.indexOf(".")==-1){
			if(tab===true){
				autoTab();	
			}
			return true;
		}
		else{
			return false;	
		}
	}
	
	function autoTab(){
		if(field.value.length==(len-1)){
			next.focus();
		}
	}
}

function enforceNumericAT(field,e,allowed){
	char=e.charCode?e.charCode:e.keyCode;
	if (char!=8&&char!=46){
		if (char<48||char>57){
			if(allowed&&allowed.length>0){
				for(i=0;i<allowed.length;i++){
					if(!allowed.inArray(char)){
						field.value=field.value.substring(0,(field.value.length-1));	
					}
				}
			}
			else{
				field.value=field.value.substring(0,(field.value.length-1));	
			}
		}
	}
	else if(char==46){
		if(!field.value.indexOf(".")==-1){
			field.value=field.value.substring(0,(field.value.length-1));	
		}
	}
}

function autoTab(field,len,next){
	if (window.XMLHttpRequest || window.ActiveXObject){
		if(field.value.length==len){
			next.focus();
		}
	}
	else{
		if(field.value.length==len){
			next.focus();
		}
	}
}

function enforceAlphaNumeric(field,e){
	char=e.charCode?e.charCode:e.keyCode;
	if((char>=48&&char<=57)||(char>=65&&char<=90)||(char>=97&&char<=122)){
		return true;
	}
	else{
		return false;	
	}
}
function rgbToHex(value){
	if (typeof(value)!=="string") {
		return false;
	}
	var result=value.match(/^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*/);
	if(result==null){ 
		return value; 
	}
	var rgb = +result[1] << 16 | +result[2] << 8 | +result[3];
	var hex="";
	var digits="0123456789ABCDEF";
	while(rgb!=0){ 
		hex=digits.charAt(rgb&0xf); 
		rgb >>>= 4; 
	} 
	while(hex.length<6){ 
		hex='0'+hex; 
	}
	return "#" + hex;
}

function setUp(c,msoverClass,ext){
	var a=new Array();
	a=document.getElementsByClassName(c);
	for(i=0; i<a.length; i++){
		a[i]['onmouseover']=function(){this.className=msoverClass;};
		a[i]['onmouseout']=function(){this.className=c;};
		if(ext.length>0){
			a[i].onclick=function(){document.location.href=this.id+"."+ext;};	
		}
		else{
			a[i].onclick=function(){document.location.href=this.id+".php";};	
		}
	}
	
}

function ShowHideContent(diveffect)
{
	if(document.all){
		if(document.all[diveffect].style.display == 'none')
		{
			document.all[diveffect].style.display = 'block';
		}
		else
		{
			document.all[diveffect].style.display = 'none';
		}
	}
	else{
		if(document.getElementById(diveffect).style.display == 'none')
		{
			document.getElementById(diveffect).style.display = 'block';
		}
		else
		{
			document.getElementById(diveffect).style.display = 'none';
		}
	}
}

function checkDisclosure(action){
	if(!Get_Cookie("disclosureAgree")){
		disclosureAction = action;
		openDialogue('disclosure');
	} else {
		pageTracker._trackPageview(stripLocationHref(action));
		eval(action);
	}
}

function stripLocationHref(str){
	str = str.replace("location.href='","");
	str = str.replace("'","");
	return str;
}


// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	if(window.scrollY){
		$('overlay').style.top = window.scrollY+"px";
	}
	document.body.style.overflow = "hidden";
	$('overlay').show();
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	document.body.style.overflow = "";
	$('overlay').hide();
}

// Open the dialogue box and displays the overlay
function openDialogue(objId)
{
	showOverlay();
	if(window.scrollY){
		$(objId).style.top = (100 + window.scrollY)+"px";
	}
	$(objId).show();
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue(objId)
{
	hideOverlay();
	
	// Hide dialogue
	$(objId).hide();
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}



