// JavaScript Document

function openWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkJoinForm() {
	var theform = document.join_form; // just to keep code cleaner below
	if(theform.emp_name.value=='' || theform.mbr_email.value=='' || theform.mbr_name.value=='' || theform.mbr_pwd.value=='') {
		alert("Please fill in all required fields. \n");
		return false ;
	}
	if(!theform.terms.checked) {
		alert("You must agree to the Terms of Use. \n");
		return false ;
	}
	if(theform.mbr_pwd.value !== theform.mbr_pwd2.value) {
		alert("Your passwords do not match. \n");
		return false ;
	}
}

function checkNewContactForm() {
	var theform = document.join_form; // just to keep code cleaner below
	if(theform.mbr_email.value=='' || theform.mbr_pwd.value=='') {
		alert("Please fill in all required fields. \n");
		return false ;
	}
	if(theform.mbr_pwd.value !== theform.mbr_pwd2.value) {
		alert("Your passwords do not match. \n");
		return false ;
	}
}

function confirmFileDelete() {
	var agree=confirm(" Are you sure you want to permanently delete this file? \nThis action cannot be undone.");
	if (agree) return true ;
	else return false ;
}

function no_docs_uploaded() {
	alert("You must upload documents before notifying the Underwriter. \n");
	return false ;
}

function confirm4CharSearch() {
	var theformfield = document.search_keyword_form.keyword; // just to keep code cleaner below
	if(theformfield.value.length > 0 && theformfield.value.length < 4) {
		var agree=confirm("Please note that effective keyword search requires words at least 4 letters long.\n");
		if (agree) return true ;
		else return false ;
	}
}

function indication_submit() {
	var theform = document.indication_form; // just to keep code cleaner below
	var error_msg = '';
	if(theform.cont_name.value=='') {
		error_msg += 'Please enter the Contractor\'s Name\n';
		theform.cont_name.style.background = 'Yellow';
	} else {
		theform.cont_name.style.background = 'White';
	}
	if(theform.cont_state.value=='') {
		error_msg += 'Please enter the Contractor\'s State\n';
		theform.cont_state.style.background = 'Yellow';
	} else {
		theform.cont_state.style.background = 'White';
	}
	if(error_msg.length > 0) { // Generate Error Message 
		var msg = 'Please correct the following errors:\n\n';
		alert(msg + error_msg);
		return false;
	}
}

function rfq_submit() {
	var theform = document.rfq_form; // just to keep code cleaner below
	var error_msg = '';
	if(theform.needby_date.value=='') {
		error_msg += 'Please enter the \'Need By\' date. \n';
		theform.needby_date.style.background = 'Yellow';
	} else {
		theform.needby_date.style.background = 'White';
	}
	if(error_msg.length > 0) { // Generate Error Message 
		var msg = 'Please correct the following errors:\n\n';
		alert(msg + error_msg);
		return false;
	}
}

function show_hide_indication_fields() {
	var theform = document.indication_form; // just to keep code cleaner below
	var radio_add_insured_auto = '';
	for (var i=0; i < theform.add_insured_auto.length; i++) {
		if(theform.add_insured_auto[i].checked) {
			radio_add_insured_auto = theform.add_insured_auto[i].value;
		}
	}
	if(radio_add_insured_auto=='Yes') { // is_applicant is set to NO
		show('wording1');
	} else {
		hide('wording1');		
		for (var i=0; i < theform.primary_wording1.length; i++) { // uncheck the primary_wording1 radio button
			theform.primary_wording1[i].checked=false;
		}		
	}
	var radio_add_insured_sched = '';
	for (var i=0; i < theform.add_insured_sched.length; i++) {
		if(theform.add_insured_sched[i].checked) {
			radio_add_insured_sched = theform.add_insured_sched[i].value;
		}
	}
	if(radio_add_insured_sched=='Yes') {
		show('wording2');
	} else {
		hide('wording2');
		theform.num_req.value='';		
		for (var i=0; i < theform.primary_wording2.length; i++) { // uncheck the primary_wording2 radio button
			theform.primary_wording2[i].checked=false;
		}		
	}
} // END SHOW/HIDE FIELDS FUNCTION

function show(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	} else {
		if (document.layers) {	
			document.id.display = 'block';
		} else {
			document.all.id.style.display = 'block';
		}
	} 
}
function hide(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	} else {
		if (document.layers) {	
			document.id.display = 'none';
		} else {
			document.all.id.style.display = 'none';
		}
	}
}


