 function CatalogItemQuotation(catid)
 {
   found = false;
 	for (i=0; i<quotations.length; i++)
 	{
 	  if (quotations[i]==catid)
 	  {
 	    found= true;
 	    break;
 	  }
 	}
 	if (found)
 	  removeCatalogItemFromQuotation(catid);
 	else
 	  addCatalogItemToQuotation(catid);
 }

 function addCatalogItemToQuotation(catid)
 {
	 url = 'catalogusmodule/catalogusactions.aspx?action=addquote&QID=' + catid
	 AjaxRequest.get(
		 {
			 'url':url
			 ,'onSuccess':function(req)
			 {
			 	quotations[quotations.length] = catid;
			 }
			 ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		 }
	 );
 }

 function removeCatalogItemFromQuotation(catid)
 {
	 AjaxRequest.get(
		 {
			 'url':'catalogusmodule/catalogusactions.aspx?action=removequote&QID=' + catid
			 ,'onSuccess':function(req)
			 { 
			 	for (i=0; i<quotations.length; i++)
			 	{
			 	  if (quotations[i]==catid)
			 	  {
			 	    quotations.splice(i,1);
			 	    break;
			 	  }
			 	}
			 }
			 ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		 }
	 );
 }

 var quotations_event = null;
 var quotations = new Array(); 
 
 function GetQuotationsDisplay()
 {
	 url = 'catalogusmodule/catalogusactions.aspx?action=getquotesdisplay'
	 AjaxRequest.get(
		 {
			 'url':url
			 ,'onSuccess':function(req)
			 {
			 	el = document.getElementById("tbquotations");
			 	if (req.responseText!="")
			 	{
			 	  if (el!=null) el.innerHTML = req.responseText;
			 	}
			 }
			 ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		 }
	 );
 }

 function GetQuotations()
 {
	 AjaxRequest.get(
		 {
			 'url':'catalogusmodule/catalogusactions.aspx?action=getquotes'
			 ,'onSuccess':function(req){
			 if (req.responseText!="")
			 {
			   quotations = req.responseText.split(",");			   			  			   
			   quotations_requested = true;
			   for (i=0; i<quotations.length; i++)
			   {
			     qcb = document.getElementById("qcb_"+quotations[i]);
			     if (qcb!=null) qcb.checked = true;
			   };
			 }
			 if (quotations_event!=null)
			   quotations_event();
		 }
		 ,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		 }
	 );
 }

 function GoRequest() {
	 if (quotations.length > 0) {
	 	window.location = "informationrequest.html";
	 }
	 else {
	 	alert("You need to select at least one machine!");
	 }
 }
 
var inputValid = true;

function submitForm()
{
   quotations_event = function() { _submitForm(); };
	GetQuotations();
}

function _submitForm()
{  
   if (quotations.length > 0) {   
     checkFields();              
     if(inputValid == true) 
     {
     
     	 var btn=document.getElementById("btn");
     	 if (btn!=null)
     	 {
     	    btn.style.display = "none";     	    
     	 }
     	 var btnspan=document.getElementById("btnspan");
     	 if (btnspan!=null)
     	 {
     	    btnspan.innerHTML = "Sending request... please wait...";
     	 }
     
       var frm = document.forms["kgtmachine"];             
       if (frm == null) return;
       frm.action = "catalogusmodule/dealeractions.aspx";
              

		 status = AjaxRequest.submit(
			frm
			 ,{
			   'onSuccess':function(req)
			   { 
			   	window.location = "informationrequest.html?thanks=1";
			   },
			   'onError':function(req)
			   { 
			   	alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
			   }
			 }
			);
     }
     else {
       alert("One or more required fields are left blank or filled incorrectly!");
     }
   }
   else {
     alert("You need to select at least one machine!");
   }
}

function checkFields()
{

  inputValid = true;
  //check input
  if(!checkRequired('txtCompany'))
  {
    setRequiredLabel('txtCompany', true);
    inputValid = false;
  }
  else
    setRequiredLabel('txtCompany', false);

  if(!checkRequired('txtContact'))
  {
    setRequiredLabel('txtContact', true);
    inputValid = false;
  }
  else
    setRequiredLabel('txtContact', false);

  if(!checkRequired('txtEmail'))
  {
	  setRequiredLabel('txtEmail', true);
	  inputValid = false;
  }
  else
  {
  	 setRequiredLabel('txtEmail', false);

	  if(!isValidEmail('txtEmail'))
	  {
	  inputValid = false;
	    setEmailValidLabel('txtEmail', true);
	  }
	    else
	  {
	    setEmailValidLabel('txtEmail', false);
	  }

  }

  if(!checkRequired('txtTel'))
  {
	  setRequiredLabel('txtTel', true);
	  inputValid = false;
	}
	else
	  setRequiredLabel('txtTel', false);
	
	if(!checkRequired('txtCountry'))
	{
	  setRequiredLabel('txtCountry', true);
	  inputValid = false;
	}
	else
	  setRequiredLabel('txtCountry', false);
	
}

function checkRequired(elemId)
{
  var elem = document.getElementById(elemId);
  if(elem != null)
  {
    if(elem.value == '')
    {
    inputValid = false;
    return false;
    }
    else
    return true;
  }
}

function setRequiredLabel(elemId, visible)
{
  var lbl = document.getElementById(elemId + '_required');
  if(visible)
    lbl.style.visibility='visible';
  else
    lbl.style.visibility='hidden';
}

function setEmailValidLabel(elemId, visible)
{
  var lbl = document.getElementById(elemId + '_format');
  if(visible)
    lbl.style.display='inline';
  else
    lbl.style.display='none';
}

function isValidEmail(elemid)
{
  var elem = document.getElementById(elemid);

  if(elem != null)
  {
    var str = elem.value;
    return ((str.indexOf(".") > 0) && (str.indexOf("@") > 0));
  }
}
