function loadRFQ(url) {
	$.ajax({
		type: "GET",	
		dataType: "html",
  	url: url,
	  cache: false,	
		error: function(XMLHttpRequest, textStatus, errorThrown) {			
				$("#rfq-form-holder").empty();
				$("#rfq-form-holder").append("<p style='color:red;'>We are currently experiencing some problems with our RFQ System, please bear with us, while we work on this issue</p>");
		},
  	success: function(html){				
				$("#rfq-form-holder").empty();
    		$("#rfq-form-holder").append(html);
  	}
	});	
}

function loadContact(url) {
	$.ajax({
	  type: "GET",
		dataType: "html",
  	url: url,
	  cache: false,
		error: function(XMLHttpRequest, textStatus, errorThrown) {			
				$("#contact-form-holder").empty();
				$("#contact-form-holder").append("<p style='color:red;'>We are currently experiencing some problems with our Contact System, please bear with us, while we work on this issue</p>");
		},
  	success: function(html){
				$("#contact-form-holder").empty();
    		$("#contact-form-holder").append(html);
  		}
	});
	
}

function hideOrShow(id, show) {
	display = 'none';
	if (show) display = 'block';
		document.getElementById(id).style.display = display;
}	


function getParameters(form, rfq) {
	
      var getstr = "?";
			//alert(form.elements.length);
      for (i=0; i<form.elements.length; i++) {
         if (form.elements[i].tagName == "INPUT") {
            if (form.elements[i].type == "text" || form.elements[i].type == "hidden") {
               getstr += form.elements[i].name + "=" + form.elements[i].value + "&";
            }
            if (form.elements[i].type == "checkbox") {
               if (form.elements[i].checked) {
                  getstr += form.elements[i].name + "=" + form.elements[i].value + "&";
               }
            }
            if (form.elements[i].type == "radio") {
               if (form.elements[i].checked) {
                  getstr += form.elements[i].name + "=" + form.elements[i].value + "&";
               }
            }
         }   
         if (form.elements[i].tagName == "SELECT") {
            var sel = form.elements[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
				 if (form.elements[i].tagName == "TEXTAREA") {
             getstr += form.elements[i].name + "=" + form.elements[i].value + "&";            
         }
				 //alert(getstr);
         
      }
     
		 if (rfq) 
			 submitRFQForm(getstr);
		 else
		 	 submitContactForm(getstr);
			 
}
	 
function submitRFQForm(getstr) {
		// make the loading images
		$("#rfq-form-holder").empty();
		$("#rfq-form-holder").append("<div style='margin: 40%;'><p align='center'><img src='/search/rfq/loading.gif'/> <br/>Processing RFQ </p></div>");
		loadRFQ('/1/search/rfq/rfq_process.cfm' + getstr);	
}

function submitContactForm(getstr) {
		// make the loading images
		$("#contact-form-holder").empty();
		$("#contact-form-holder").append("<div style='margin: 40%;'><p align='center'><img src='/search/rfq/loading.gif'/> <br/>Processing Contact Form </p></div>");
		loadContact('/search/contact/feedback_process.cfm' + getstr);
}



function check(){
	var form=document.frmData;
		if (form.contactName.value==""){
			alert("You need to fill in your Contact Name.");
			form.contactName.focus();
			return false;
		}
		
		if (form.companyName.value==""){
			alert("You need to fill in your Company Name.");
			form.companyName.focus();
			return false;
		}

		if (form.city.value==""){
			alert("You need to fill in your City");		 	
			form.city.focus();
			return false;
		}
		if (form.Prov.value==""){
			alert("You need to fill in your State.");		 	
			form.Prov.focus();
			return false;
		}		

	if (form.email.value==""){
	// checks if email field is valid enter
		var emailflag=0;
		for(var i=0; i<form.email.value.length; i++){
		        var temp=form.email.value.substring(i, i+1);
		
				 if(temp=="@"&&emailflag==1){
					emailflag=2;
					break;
				 }
				 
				 if(temp=="@"&&emailflag==0){
					emailflag=1;
				 }
		} 
		      
		if(emailflag==0||emailflag==2){
		    alert("Provide a proper e-mail address!");				
				form.email.focus();
				form.email.select();
		        return false;
		}
	}
		
	if (form.information.value==""){
		alert("You need to fill in the Information for the quote.");
		form.information.focus();
		return false;
	}


	if(form.information.value.length > 400) {
			alert("The Requested Information field must have less than 400 characters.");
			form.information.focus();
			return false;
	}

	return true;
}


