// Utility functions for working with Objects cross browser platform.

var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function getObj(oname){		
	           	
     if ((ie4 || ie5)) return document.all[oname];	
     if (ns4) return document.layers[oname];
     if (ns6) return document.getElementById(oname);     
     return null; // Unsupported browser.
}

var pCnt=0;

function uc(cb) {
	if(cb.checked) pCnt++;
	else pCnt--;
	if(pCnt<0)pCnt=0;
}

function trim(s) {
  if(typeof(s)!='string') return s;
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isEmailAddr(Email)
{
  var result = false;
  var theStr = new String(Email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function sbIsValid() {
	var r='';
	if(trim(document.form1.name.value)=='') r+='\n - Name';
	if(trim(document.form1.typeofenquiry.value)=='') r+='\n - Type of Enquiry';
	if(trim(document.form1.natureofenquiry.value)=='') r+='\n - Nature of Enquiry';
	
	if(document.form1.respondby.value=='Telephone' && trim(document.form1.telephone.value)=='') r+='\n - Telephone';
	if(document.form1.respondby.value=='Fax' && trim(document.form1.telephone.value)=='') r+='\n - Fax';	
	if(document.form1.respondby.value=='Email' && !isEmailAddr(document.form1.email.value)) r+='\n - Valid Email Address';
			
	if(trim(document.form1.respondby.value)=='') r+='\n - How Would You Like Rainbow to Respond to Your Enquiry ?';
			 
	if(r!='')
	{
		alert('Please enter the following:' +r);
		return false;
	}

	return true;
}


function sbSubmit() {
	if(sbIsValid()) document.form1.submit();	
}



