﻿//variable that will increment through the images
var step=1;
var imageCount;

function SlideShow()
{
	//if browser does not support the image object, exit.
	if (!document.images)
	{
	    return;
	}
	
	document.getElementById('SlideShowImg').src = eval("image" + step + ".src");
	
	if (step < imageCount)
	{
	    step++;
    }
	else
	{
	    step=1;
    }

	setTimeout("SlideShow()",5000);
}

function CenterNewPopupWindow(myPage,myName,w,h,features) 
{
	if(screen.width)
	{
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else
	{
		winl = 0;wint = 0;
	}

	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
				
	var windowSettings = 'height=' + h + ',';
	    windowSettings += 'width=' + w + ',';
	    windowSettings += 'top=' + wint + ',';
	    windowSettings += 'left=' + winl + ',';
	    windowSettings += features;
	    
	win = window.open(myPage,myName,windowSettings);
	
	win.window.focus()
}

function ClearContactUsForm()
{
    if (document.getElementById(row).style.display == "block")
    {
        displayRow(row, false);
    }
    else
    {
        displayRow(row, true);
    }
}

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

function FormatPhoneNumber(objTextBox)
{
	FormatNumber(objTextBox, '(###) ###-#### ');
}

function FormatNumber(num, format, shortformat)
{
	if(format==null)
	{
		// Choose the default format you prefer for the number. 
		//format = "#-(###) ###-#### ";		// Telephone w/ LD Prefix and Area Code
		format = "(###) ###-#### ";			// Telephone w/ Area Code
		//format = "###-###-####";			// Telephone w/ Area Code (dash seperated)
		//format = "###-##-####";			//Social Security Number
	}					
//---------------------------------------------------------------------------------------------------------------------
	if(shortformat==null)
	{
		// Choose the short format (without area code) you prefer. 
		//If you do not want multiple formats, leave it as "".

		//var shortformat = "###-#### ";
		var shortformat = "";
	}
	
//---------------------------------------------------------------------------------------------------------------------
//----------------------------------------This code can be used to format any number. ---------------------------------
//----------------------------------------Simply change the format to a number format ---------------------------------
//---------------------------------------- you prefer. It will ignore all characters  ---------------------------------
//----------------------------------------  except the #, where it will replace with  ---------------------------------
//----------------------------------------               user input.                  ---------------------------------
//---------------------------------------------------------------------------------------------------------------------

	var validchars = "0123456789";
	var tempstring = "";
	var returnstring = "";
	var extension = "";
	var tempstringpointer = 0;
	var returnstringpointer = 0;
	count = 0;

	// Get the length so we can go through and remove all non-numeric characters
	var length = num.value.length;
		
	// We are only concerned with the format of the phone number - extensions can be left alone.
	if (length > format.length)
	{
		length = format.length;
	};
	
	// scroll through what the user has typed
	for (var x=0; x<length; x++)
	{
		if (validchars.indexOf(num.value.charAt(x))!=-1)
		{
			tempstring = tempstring + num.value.charAt(x);
		};
	};
	
	// We should now have just the #'s - extract the extension if needed
	if (num.value.length > format.length)
	{
		length = format.length;
		extension = num.value.substr(format.length, (num.value.length-format.length));
	};
	
	// if we have fewer characters than our short format, we'll default to the short version.
	for (x=0; x<shortformat.length;x++)
	{
		if (shortformat.substr(x, 1)=="#")
		{
			count++;
		};
	}
	
	if (tempstring.length <= count)
	{
		format = shortformat;
	};
	
	//Loop through the format string and insert the numbers where we find a # sign
	for (x=0; x<format.length;x++)
	{
		if (tempstringpointer <= tempstring.length)
		{
			if (format.substr(x, 1)=="#")
			{
				returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
				tempstringpointer++;
			}else{
				returnstring = returnstring + format.substr(x, 1);
			}
		}
	}

	// We have gone through the entire format, let's add the extension back on.
	returnstring = returnstring + extension;
	
	//we're done - let's return our value to the field.
	num.value = returnstring;
}

function DisplayRow(rowShowHide, isHidden)
{
    if (isHidden)
    {
        document.getElementById(rowShowHide).style.display = 'none';
    }
    else
    {
        document.getElementById(rowShowHide).style.display = 'block';
    }
}

function MyAccountTogglePassword(radioButtonObj, targetRow)
{
    for (i=0;i<document.aspnetForm.ctl00$CPHMainBody$uxChangePasswordRbl.length;i++)
    {
        var radioValue;
        
        if (document.aspnetForm.ctl00$CPHMainBody$uxChangePasswordRbl[i].checked==true)
        {
            radioValue = document.aspnetForm.ctl00$CPHMainBody$uxChangePasswordRbl[i].value;
        }
    }
    
    if (radioValue == 1)
    {
        DisplayRow(targetRow, false);
    }
    else
    {
        DisplayRow(targetRow, true);
    }
    
}

function ForceNumeric(field)
{
	var inputStr = field.value.toString();
	var strLength = inputStr.length;
	var newStr = "";
	
	for (var i = 0; i < strLength; i++)  
	{
		var oneChar = inputStr.charAt(i);
		
		if (!( isNaN(oneChar) || oneChar == ' ') || oneChar == '.' || oneChar == '(' ||oneChar == ')' ||oneChar == '-')
		{  
			newStr = String(newStr) + String(field.value.substring(i,i+1));
		}
	}
	if (newStr != field.value)
	{
		field.value = newStr;
	}
}
function NumericKeyUp(fieldToEval,fieldToEvalLength,objToJumpTo)  
{
	ForceNumeric(fieldToEval);
	if ((fieldToEval.value.length == fieldToEvalLength)&&  
		(fieldToEval.value != prevValue) && (objToJumpTo != null)) { objToJumpTo.focus() }  
		prevValue = fieldToEval.value;
}