// JavaScript Document
// Google Maps
function load() {
	if (GBrowserIsCompatible()) {
		var point = new GLatLng(43.662998,-79.371972);
		var center = new GLatLng(43.662998,-79.371972);
		var marker = new GMarker(point);
		var message = "<b>WEA Canada</b><br />157 Carlton Street, Suite 205<br />Toronto, Ontario<br />Canada M5A 2K2";
		var map = new GMap2(document.getElementById("map"));
		var marker = new GMarker(point);

		GEvent.addListener(marker, "click", function() {map.openInfoWindowHtml(point, message);});

		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		map.setCenter(center, 14);
		map.addOverlay(marker);
  		}
}

function emailValid (email)
{
	email = trim(email);
	
	/* Only one @ in email address */
	if (email.indexOf("@") != email.lastIndexOf("@")) {
		return false;
	}

	/* special characters' position checking */
	// Have @ and not be the first
	if (email.indexOf("@") < 1) {
		return false;
	// Last . must be after @ and between . and @ at least one character
	} else if (email.lastIndexOf(".") <= (email.indexOf("@")+1)) {  
		return false;
	// No two .
	} else if (email.indexOf("..") >=0) {
		return false;
	// . must not be the last character
	} else if (email.lastIndexOf(".") == (email.length - 1)) {  // . must not be the last character
		return false;
	}
	
	/* characters' validation checking */
	// allow ONLY valid characters for email Field
	var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_";
	var i = 0
	for (i = 0;  i < email.length;  i++)
	{
		ch = email.charAt(i);
	
		if (validChars.indexOf(ch) != -1)
			continue;
	
		return false;
	}

	
	return true;
}

function trim(str)
{
	s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');

	return s;
}

function _CF_onError(form_object, input_object, object_value, error_message)
    {
	alert(error_message);
       	return false;	
    }

function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    	}
    else if (obj_type == "SELECT")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected)
			return true;
		}
       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{
		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
	}

function  _CK_Form(_CF_this)
    {
    
		if  (!_CF_hasValue(_CF_this.Name, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Name, _CF_this.Name.value, "your Name is required"))
            {
						_CF_this.Name.focus();
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.Email, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Email, _CF_this.Email.value, "E-mail is required"))
            {
						_CF_this.Email.focus();
            return false; 
            }
        }

		// validate the email fields
    if (!emailValid(_CF_this.Email.value)) {
		   alert("Please enter a valid email address.");
			 _CF_this.Email.focus();
			 return false;
		}

    if (!_CF_hasValue(_CF_this.Message, "TEXT" ))
        {
        if (!_CF_onError(_CF_this, _CF_this.Message, _CF_this.Message.value, "Please enter your messages."))
            {
						_CF_this.Message.focus();
            return false;
            }
        }
}

function  _CK_App_Form(_CF_this)
    {
    
		if  (!_CF_hasValue(_CF_this.Name, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Name, _CF_this.Name.value, "your Name is required"))
            {
						_CF_this.Name.focus();
            return false; 
            }
        }
		
		if  (!_CF_hasValue(_CF_this.Address, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Address, _CF_this.Address.value, "your Address is required"))
            {
						_CF_this.Address.focus();
            return false; 
            }
        }

		if  (!_CF_hasValue(_CF_this.Phone, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Phone, _CF_this.Phone.value, "your Phone# is required"))
            {
						_CF_this.Phone.focus();
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.Email, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.Email, _CF_this.Email.value, "E-mail is required"))
            {
						_CF_this.Email.focus();
            return false; 
            }
        }

		// validate the email fields
    if (!emailValid(_CF_this.Email.value)) {
		   alert("Please enter a valid email address.");
			 _CF_this.Email.focus();
			 return false;
		}

	if (!_CF_this.winter1.checked && !_CF_this.winter2.checked && !_CF_this.spring1.checked && !_CF_this.spring2.checked) {
		alert("Please select at least one course!!");
		return false;
	}


    if (!_CF_hasValue(_CF_this.edu_background, "TEXT" ))
        {
        if (!_CF_onError(_CF_this, _CF_this.edu_background, _CF_this.edu_background.value, "Please enter your education background."))
            {
						_CF_this.edu_background.focus();
            return false;
            }
        }
}

	