
/**
   FUNCTION RESULT: <a rel="external">link</a> will open link in new window.

   Why do this through Javascript instead of adding the attribute directly?
     1. The "target" attribute is depreciated in HTML 4.0, but not in the DOM 2.0 (and won't be in the forseeable future)
     2. Kevin Yank explains in his article: 

        One of the ideals that is expressed by the removal of 
		the target attribute from the Strict standards 
		is that (X)HTML should only be concerned with the 
		information that's displayed within a browser window.

        Consequently, as soon as we start talking about 
		opening new browser windows, the idealistic notion 
		is that we have exceeded the responsibilities of (X)HTML 
		and entered the world of client-side scripting (i.e. JavaScript).
		
		- "New-Window Links in a Standards-Compliant World"  ( http://www.sitepoint.com/article/standards-compliant-world )
*/		



function External_Links() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

window.onload = External_Links;



/**
   check DOCTYPE 
javascript:alert(document.compatMode);
*/


/**
   CLIENT_SIDE VALIDATION
   We don't trust this to actually validate the data, it just makes it faster for users to correct errors.
*/


function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
  result = true;
  }
  return result;
}



function validRequired(formField,fieldLabel)
{
  var result = true;
  
  if (formField.value == "")
  {
    alert('Please enter a ' + fieldLabel +'.');
    formField.focus();
    result = false;
  }
  
  return result;
}



function validEmail(formField,fieldLabel,required)
{
  var result = true;
  
  if (required && !validRequired(formField,fieldLabel))
    result = false;

  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert("Please enter a valid email address");
    formField.focus();
    result = false;
  }
   
  return result;

}




function validNum(formField,fieldLabel,required)
{
  var result = true;

  if (required && !validRequired(formField,fieldLabel))
    result = false;
  
   if (result)
   {
     var num = parseInt(formField.value,10);
     if (isNaN(num))
     {
       alert('Please enter a number for the "' + fieldLabel +'" field.');
      formField.focus();    
      result = false;
    }
  } 
  
  return result;
}



function validDate(formField,fieldLabel,required)
{
  var result = true;

  if (required && !validRequired(formField,fieldLabel))
    result = false;
  
   if (result)
   {
     var elems = formField.value.split("/");
     
     result = (elems.length == 3); // should be three components
     
     if (result)
     {
       var month = parseInt(elems[0],10);
        var day = parseInt(elems[1],10);
       var year = parseInt(elems[2],10);
      result = !isNaN(month) && (month > 0) && (month < 13) &&
            !isNaN(day) && (day > 0) && (day < 32) &&
            !isNaN(year) && (elems[2].length == 4);
     }
     
      if (!result)
     {
       alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
      formField.focus();    
    }
  } 
  
  return result;
}



function validateForm(theForm)
{
  // Customize these calls for your form

  // Start ------->
  if (!validRequired(theForm.name,"Name"))
    return false;
	
  if (!validEmail(theForm.email,"Email Address",true))
    return false;



/*
  if (!validDate(theForm.available,"Date Available",true))
    return false;

  if (!validRequired(theForm.phone,"Phone"))
    return false;

  if (!validRequired(theForm.address1,"Business Address"))
    return false;

  if (!validRequired(theForm.city,"City"))
    return false;

  if (!validNum(theForm.zip,"Zipcode",true))
    return false;

  // <--------- End
  */
  return true;
}





















