/* Windows Media States */
var WMSTATE_UNDEFINED = 0; // Undefined Windows Media Player is in an undefined state. 
var WMSTATE_STOPPED = 1; //Stopped Playback of the current media item is stopped. 
var WMSTATE_PAUSED = 2; //Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. 
var WMSTATE_PLAYING = 3; //Playing The current media item is playing. 
var WMSTATE_SCANF = 4; //ScanForward The current media item is fast forwarding. 
var WMSTATE_SCANR = 5; //ScanReverse The current media item is fast rewinding. 
var WMSTATE_BUFFERING = 6; //Buffering The current media item is getting additional data from the server. 
var WMSTATE_WAITING = 7; //Waiting Connection is established, but the server is not sending data. Waiting for session to begin. 
var WMSTATE_COMPLETED = 8; //MediaEnded Media item has completed playback.  
var WMSTATE_TRANSITION = 9; //Transitioning Preparing new media item. 
var WMSTATE_READY = 10; //Ready Ready to begin playing.
var WMSTATE_RECONNECT = 11; //Reconnecting Reconnecting to stream. 
/* Windows Media States */

var rotateArray = new Array();
var rotateInterval = 10;

function getElementsByClassName(clsName)
{    
    var retVal = new Array();    
    var elements = document.getElementsByTagName("*");    
    for(var i = 0;i < elements.length;i++)
    {        
        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;
}

function SetRotateInterval(iRotateInterval)
{
    rotateInterval = iRotateInterval * 1000;
}

function AddRotateImage(strImagePath)
{
    rotateArray[rotateArray.length] = strImagePath;
}

function RotateImage(elName, showImageIdx)
{
    var imageEl = document.getElementById(elName);
    imageEl.src = rotateArray[showImageIdx];
    
    if ((showImageIdx + 1) < rotateArray.length)
    {
        setTimeout("RotateImage('" + elName + "', " + (showImageIdx + 1) + ")", rotateInterval);
    }
    else
    {
        setTimeout("RotateImage('" + elName + "', 0)", rotateInterval);
    }
}

function StartRotate(elName, showImageIdx)
{
    setTimeout("RotateImage('" + elName + "', " + showImageIdx + ")", rotateInterval);
}

function navigateToPage(sender)
{
    window.location.href = sender.value;
}

function performSearchActual(criteriaID)
{
    if (document.getElementById(criteriaID).value.trim() != "")
    {
        var pageStr = "/searchresults/default.cms?SearchValue=" + document.getElementById(criteriaID).value;
        window.location.href = pageStr;
    }
    else
    {
        alert("Please ensure you enter a search criteria.");
    }
}

function performSearch()
{
    performSearchActual("searchFieldValue");
}

function performSearch2()
{
    performSearchActual("searchValue");
}

function searchBoxEnter(sender)
{
    if (sender.value == "Search")
    {
        sender.value = "";
    }
}

function searchBoxLeave(sender)
{
    if (sender.value == "")
    {
        sender.value = "Search";
    }
}

function RemoveChildren(obj)
{
    while (obj.hasChildNodes())
    {
        obj.removeChild(obj.firstChild);
    }
}

function setInnerText(obj, newText)
{
    RemoveChildren(obj);
    var xNewContent = document.createTextNode(newText);
    obj.appendChild(xNewContent);
}

var popupTimeout;
function showContents(evt, sender)
{
    clearTimeout(popupTimeout);
    var xPopup = document.getElementById("oursolutionspopup");
    var oursolutionsboxPlus = document.getElementById("oursolutionsboxPlus");
    setInnerText(oursolutionsboxPlus, "-");
    xPopup.style.display = "block";
    
    //var xSource = getSourceElement(evt);
    //xPopup.style.left = xSource.clientLeft;
    
}

function clearContents(evt, sender)
{
    popupTimeout = setTimeout(performClearContents, 100);
}

function performClearContents()
{
    var xPopup = document.getElementById("oursolutionspopup");
    var oursolutionsboxPlus = document.getElementById("oursolutionsboxPlus");
    setInnerText(oursolutionsboxPlus, "+");
    xPopup.style.display = "none";
}

/*
String Extension Methods
*/

String.prototype.isAlpha = function() {
	return (this.match(/[A-Za-z]/g) ? true : false);
}

String.prototype.isNumeric = function() {
	return (this.match(/^\d+$/) ? true : false);
}

String.prototype.isAlphanumeric = function() {
	return (this.match(/[^A-Za-z0-9]/g) ? true : false);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/, "");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/, "");
}

String.prototype.isEmail = function() {
	var rx = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
	var matches = rx.exec(this);
	return (matches != null && this == matches[0]);
}

String.prototype.isURL = function() {
	var rx = new RegExp("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-\\+ ./?%:&=#\\[\\]]*)?");
	var matches = rx.exec(this);
	return (matches != null && this == matches[0]);
}

String.prototype.contains = function(t) {
	return this.indexOf(t) >= 0 ? true : false;
}

String.prototype.beginsWith = function(t, caseInsensitive) {
	if (caseInsensitive == false) {
		return (t == this.substring(0, t.length));
	}
	else {
		return (t.toLowerCase() == this.substring(0, t.length).toLowerCase());
	}
}

String.prototype.endsWith = function(t, caseInsensitive) {
	if (caseInsensitive == false) {
		return (t == this.substring(this.length - t.length));
	}
	else {
		return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase());
	}
}

function getSourceElement(evt)
{
    var targ;
    if (!evt) var evt = window.event;
    if (evt.target) targ = evt.target;
    else if (evt.srcElement) targ = evt.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
	    targ = targ.parentNode;	    
    return targ;
}