//Verisign SSL Cert Verification
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin"; }

function checkKeys(type, value)
{		
	switch (type.toLowerCase())
	{   
		//Prevents enter key from submitting
		case 'supressenter' :
			       
			if (value == 13)
				return false;     
			
			break;			
	}
		
}

//Ensures a ZipCode has been eneterd on Default.asp
function IsZipPresent(sZip, iRadius)
{
	
	if (sZip == "" && iRadius == 0){
		alert( 'Please enter a zipcode and select a radius');
		return false;
		}
		
	if (sZip == ""){
		alert( 'Please enter a zipcode');
		return false;
		}
		
	if (iRadius == 0){
		alert( 'Please select a radius');
		return false;
	}
		//return true;	
}

function toggleVisibility(id, bVisible)
{
	
	var d = this.document;
	
	if (bVisible)
		d.getElementById(id).style.visibility = 'visible';
	else
		d.getElementById(id).style.visibility = 'hidden';

}

function toggleDisplay(id, bDisplay)
{
	var d = this.document;
	
	if (bDisplay)
		d.getElementById(id).style.display = 'inline';
	else
		d.getElementById(id).style.visibility = 'none';

}

// Changes the first letter of each word to a cap
 function formatCaps(value) 
	{ 
		var formattedValue = "";
		var spaceLocations = new Array();
		var counter = 0;
		var temp = "";
		var index = 0;
		var checkParen = "";
		
		//Find locations of spaces
		var valueLength = value.length;
				
		for (i = 0; i != valueLength; i++)
		{			
			if (value.charAt(i) == " ")
			{
				if (value.charAt(i + 1) == "(")
					spaceLocations[counter] = i + 1;
				else
					spaceLocations[counter] = i;
				
				counter++;
			}				
				
		}// End spaceLocation For		
		
		//If there is more than one word, change the first letter to a cap
		if (spaceLocations.length != 0)	
		{	
			
			for (i = 0; i != spaceLocations.length + 1; i++)
			{
				
				if (i != 0 && i != spaceLocations.length)
				{
					index = spaceLocations[i-1] + 1;
					temp = value.slice(index, spaceLocations[i]);
				}
				
				else if (i == spaceLocations.length)
				{
					index = spaceLocations[i-1] + 1
					temp = value.slice(index, valueLength);
				}	
				
				else
					temp = value.slice(i, spaceLocations[i]);
													
				if (isNaN(temp) == true)
				{
					if (temp == "of" || temp == "to" || temp == "the" || temp == "and" || temp == "a" || temp == "it" || temp == "is")
					{
						lowerValue = (temp.substring(1,temp.length).toLowerCase());
						upperValue = (temp.charAt(0).toLowerCase());
					}
					
					else
					{
						lowerValue = (temp.substring(1,temp.length).toLowerCase());
						upperValue = (temp.charAt(0).toUpperCase());
					}					
					// Check for parenthesis
					if ( i < spaceLocations.length && i > 0)
						checkParen = value.substring(spaceLocations[i-1], spaceLocations[i-1] + 1);
										
					if (checkParen == "(")
					{
						formattedValue = formattedValue + checkParen + upperValue + lowerValue;
						checkParen = "";	
					}
					else
						formattedValue = formattedValue + upperValue + lowerValue;
									
					if (formattedValue.charAt(formattedValue.length-1) != " "  && i  !=  spaceLocations.length)
						formattedValue = formattedValue + " ";
				}
				
				//IsNAN Else	
				else
				{
					formattedValue = formattedValue + temp;
					
					if (formattedValue.charAt(formattedValue.length-1) != " "  && i  !=  spaceLocations.length)
						formattedValue = formattedValue + " ";
				}			
				
			}//End For
		
		}//End if
		
		//Else if there is only one word
		else
		{
			temp = value;
			lowerValue = (temp.substring(1,temp.length).toLowerCase());
			upperValue = (temp.charAt(0).toUpperCase());
			
			formattedValue = upperValue + lowerValue;
		}
	
	return formattedValue; 
	}
	
//Format Zip Codes for US or Canada
function formatZip(zip)
{
	var fChar;
	var left;
	var right;
	
	//remove spaces
	zip = zip.replace(/ /g, "");
	
	fChar = zip.substr(0, 1)
	
	if (isNaN(fChar) == true)//Canadian Zip
	{
		//Format Zip properly
		if (zip.length != 7)
		{
			left = zip.substr(0, 3);
			right = zip.substr(3, 3);			
								
			zip = left + ' ' + right;
			
			if (zip.length != 7)
				zip = "";						
		}
	}
				
	else //US Zip
	{
		zip = zip.substr(0, 5)
		if (zip.length != 5)
			zip = "";						
	}
	
	zip = zip.toUpperCase();					
	return zip;
}

//Remove spaces
function removeSpaces(value)
{
	value = value.replace(/ /g, "");
	value = value.replace(/-/g, "");
	//alert(value);
	return value;
}

//Verify proper suffix, not Mr., Mrs. etc
function verifySuffix(value)
{

	if ( value.charAt(0) == "M" || value.charAt(0) == "m" )
		value = "";
	
	return value;

}

function removeChars(value, type)
{	
	var left;
	var right;
	var index;	
	
	switch(type)
	{
		case 'Phone':
			value = value.replace(/[^0-9]/g,"");
			left  = value.substr(0, 3);
			right = value.substr(3, 4);			
			value = left + "-" + right;
			
			if (value.length != 8)
				value = "";
			break;
		
		case 'AreaCode':			
			value = value.replace(/[^0-9]/g,"");
			if (value.length != 3)
				value = "";
			break;
		
		case 'Currency':
			index = value.indexOf(".")
			
			if (index != -1)
				value = value.substring(0,index);			
			
			value = value.replace(/[^0-9]/g,"");			
			break;
	}
	
	return value;	
}

//Delete Confirmation
function verifyDelete()
{
	return confirm("Are you sure you want to delete this item?");				
}

//Remove Illegal Filename Characters
function removeIllegalFilenameChars(sValue)
{
	return sValue.replace(/['|!|@|#|$|%|^|&|*|()|//]/g,"");	
}