function keyCancel ()
{
	// Called from the <body> tag.
	// Cancels the enter key for
	// all textboxes to eliminate
	// improper button clicks.
	if (window.event.keyCode == 13) 
	{
		event.returnValue = false;
		event.cancel = true;
	}
}

function keyPress (btnToClickId)
{
	// Called from a textbox to submit
	// a form.  The Id of the button to
	// click is passed as a parameter.
	// This function fires before
	// the "keyCancel" function above,
	// making it possible to click a btn
	// from a textbox using the enter key.
	if (window.event.keyCode == 13) 
	{
		var btn = document.getElementById(btnToClickId);
		btn.click();
	}
}


function formatPhone(elementId)
{
  
    var x=document.getElementById(elementId).value;
	// strip all non-numbers out of szInput
	var rString = new String(stripNonNumbExcept(x, null))
	var len = rString.length;
	
	// phone number format from 3121234567 to (312)123-4567
	if (len == 10) 
	{
		rString = "(" + rString.substr(0,3) + ")" + rString.substr(3,3) + "-" + rString.substr(6,4);
	}
	// phone number format with from 13121234567 to (312)123-4567
	else if ((len == 11) && (rString.charAt(0) == "1"))
	{
		rString = "(" + rString.substr(1,3) + ")" + rString.substr(4,3) + "-" + rString.substr(7,4);
	}
	else if (len == 12)
	{
	    if((rString.charAt(0) == "(") && (rString.charAt(4) == ")"))
	    {
	          rString = rString.substr(0,5) + rString.substr(5,3) + "-" + rString.substr(8,4);
	    }
	    else if ((rString.charAt(3) == "-") && (rString.charAt(7) == "-"))
	    {
	        rString = "(" + rString.substr(0,3) + ")" + rString.substr(4,8);
	    }
	    else
	    {
	         //Send alert message
		    alert("Please enter phone number in format like (999)999-9999");
		    rString = ""; //This triggers focus
	    }
	}	
	else if ((len == 13) && (rString.charAt(0) == "("))
	{
	    if((rString.charAt(4) == ")") && (rString.charAt(8) == "-"))
	    {
	    
	    }
	    else
	    {
	        //Send alert message
		    alert("Please enter phone number in format like (999)999-9999");
		    rString = ""; //This triggers focus
	    }
	}
	else if(len == 0)
	{
	
	}
	else
	{	
		//Send alert message
		alert("Please enter phone number in format like (999)999-9999");
		rString = ""; //This triggers focus
	}
	document.getElementById(elementId).value = rString;

} // end formatPhone()



function stripNonNumbExcept(sValue, sArray)
{
	var sRtrn	= new String( sValue );
	var sREVals = new String( "[^0-9" );
	
	if (sArray)
	{
		for (x = 0; x < sArray.length; x++)
		{
			sREVals += sArray[x];
		}
	}
	sREVals += "]";

   //strip all invalid characters
   var re = new RegExp(sREVals ,"g");
   return sRtrn.replace( re, "" );
}


//////////////////////////////////////////////////////////////////////////////
//
// JavaScript Image Rollover Script - 
//
// This file provides for multiple image states including image rollover 
// functionality (onMouseover,onMouseout) along with persistent states (onClick). 
// To use, declare each of the images that will have multiple states using the 
// gdsObjImg function. This function takes four parameters: image tag name, url of
// the image's off state, url of the image's over state, and url of the image's
// on state. Insert each of the declared images into the imageArray array. In
// the HTML, make sure to include the 'NAME' attribute for the image tags that
// correspond to the declared images.
//
// Usage:
//  ( in the <HEAD> )
//  <script language="JavaScript" src="imageSwapping.js"></script>
//  <script language="JavaScript">
//  imgOne = new objImg('imageOneName','images/imageoneoff.gif','images/imageoneover.gif','images/imageoneon.gif');
//  imgTwo = new objImg('imageTwoName','images/imagetwooff.gif','images/imagetwoover.gif','images/imagetwoon.gif');
//
//  imageArray = new Array(imgOne,imgTwo);
//  </script>
//
//  ( in the <BODY> )
//  <a href="#" onClick="gdsSwapImg(imgOne,'on');"><img name="imageOneName" src="images/imageoneoff.gif"></a>
//
function gdsLoadImg(URL)
{
  if (document.images) 
  {
    newImg = new Image();
    newImg.src = URL;
    return newImg;
  }
}
function gdsObjImg(imgName,offImgURL,overImgURL,onImgURL)
{
  this.name = imgName
  this.state = "off";
  if (offImgURL) {this.offImg = gdsLoadImg(offImgURL);}
  if (overImgURL) {this.overImg = gdsLoadImg(overImgURL);}
  if (onImgURL) {this.onImg = gdsLoadImg(onImgURL);}
}
function gdsSwapImg(imgArray,imgName,newState)
{
  var thisState = imgArray[imgName].state;
  
  if(newState=="over" && thisState != "on" && imgArray[imgName].overImg)
  {
    document.images[imgName].src = imgArray[imgName].overImg.src;
    imgArray[imgName].state = "over";
  }
  if(newState=="off" && thisState != "on" && imgArray[imgName].offImg)
  {
    document.images[imgName].src = imgArray[imgName].offImg.src;
    imgArray[imgName].state = "off";
}
  
  if(newState=="on")
  {
    for(i=0;i<imgArray.length;i++)
    {
      thisImage = imgArray[i].name;
      thisState = imgArray[i].state;
      
      if(thisImage == imgName.name)
      {
        document.images[thisImage].src = imgArray[i].onImg.src;
        imgArray[i].state = "on";
      }
      else
      {
        document.images[thisImage].src = imgArray[i].offImg.src;
        imgArray[i].state = "off";
      }
    }
  }
}
function gdsMakeImgArray(n)
{
	this.length = n;
	for (var i = 1; i <= n; i++)
	{
		this[i] = 0
	}
	return this
}


// Want several separate toggle buttons inside a table to toggle their own multiple rows.
function toggle(thisname) {
    var trs = zxcByClassName(thisname);
    for (var z0 = 0; z0 < trs.length; z0++) {
        trs[z0].style.display = trs[z0].style.display == 'none' ? '' : 'none';
    }
}

function zxcByClassName(nme, el, tag) {
    if (typeof (el) == 'string') el = document.getElementById(el);
    el = el || document;
    for (var tag = tag || '*', reg = new RegExp('\\b' + nme + '\\b'), els = el.getElementsByTagName(tag), ary = [], z0 = 0; z0 < els.length; z0++) {
        if (reg.test(els[z0].className)) ary.push(els[z0]);
    }
    return ary;
}

//function onSilverlightError(sender, args) {

//    var appSource = "";
//    if (sender != null && sender != 0) {
//        appSource = sender.getHost().Source;
//    }
//    var errorType = args.ErrorType;
//    var iErrorCode = args.ErrorCode;

//    var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";

//    errMsg += "Code: " + iErrorCode + "    \n";
//    errMsg += "Category: " + errorType + "       \n";
//    errMsg += "Message: " + args.ErrorMessage + "     \n";

//    if (errorType == "ParserError") {
//        errMsg += "File: " + args.xamlFile + "     \n";
//        errMsg += "Line: " + args.lineNumber + "     \n";
//        errMsg += "Position: " + args.charPosition + "     \n";
//    }
//    else if (errorType == "RuntimeError") {
//        if (args.lineNumber != 0) {
//            errMsg += "Line: " + args.lineNumber + "     \n";
//            errMsg += "Position: " + args.charPosition + "     \n";
//        }
//        errMsg += "MethodName: " + args.methodName + "     \n";
//    }

//    throw new Error(errMsg);
//}