// JavaScript Document
/**
 * 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 ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function CheckAttendeeForm()
{
	if (document.getElementById('Name1').value=='')
	{
		alert('Please Enter an Attendee Name!');
		document.getElementById('Name1').focus();
		document.getElementById('Name1').style.backgroundColor='#FF9';
		return false;
	}


	return true;
}

function CheckRegForm()
{
	var emailID=document.getElementById('email')

	
	if (document.getElementById('first_name').value=='')
	{
		alert('Please Enter a First Name!');
		document.getElementById('first_name').focus();
		document.getElementById('first_name').style.backgroundColor='#FF9';
		return false;
	}
	
	if (document.getElementById('last_name').value=='')
	{
		alert('Please Enter a Last Name!');
		document.getElementById('last_name').focus();
		document.getElementById('last_name').style.backgroundColor='#FF9';
		return false;
	}
	
	if (document.getElementById('night_phone_a').value=='')
	{
		alert('Please Enter a Area Code!');
		document.getElementById('night_phone_a').focus();
		document.getElementById('night_phone_a').style.backgroundColor='#FF9';
		return false;
	}

	if (document.getElementById('night_phone_b').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_b').focus();
		document.getElementById('night_phone_b').style.backgroundColor='#FF9';
		return false;
	}

	if (document.getElementById('night_phone_c').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_c').focus();
		document.getElementById('night_phone_c').style.backgroundColor='#FF9';
		return false;
	}

	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email Address");
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}


	return true;
}

function CheckRegistrationForm()
{
	var emailID=document.getElementById('email')

	if (document.getElementById('first_name').value=='')
	{
		alert('Please Enter a First Name!');
		document.getElementById('first_name').focus();
		document.getElementById('first_name').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('last_name').value=='')
	{
		alert('Please Enter a Last Name!');
		document.getElementById('last_name').focus();
		document.getElementById('last_name').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_a').value=='')
	{
		alert('Please Enter an Area Code!');
		document.getElementById('night_phone_a').focus();
		document.getElementById('night_phone_a').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_b').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_b').focus();
		document.getElementById('night_phone_b').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_c').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_c').focus();
		document.getElementById('night_phone_c').style.backgroundColor='#FF9';
		return false;
	}

	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email Address");
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}

	return true;
}

function CheckRegistrationFormGolf()
{
	var emailID=document.getElementById('email')

	if (document.getElementById('first_name').value=='')
	{
		alert('Please Enter a First Name!');
		document.getElementById('first_name').focus();
		document.getElementById('first_name').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('last_name').value=='')
	{
		alert('Please Enter a Last Name!');
		document.getElementById('last_name').focus();
		document.getElementById('last_name').style.backgroundColor='#FF9';
		return false;
	}


		if (document.getElementById('night_phone_a').value=='')
	{
		alert('Please Enter an Area Code!');
		document.getElementById('night_phone_a').focus();
		document.getElementById('night_phone_a').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_b').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_b').focus();
		document.getElementById('night_phone_b').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_c').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_c').focus();
		document.getElementById('night_phone_c').style.backgroundColor='#FF9';
		return false;
	}

	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email Address");
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}


	return true;
}

function CheckRegistrationForm2()
{
	var emailID=document.getElementById('email')
	
		if (document.getElementById('os2').value=='')
	{
		alert('Please Enter a Type of Business Offered!');
		document.getElementById('os2').focus();
		document.getElementById('os2').style.backgroundColor='#FF9';
		return false;
	}	
	
	if (document.getElementById('os3').value=='')
	{
		alert('Please Enter a Business Type!');
		document.getElementById('os3').focus();
		document.getElementById('os3').style.backgroundColor='#FF9';
		return false;
	}
	if (document.getElementById('os4').value=='')
	{
		alert('Please Enter a Company Name!');
		document.getElementById('os4').focus();
		document.getElementById('os4').style.backgroundColor='#FF9';
		return false;
	}


	if (document.getElementById('first_name').value=='')
	{
		alert('Please Enter a First Name!');
		document.getElementById('first_name').focus();
		document.getElementById('first_name').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('last_name').value=='')
	{
		alert('Please Enter a Last Name!');
		document.getElementById('last_name').focus();
		document.getElementById('last_name').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('address1').value=='')
	{
		alert('Please Enter an Address!');
		document.getElementById('address1').focus();
		document.getElementById('address1').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('city').value=='')
	{
		alert('Please Enter a City!');
		document.getElementById('city').focus();
		document.getElementById('city').style.backgroundColor='#FF9';
		return false;
	}
	
		if (document.getElementById('state').value=='')
	{
		alert('Please Enter a State!');
		document.getElementById('state').focus();
		document.getElementById('state').style.backgroundColor='#FF9';
		return false;
	}
	
			if (document.getElementById('zip').value=='')
	{
		alert('Please Enter a Zip Code!');
		document.getElementById('zip').focus();
		document.getElementById('zip').style.backgroundColor='#FF9';
		return false;
	}


		if (document.getElementById('night_phone_a').value=='')
	{
		alert('Please Enter an Area Code!');
		document.getElementById('night_phone_a').focus();
		document.getElementById('night_phone_a').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_b').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_b').focus();
		document.getElementById('night_phone_b').style.backgroundColor='#FF9';
		return false;
	}

		if (document.getElementById('night_phone_c').value=='')
	{
		alert('Please Enter a Full Phone Number!');
		document.getElementById('night_phone_c').focus();
		document.getElementById('night_phone_c').style.backgroundColor='#FF9';
		return false;
	}

	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please Enter your Email Address");
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		emailID.style.backgroundColor='#FF9';
		return false;
	}


	document.getElementById('os4').value = document.getElementById('os4').value + " - Phone# " + document.getElementById('night_phone_a').value+document.getElementById('night_phone_b').value+document.getElementById('night_phone_c').value;
	return true;
}






//////////////////////////////////////////////////////////////////////////////////////////////////////

//GOOGLE API MAP CODE

var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {
  if (GBrowserIsCompatible()) {      
    map = new GMap2(document.getElementById("map_canvas"));
    gdir = new GDirections(map, document.getElementById("directions"));
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());  

    setDirections("Phoenix", "7520 East Adobe Drive, Scottsdale, AZ 85255-4804", "en_US");
  }
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
}

function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
     
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
    
   else alert("An unknown error occurred.");
   
}

function onGDirectionsLoad(){ 
  // Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...
}
//END GOOGLE API MAP CODE

//////////////////////////////////////////////////////////////////////////////////////////////////////

//PopUp Window 1
function PopUpAction(PassedLink) {
	window.open(PassedLink,"LogIn", "width=400, height=300, status=no, scrollbars=no, resizable=no, directories=no, location=no, menubar=no, toolbar=no");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

//POPUP Window 2
	function myOpen(page,width,height) {
		if (navigator.appName == 'Netscape') {
			adjWidth = width+10;
			adjHeight = height+10;
		}
		else {
			adjWidth = width;
			adjHeight = height;
		}
	   
		window.open(page,'windowName','width=' + adjWidth + ',height=' + adjHeight + ',toolbar=no,location=no,directories=no,resizable=yes,status=yes,menubar=yes,scrollbars=yes');
}
//END POPUP

//////////////////////////////////////////////////////////////////////////////////////////////////////

//CONFIRM DELETE
function confirmDelete(passedLink)
{
	if(confirm('Are you sure you want to delete this record'))
	{
		window.location.href = (passedLink);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

//GET CURRENT DATE
	function initArray() {
		for(i=0;i<initArray.arguments.length; i++)
		this[i] = initArray.arguments[i];
	}
	
	var isnMonths=new initArray("January","February","March","April","May","June","July","August","Sept.","October","November","December");
	var isnDays = new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
	today=new Date();
	hrs=today.getHours();
	min=today.getMinutes();
	sec=today.getSeconds();
	clckh=""+((hrs>12)?hrs-12:hrs);
	clckm=((min<10)?"0":"")+min;
	clcks=((sec<10)?"0":"")+sec;
	clck=(hrs>=12)?"p.m.":"a.m.";
	
	var stnr="";
	var ns="0123456789";
	var a="";
	
	function getFullYear(d) { // d is a date object
		yr = d.getYear();
		if (yr < 1000)
		yr+=1900;
		return yr;
	}
//END GET DATE

//////////////////////////////////////////////////////////////////////////////////////////////////////

//FIX FOR FLASH CONTENT
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////


