// PopUp
// creates a new popup window
function PopUp(URL,Name,w,h,a,t) {

	// collect attributes
	var winN = Name;                    // set the value of the window's name (no spaces allowed)
	var winW = w;                       // set window's width to passed width (if any)
	var winH = h;                       // set window's height to passed height (if any)
	var aVal = a;                       // set the value of the window's attributes (if any)
	var tVal = t;                       // set the value of the window's toolbar
   
	// set attributes if undefined
	if (!winN) winN = Math.round(Math.random() * 1000000000); // set window name to a random number if undefined
	if (!winW) winW = 400;                                    // set window width if undefined
	if (!winH) winH = 400;                                    // set window height if undefined
	if (!aVal) aVal = "yes";                                  // set window default attribute value
	if (!tVal) tVal = "yes";                                  // set window default toolbar value
   
	// open popup window
	var newWin= window.open(URL,winN,'width=' + winW + ',height=' + winH + ',resizable=' + aVal + ',scrollbars=' + aVal + ',toolbar=' + tVal);
	newWin.focus();                     // set focus on the new window
}


function open_req(url) {
	jpegwindow = window.open(url,"jpegwindow",'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=470,height=475');
}


// Begin Field Content Check
// check for valid email address
var emailexp = /^[A-Z_a-z_0-9/./_/-]+@[A-Z_a-z_0-9\.\-]+\.[A-Z_a-z]/;

function FormCheck(formtype){
var formtype = formtype;	

	/*
		Check to make sure that required fields are complete upon
		submission of form. This JavaScript is used to check for basic 
		contact info on all the Mac-Gray contact forms. Some forms 
		use additonal Javascript to check for form specific required 
		fields. These forms pass a "form type" parameter upon 
		submitting the form. 
	*/
	
	var error_msg="";
	if (FieldCheck('first_name')) error_msg +="\nFirst Name";
	if (FieldCheck('last_name')) error_msg +="\nLast Name";
	if (FieldCheck('organization')) error_msg +="\nCompany, Property or Institution"; 
	if (FieldCheck('title')) error_msg +="\nTitle";
	if (FieldCheck('phone')) error_msg +="\nPhone Number";
	if (FieldCheck('email')) error_msg +="\nEmail";
	if (document.template.email.value != ''){
		if (!(emailexp.test(document.template.email.value))){
				error_msg +="\nValid email address";
		}	 
	}
	if (FieldCheck('address1')) error_msg +="\nAddress 1";
	if (FieldCheck('city')) error_msg +="\nCity";
	if (FieldCheck('state')) error_msg +="\nState";
	if (FieldCheck('zip')) error_msg +="\nZip Code";

	
	////////////////////////////////////
	// BEGIN FORM SPECIFIC JAVASCRIPT //
	////////////////////////////////////

	//////////////////////////////////////////////////////
	/* Begin JavaScript for Multi-Housing Request pages 
	   to check form specific required fields, Primarily 
	   to make sure that all fields are entered if the user 
	   opts to receive free brochure.
	   
	   The JavaScript is used by the following forms:
	   		req_multihouse.html
			req_multihouse_laun.html
			req_multihouse_corp.html)
	   
	*/
	//////////////////////////////////////////////////////
	
	
	///////////////////////////////////////////////////////////////
	// Begin JavaScript for Customer Service Request pages 
	// to check form specific required fields.
	///////////////////////////////////////////////////////////////
	
	// csLaundry.html - JavaScript 
	
	if (formtype == 'laundryservice') { 
	
		// Check to make sure that at least one option was selected for "business or professional area"
		var radio = eval("document.template.F1");
		if ( !radio[0].checked &&
           !radio[1].checked &&
           !radio[2].checked &&
           !radio[3].checked &&
           !radio[4].checked &&
           !radio[5].checked ) {
               error_msg +="\nBusiness or Professional Area";
        }       
		// Check to make sure that at least one option was selected for "Equipemt Information"
		var checkbox_choices = 0;  
		for (var i = 2; i < 6; i++){
			var checkbox = eval("document.template.F" + i);
			if (checkbox.checked){
				checkbox_choices = checkbox_choices + 1; 
			}
		}
		// If "Other", check to make sure that the equipment was entered in the text field
		var dummy = eval("document.template.dummy"); 
		if ((dummy.checked) && (document.template.F7.value == '')) { // alert user
			alert('You have selecetd "Other" for "Equipment Information" field. \nPlease enter the equipment type.');
			return false;
		}	
		//If the "Other" field is empty and no check boxes are selected => error message
		if ((document.template.F7.value == '') && (checkbox_choices < 1 )){
			error_msg +="\nEquipment Information";
		}
		// if (FieldCheck('F8')) error_msg +="\nModel Number";
		// if (FieldCheck('F9')) error_msg +="\nSerial Number";
		// if (FieldCheck('F10')) error_msg +="\nManufacture Date";
		if (FieldCheck('F11')) error_msg +="\nDescription of Problem";
		if (FieldCheck('F12')) error_msg +="\nBuilding Name or Number";
		if (FieldCheck('F13')) error_msg +="\nFloor";
	}
	
	
	// mf_refrequest.html - Javascript
	
	if (formtype == 'microfridgeref') { 
		// Check to make sure that at least one option was selected for "Equipemt Information"
		var checkbox_choices = 0;  
		for (var i = 3; i < 8; i++){
			var checkbox = eval("document.template.F" + i);
			if (checkbox.checked){
				checkbox_choices = checkbox_choices + 1; 
			}
		}
		//If no check boxes are selected => error message
		if (checkbox_choices < 1 ){
			error_msg +="\nProduct Type";
		}
	}
	
	
	// csMF.html - Javascript
	
	if (formtype == 'microfridgeservice') { // microfridge form specific required fields
		// Check to make sure that at least one option was selected for "business or professional area"
		var radio = eval("document.template.F1");
		if ( !radio[0].checked &&
           !radio[1].checked &&
           !radio[2].checked &&
           !radio[3].checked &&
           !radio[4].checked &&
           !radio[5].checked &&
           (document.template.F2.value == '')){
            error_msg +="\nBusiness or Professional Area";
        }    
        // If "Other"(option 5), check to make sure that the business or professional is entered in the text field
		if ((radio[5].checked) && (document.template.F2.value == '')) { // alert user
			alert('You have selecetd "Other" for the "Business or Professional Area" field. \nPlease enter your business or professional area.');
			return false;
		}   
		// Check to make sure that at least one option was selected for "Equipemt Information"
		var checkbox_choices = 0;  
		for (var i = 3; i < 6; i++){
			var checkbox = eval("document.template.F" + i);
			if (checkbox.checked){
				checkbox_choices = checkbox_choices + 1; 
			}
		}
		//If the "Other" field is empty and no check boxes are selected => error message
		if (checkbox_choices < 1 ){
			error_msg +="\nEquipment Information";
		}
		// if (FieldCheck('F6')) error_msg +="\nModel Number";
		// if (FieldCheck('F7')) error_msg +="\nSerial Number";
		// if (FieldCheck('F8')) error_msg +="\nManufacture Date";
		if (FieldCheck('F9')) error_msg +="\nDescription of Problem";
		if (FieldCheck('F10')) error_msg +="\nBuilding Name or Number";
		if (FieldCheck('F11')) error_msg +="\nFloor";
	}
	
	
	// cscopico.html - Javascript
	
	if (formtype == 'copicoservice') { // copico form specific required fields
		if (FieldCheck('F1')) error_msg +="\nEquipment ID Number";
		if (FieldCheck('F2')) error_msg +="\nDescription of Problem";
	}
	
	/////////////////////////////////
	//END FORM SPECIFIC JAVASCRIPT //
	/////////////////////////////////
	
	if (error_msg){
		error_msg = "Please complete the following\nfields before submitting the form:\n" + error_msg;
		alert(error_msg);
		return false;
	}

} // end FormCheck()

// Check for contents in required fields
function FieldCheck(field_name) {
	if(eval("document.template." + field_name + ".value")) return false; 
	else return true;	
}

// End Field Content Check
