//Cross-browser compatability functions
var is=new function()
{ 	
	this.VER=navigator.appVersion;
	this.AGENT=navigator.userAgent;
	this.DOM=(document.getElementById)?1:0;
	this.IE4=(document.all&&!this.DOM)?1:0;
	this.IE5=(this.VER.indexOf("MSIE 5")>-1&&this.DOM)?1:0; 
	this.IE6=(this.VER.indexOf("MSIE 6")>-1&&this.DOM)?1:0;
	this.IE=(this.IE4||this.IE5||this.IE6)?1:0;	
	this.MAC=this.AGENT.indexOf("Mac")>-1;
	this.NS6=(document.getElementById&&!document.all)?1:0;
	this.NS4=(document.layers&&!this.DOM)?1:0;
	this.NS=(this.NS6||this.NS4)?1:0;
	this.OPERA=this.AGENT.indexOf("Opera")>-1;
	return this;
}
function getElement(id)
{
	if(is.DOM)
	{
		return document.getElementById(id);
	}
	else if(is.IE)
	{
		return eval("document.all."+id);
	}
	else if(is.NS)
	{
		return eval("document."+id);
	};
}
//Disable right click functions
function disableRightClick()
{
	var message="";	
	if(document.layers)
	{
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS;
	}
	else
	{
		document.onmouseup=clickNS;
		document.oncontextmenu=clickIE;
	};
};
function clickIE() //Needed for disableRightClick()
{
	var message="";
	if(is.IE)
	{
		(message);
		return false;
	};
};
function clickNS(e) //Needed for disableRightClick()
{
	var message="";
	if(is.NS)
	{
		if (e.which==2||e.which==3)
		{
			(message);
			return false;
		};
	};
};
function setStatus(msg)
{
	window.status=(msg!=undefined)?msg:"";
	return true;
}
function replace(string,text,by)
{
	var strLength=string.length,txtLength=text.length;
	if((strLength==0)||(txtLength==0))
	{
		return string;
	};
	var i=string.indexOf(text);
	if((!i)&&(text!=string.substring(0,txtLength)))
	{
		return string;
	};
	if(i==-1)
	{
		return string;
	};
	var newstr=string.substring(0,i)+by;
	if(i+txtLength<strLength)
	{
		newstr+=replace(string.substring(i+txtLength,strLength),text,by);
	};
	return newstr;
};
//String.prototype.replace=replace;
function trim(str)
{
	str=str.replace(/^\s+/,"");
	str=str.replace(/\s+$/,"");
	return str;
};
function chopString(str,len,app)
{
	if(str==undefined)
	{
		return;
	};
	len=(len==undefined)?str.length:len;
	app=(app==undefined)?"...":app;
	return (str.length<=len)?str:str.substr(0,(len-app.length))+app;
};
function popup(page,width,height,design,name)
{
	name=(name==undefined)?"":name;
	var left=(screen.width-width)/2;
	var top=(screen.height-height)/2;
	if(design==undefined||design==0)
	{
		design="status=0,scrollbars=0,directories=0,resizable=0,width="+width+",height="+height+",top="+top+",left="+left;
	}
	else if(trim(design)=="")
	{
		design="toolbar=1,scrollbars=1,location=1,statusbar=1,status=1,menubar=1,resizable=1";
	}
	else
	{
		design+=",height="+height+",width="+width+",top="+top+",left="+left;
	};
	var win=window.open(page,name,design);
	if(win.focus)
	{
		/*win.focus();*/
	};
	return win;
};
function setBorderStyle(obj)
{
	obj.style["border"]="1px solid #A5ACB2";
	obj.style["backgroundColor"]="#FFFFC6";
};
function restoreBorderStyle(obj)
{
	obj.style["border"]="1px solid #A5ACB2";
	obj.style["backgroundColor"]="#FFF";
};
function checkPhone(id)
{
	var phone=getElement(id)
	var digits=phone.value.replace(/[^0-9]/ig, '');
	if(!digits)
	{
		phone.value="";
		return;
	};
	if(digits.length==10)
	{
		phone.value="("+digits.substring(0,3)+") "+digits.substring(3,6)+'-'+digits.substring(6,10);
	}
	else
	{
		phone.value = digits;
	};
};
function ucfirst(str)
{
	if(str.length>0)
	{
		// Caps first letter of each word
		var rtn = "";
		var words = str.split(" ");

		for(var i=0;i<words.length;i++)
		{
			if(words[i]!="")
			{
				rtn+=words[i][0].toUpperCase()+words[i].substr(1,words[i].length)+" ";
			};
		};

		// Return the string, removing the last space
		return rtn.substr(0,rtn.length-1);
	};
	return "";
};
function verifyEmail(email)
{
	if(email.indexOf("@")==-1||email.indexOf(".")==-1||email.indexOf("@")>email.indexOf("."))
	{
		alert("Your e-mail address appears invalid.");
	};
	return email.toLowerCase();
};
function checkPhone(id)
{
	var phone=getElement(id)
	var digits=phone.value.replace(/[^0-9]/ig, '');
	if(!digits)
	{
		phone.value="";
		return;
	}
	if(digits.length==10)
	{
		phone.value="("+digits.substring(0,3)+") "+digits.substring(3,6)+'-'+digits.substring(6,10);
	}
	else
	{
		phone.value = digits;
	};
};
function swapImg(id,img)
{
	if(getElement(id)!=undefined)
	{
		getElement(id).src = img;
	};
};
function toggleBugReport(id)
{
	var expanded;

	// Close them all
	for(var i=1;i<=1000;i++)
	{
		if(getElement('bug_'+i)!=undefined)
		{
			// Is this the current expanded element?
			expanded = (getElement('bug_'+i).style.display != 'none') ? 'bug_'+i : expanded;

			// Hide it
			getElement('bug_'+i).style.display = 'none';
		}
	}

	// Expand it if its not the last one that was expanded
	if(getElement(id) != undefined)
	{
		getElement(id).style['display'] = (id == expanded) ? 'none' : 'block';
	};

	return false;
};