/*******************************
/*  Scripts for Stuart Lanes   *
*******************************/



function doConfirm(controlIn){
	if (confirm("Are you sure you wish to delete this entry?")){
        eval(controlIn);
        }
    }
    


		// COPY CONTACT DETAILS
        function copyContactDetails() 
        {
            document.CheckOut.sFirstName.value = document.CheckOut.FirstName.value;
            document.CheckOut.sLastName.value = document.CheckOut.LastName.value;
            document.CheckOut.sStreet.value = document.CheckOut.Street.value;
            document.CheckOut.sStreet2.value = document.CheckOut.Street2.value;
            document.CheckOut.sCity.value = document.CheckOut.City.value;
            document.CheckOut.sCountryList.selectedIndex = document.CheckOut.CountryList.selectedIndex;
            document.CheckOut.sState.value = document.CheckOut.State.value;
            document.CheckOut.sPostalCode.value = document.CheckOut.PostalCode.value;
            document.CheckOut.sTelephone.value = document.CheckOut.Telephone.value;
            if ( document.CheckOut.nyCountyList != null )
            {
				document.CheckOut.sNYCountyList.selectedIndex = document.CheckOut.nyCountyList.selectedIndex;
			}
			
			if ( document.CheckOut.CountyBox != null )
			{
				document.CheckOut.sCountyBox.value = document.CheckOut.CountyBox.value;
			}
                     
			if ( document.CheckOut.sPostalCode.value != '' )
			{
				document.CheckOut.submit();
			}
			
        }
        
       //add three scores together to make a series
       function AddScores()
       {
			var score1;
			var score2;
			var score3;
			if( document.EditBowler.Game1.value != "" )
			{
				score1 = parseInt(document.EditBowler.Game1.value);
				
			}
			else
			{
				score1 = 0;
				
			}
			if( document.EditBowler.Game2.value != "" )
			{
				score2 = parseInt(document.EditBowler.Game2.value);
				
			}
			else
			{
				score2 = 0;
				
			}
			if( document.EditBowler.Game3.value != "" )
			{
				score3 = parseInt(document.EditBowler.Game3.value);
				
			}
			else
			{
				score3 = 0;
				
			}
			//document.EditBowler.Game2.value = IsNumber( document.EditBowler.Game2.value );
			//document.EditBowler.Game3.value = IsNumber( document.EditBowler.Game3.value );
			/*if ( document.EditBowler.Game1.value == "" )
			{
				document.EditBowler.Game1.value = '0';
			}
			if ( document.EditBowler.Game2.value == "" )
			{
				document.EditBowler.Game2.value = '0';
			}
			if ( document.EditBowler.Game3.value == "" )
			{
				document.EditBowler.Game3.value = '0';
			}*/
			document.EditBowler.Series.value = score1 + score2 + score3;// parseInt( document.EditBowler.Game1.value ) + parseInt(document.EditBowler.Game2.value ) + parseInt( document.EditBowler.Game3.value );       
			//document.EditBowler.Series.value = score1 + score2 + score3;       
       } 
       
       /*function IsNumber(sText)
       {			
			var ValidChars = "0123456789";
  			var IsNumber=true;
   			var c = '';

   			for (i = 0; i < sText.length ; i++) 
      		{ 
      			c = sText.charAt(i); 
      			if (ValidChars.indexOf(c) == -1) 
         		{
         			IsNumber = false;
         			break;
         		}
      		}
   			return IsNumber;
		
       }*/
       
		function formatPhone(num)
		{ 
			var _return=false;
			/*
				* 7181238748 to 1(718)123-8748
			*/ 
			
			num= replaceSubstring(num, "-", "");
			num= replaceSubstring(num, " ", "");
			
			if(num.length != 10)
			{ 
				/* 
				* if user did not enter 10 digit phone number then simply print whatever user entered 
				*/ 
				_return=_OUTPUT?num:false;
			} 
			else
			{ 
				/* formating phone number here */ 
				_return="(";
				var ini = num.substring(0,3);
				_return+=ini+") ";
				var st = num.substring(3,6);
				_return+=st+"-";
				var end = num.substring(6,10);
				_return+=end;
			}
			return _return; 
		} 
	
	// REPLACE A SUBSTRING WITHIN A STRING
	function replaceSubstring(inputString, fromString, toString) 
	{
		// Goes through the inputString and replaces every occurrence of fromString with toString
		var temp = inputString;
		if (fromString == "") 
		{
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) 
		{ // If the string being replaced is not a part of the replacement string (normal situation)
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		else 
		{ // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";
			// Find a string that doesn't exist in the inputString to be used
			// as an "inbetween" string
			while (midString == "") 
			{
				for (var i=0; i < midStrings.length; i++) 
				{
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) 
					{
						midString = tempMidString;
						i = midStrings.length + 1;
					}
				}
			} // Keep on going until we build an "inbetween" string that doesn't exist
			// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
			while (temp.indexOf(fromString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			// Next, replace the "inbetween" string with the "toString"
			while (temp.indexOf(midString) != -1) 
			{
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} // Ends the check to see if the string being replaced is part of the replacement string or not
		return temp; // Send the updated string back to the user
	
	} // Ends the "replaceSubstring" function


	
