function CheckTraining(){
	f=document.frmInquiry;
	if (f.ProductTraining.checked) return;
	f.TrainingID[0].checked=false;
	f.TrainingID[1].checked=false;
}
function CheckTrainingCD(){
	f=document.frmInquiry;
	if (f.TrainingCD.checked) return;
	IDs = f.TrainingCDIDs.value.split(',');
	for (i=0;i<IDs.length;i++)
		f['ServID'+IDs[i]].checked=false;
	f.TrainingCDOther.value='';
}
function CDactivate(){
	f=document.frmInquiry;
	IDs = f.TrainingCDIDs.value.split(',');
	for (i=0;i<IDs.length;i++)
		if (f['ServID'+IDs[i]].checked)
			{f.TrainingCD.checked=true; return;}
	if (Trim(f.TrainingCDOther) != '') {f.TrainingCD.checked=true;return;}
	f.TrainingCD.checked=false;
}
function CheckChildren(par) {
	f=document.frmInquiry;
	if (f['ServID'+par].checked) return;
	IDs = f['Children'+par].value.split(',');
	for (i=0;i<IDs.length;i++)
		f['ServID'+IDs[i]].checked=false;
}
function CheckServices(f){
	num=0;
	/*if (f.ProductTraining.checked){
		if (f.TrainingID[0].checked||f.TrainingID[1].checked) num++;
		else return Msg(f.TrainingID[0],"You selected Product Training but need to specify Markham or Customer Site");
	}
	if (f.TrainingCD.checked){
		IDs=f.TrainingCDIDs.value.split(',');
		found=false;
		for(i=0;i<IDs.length; i++)
			if (f['ServID'+IDs[i]].checked)
				{found=true; break;}
		if (f.TrainingCDOther.value!='') found=true;
		if (found) num++;
		else return Msg(f['ServID'+IDs[0]],"You selected Learning CD but didn't select which one(s)");
	}*/
	IDs =f.MainIDs.value.split(',');
	for(i=0;i<IDs.length;i++) {
		if (!f['ServID'+IDs[i]].checked) continue;
		if (f['Children'+IDs[i]]) {
			SIDs=f['Children'+IDs[i]].value.split(',');
			found=false;
			for (c=0;c<SIDs.length;c++)	
				if (f['ServID'+SIDs[c]].checked)
					{found=true;break;}
			if(!found) return Msg(f['ServID'+SIDs[0]],"You didn't select an item for 'Design and Test protection scheme'");
		}
		num++;
	}
		
	if (num==0) return Msg(f.ServID1,"At least 1 requested service must be selected");
	else return true;
}

function CheckForm(){
	var frm=document.frmInquiry;
	if (ValidateEntries(frm)) {
		if (document.location.toString().indexOf('.ge.com')!=-1) frm.action = "http://olsdev.consind.ge.com/cgi-bin/cons-form.asp";
		frm.submit();
	}
}
function ValidateEntries(frm){
	if (Trim(frm.FirstName)=='') return Msg(frm.FirstName, "First Name is required");
	if (frm.FirstName.value.length==1) return Msg(frm.FirstName, "Please enter a valid first name");
	if (Trim(frm.LastName)=='') return Msg(frm.LastName, "Last Name is required");
	if (frm.LastName.value.length==1) return Msg(frm.LastName, "Please enter a valid last name");
	if (Trim(frm.Company)=='') return Msg(frm.Company, "Company name is required");
	if (frm.Company.value.length<3) return Msg(frm.Company, "Please enter a valid company name");
	if (Trim(frm.Phone)=='') return Msg(frm.Phone, "Phone number is required");
	if (!validPhone(frm.Phone.value)) return Msg(frm.Phone, "Please enter a valid phone number");
	if (Trim(frm.Email)!='') if (!isValidEmail(frm.Email.value)) return Msg(frm.Email, "Please enter a valid email address");
	if (!CheckServices(frm)) return false;
	if (Trim(frm.Products)=='') return Msg(frm.Products, "Please specify the product(s) for which you are requesting Consulting Services");
	return true;
}
function Trim(fld) {
	var v=fld.value;
	v = v.replace(/^ +/,'');
	v = v.replace(/\b +$/, '');
	fld.value = v;
	return v;
}
function Msg(ctl,msg){
	ctl.focus();
	alert(msg);
	return false;
}
function isValidEmail(email) {
	var rxEmail;
	rxEmail = /^[\w\-]+[\.\w\-\/%]*[\w\-]+@[\w]+[\w\.\-]*\.[a-z]{2,4}$/i;
	return rxEmail.test(email);
}
function validPhone(num){
	var rx = /^[0-9\(\)\.ext \-\+]*$/i;
	return rx.test(num);
}
function Toggle(ctl){
	if (eval("document.frmInquiry."+ctl+".type")=='radio')
		eval("document.frmInquiry."+ctl+".checked = true");
	else
		eval("document.frmInquiry."+ctl+".checked = !document.frmInquiry."+ctl+".checked");
}

