// Son-Of-Sucker-Fish IE Hack
// -----------------------------------------------------------------

//  sfHover = function() {
//  var sfEls = document.getElementById("navbar").getElementsByTagName("LI");
//  for (var i=0; i < sfEls.length; i++) {
//    sfEls[i].onmouseover=function() {
//      this.className+=" sfhover";
//    }
//    sfEls[i].onmouseout=function() {
//      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//    }
// }
// }
// if (window.attachEvent) window.attachEvent("onload", sfHover);
 
 
 //------------------- for clearing and replacing text in form input fields and textareas -------------------//
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

function addBookmark(title,url) { 
 if (window.sidebar) { 
 window.sidebar.addPanel(title, url,""); 
 } else if( document.all ) { 
 window.external.AddFavorite( url, title); 
 } else if( window.opera && window.print ) { 
 return true; 
} 
} 

function FormSubmit(frm) {		// validate form1
	if (document.form1.name.value=='name') {
		alert('Please enter name');
		document.form1.name.focus()
		return false;
	}
	// check to see if email address field is of valid syntax
	substremail = document.form1.email.value.split("@")
	if (substremail.length > 1)
	{
		index = substremail[1].indexOf(".")
		if (index == -1)
 		{
		alert("Please enter a valid e-mail address")
		document.form1.email.focus()
		return false
		}
	}
	else {
		alert("Please enter a valid e-mail address")
		document.form1.email.focus()
		return false
	}
	if (document.form1.phone.value=='phone') {
		alert('Please enter phone number');
		document.form1.phone.focus()
		return false;
	}
//	document.form1.name.value = document.form1.fname.value + ' ' + document.form1.name.value
	return true;
}



// performs form verification, invoked from the onSubmit() event handler. 
// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for invalid fields.
// Writen by Scott Winterbourne June 20th, 2005.

function verify(fields)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var thePosition;
	var email;
   
	
    for(var i = 0; i < fields.length; i++) 
	{
        var formver = fields.elements[i];
				
		//thePosition=formver.name.indexOf("_");
		//if(-1==thePosition)
		//{
			//thePosition=formver.name.length;
		//}
			
//////////////////////////////////////////////////////////////////////////////////////////////////		
		//Checks for blank required fields
        if (formver.id== 'text') //checks for required fields
		{
            //check if the field is empty
            if ((formver.value == null) || (formver.value == "") || (formver.value == " name") || (formver.value == " phone") || (formver.value == "Name:")) 
			{
                empty_fields += "\n          " + formver.name
                continue;
            }
        }
		
		
//////////////////////////////////////////////////////////////////////////////////////////////////		
		//Phone
		
		if (formver.id == 'phone')
		{
			var error = "";
			var stripped = formver.value.replace(/[\(\)\.\-\ ]/g, '');    
	
			if (isNaN(parseInt(stripped))) 
			{
				errors = "The phone number contains invalid characters.\n";
				//fld.style.background = 'Yellow';
				continue;
			} else if (!(stripped.length == 10)) 
			{
				errors = "The phone number is the wrong length. Make sure you included an area code.\n";
				//fld.style.background = 'Yellow';
				continue;
			}
			//return error;
		}
		
////////////////////////////////////////////////////////////////////////////////////////////////////	
		// check to see if email address field is of valid syntax 
  
		if (formver.id == 'email')//Checks for an email field
		{
		  substremail = formver.value.split("@")   
		  if (substremail.length > 1)//makes sure the email address has an @ symbol   
		  {   
			  index = substremail[1].indexOf(".") 
				 
			   if (index == -1)   //makes sure there is a dot (.) in the address
			   { 
				
			   errors = "Please enter a valid e-mail address";               
			   continue; 
			   }   
		  } 
	  
		  else 
			{  
			   errors = "Please enter a valid e-mail address";     
			   continue;  
			}
		}
		if (formver.id == 'number')//checks for a number field
		 {	 
		 if (IsNumeric(formver.value)==false)//checks for a non numeric value
			{			
				errors = "Please enter a numeric value";
				continue;	
				
			}
			//if (formver.value.length != formverid[1])//checks to see if the value length matches the perameters
			//	{
			//	errors = "Please enter a 5 digit zip code";
			//	continue;
			//	}		
		 }
		 
		 
	} //end for loop


/////////////////////////////////////////////////////////////////////////////////////////////////////////	
    // if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    
	if (!empty_fields && !errors) return true;
    
	msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"
    
	if (empty_fields) 
	{
        msg += "The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    	msg += errors;
    	alert(msg);
    	return false;  
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// this function is called to check if a value is numberic
function IsNumeric(sText)
{

	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
}



function verifyPhoneEmail(theForm) {
var themessage = "You are required to complete the following fields: \n\n";
myOption = -1;
for (i=theForm.injured.length-1; i > -1; i--) 
{
	if (theForm.injured[i].checked) 
	{
		myOption = i; i = -1;
	}
}

if (myOption == -1) {
themessage = themessage + " -  Injured in the last 2 years? \n";
}
/*if(theForm.Name)
{
	if (theForm.Name.value=="") 
	{
		themessage = themessage + " -  Name \n";
	}
}
if(theForm.First_Name)
{
	if (theForm.First_Name.value=="")
	{
		themessage = themessage + " -  First Name \n";
	}
}
if(theForm.Phone){	
	if ((theForm.Phone.value==null)||(theForm.Phone.value==""))
	{
		themessage = themessage + " -  Phone \n";
	}	
}
if (theForm.Email.value=="")
{
	themessage = themessage + " -  Email \n";
}*/


//alert if fields are empty and cancel form submit
if (themessage != "You are required to complete the following fields: \n\n") {
alert(themessage);
return false;
}
return true;
}



/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function ValidatePhone(frm){
	var Phone=frm.phone
	
	/* if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	} */
	if (checkInternationalPhone(Phone.value)==false){
		alert("Invalid phone number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }



 
 
 /* videos on internal pages */
 function loadSWF(url){
  swfobject.embedSWF(url, "standalone", "344", "294", "7");
}


function embedCode(flvname)
{
	var embedwindow = window.open("", "EmbedCode", "status = 1, height = 250, width = 500, resizable = 0" );
	embedwindow.document.writeln('<p>Copy the code below and paste where you would like the video to appear</p>');
	embedwindow.document.writeln('<textarea readonly="true" rows="10" cols="55">');
	embedwindow.document.writeln('<embed src="http://www.killinofirm.com/videos/player.swf" '); 
	embedwindow.document.writeln('width="355" '); 
	embedwindow.document.writeln('height="265"'); 
	embedwindow.document.writeln('allowscriptaccess="always" '); 
	embedwindow.document.writeln('allowfullscreen="true" '); 
	embedwindow.document.writeln('flashvars="width=400&height=250&file=http://cmtm.s3.amazonaws.com/killinofirm/'+flvname+'"/>'); 
	embedwindow.document.writeln('</textarea>');
}




 
 
