function CG_validateForm(theForm){
	for (i=0; i< theForm.length; i++){
		theField = theForm.elements[i];
		if(theField.id == "required"){
			if(theField.type == "select-one"){
				if(theField.options[theField.selectedIndex].value == ""){
					alert("Please Select " + theField.name + ".");
					theField.focus();
					return false;
				}
			}
			else{
				if(theField.value == ""){
					alert("Please Enter " + theField.name + ".");
					theField.focus();
					return false;
				}
			}
		}
		if(theField.id == "email"){
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theField.value))){
				alert("Please enter valid email format!");
				theField.focus();
				return false;
			}
		}
		if(theField.id == "phone"){
			if (!(/^[0-9]{3}[\- ]?[0-9]{3}[\- ]?[0-9]{4}$/.test(theField.value))){
				alert("Please enter valid phone number format! (Ex:123-123-1234)");
				theField.focus();
				return false;
			}
		}
		if (theField.id == "strCAPTCHA"){
			if (theField.value == ""){
				alert("Please Enter Secure Code.");
				theField.focus();
				return false;
			}
		}
	}

	return true;
}

function CG_CalPop(sInputName){	
	window.open('http://www2.cybergolf.com/appointments/calendar/Calendar.asp?birthday=yes&hidedate=yes&N=' + escape(sInputName) + '&DT=' + escape(window.eval(sInputName).value), 'CalPop', 'toolbar=0,width=378,height=225');
}

function CG_popup(url,w,h,scrollbar){
	if (w == "")
		open(url,'newWindow','toolbar=yes,location=yes,directiries=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes,status=yes');
	else{
		screenWidth = window.screen.width;
		l = (screenWidth - w) / 2;
		screenHeight = window.screen.height;
		t = (screenHeight - h) / 2;
		if (scrollbar)
			scrollbar = "yes"
		else
			scrollbar = "no"
		open(url,'newWindow','width='+w+',height='+h+',left='+l+',top='+t+',status=yes,scrollbars='+scrollbar);
	}
}

function CG_selectDate(fieldName,yy,mm,formName){

	url = "selectDate.asp?fieldName="+fieldName;
	if (yy) url += "&year="+yy;
	if (mm) url += "&month="+mm;
	if (formName) url += "&formName="+formName;
	pageWidth = 180;
	screenWidth = window.screen.width;
	l = (screenWidth - pageWidth) / 2;
	pageHeight = 235;
	screenHeight = window.screen.height;
	t = (screenHeight - pageHeight) / 2;
	uploadWin = window.open(url,'date','width='+pageWidth+',height='+pageHeight+',left='+l+',top='+t);
}

function CG_encryptedEmail(arr_str){
	var encryptedStr = '';
	for (var i=0; i<arr_str.length; i++){
 		encryptedStr += String.fromCharCode(arr_str[i]);
	}
	document.location.href = "mailto:" + encryptedStr;
}

function CG_numberOnly(e) {
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
		
	keychar = String.fromCharCode(key);

	if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
		return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)) {
  		return true;
	}
	else
		return false;
}

function CG_requestURL(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
}

var ua = navigator.userAgent;
var isIpad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);

