function getAbsoluteLeft(objectId) {
	o =objectId;
	oLeft = o.offsetLeft;            // Get left position from the parent object
	while(o.offsetParent!=null) {    // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;    // Get parent object reference
		oLeft += oParent.offsetLeft; // Add parent left position
		o = oParent;
	}
	return oLeft;
}
function getAbsoluteTop(objectId) {
	o =objectId;
	oTop = o.offsetTop;            // Get top position from the parent object
	while(o.offsetParent!=null) {  // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;  // Get parent object reference
		oTop += oParent.offsetTop; // Add parent top position
		o = oParent;
	}
	return oTop;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function BlankSpaces(checkStr){
   var allValid = true;
   var nonBlank = 0;
   for (var i = 0;  i < checkStr.length;i++){
      if(checkStr.charAt(i)==" "){
         allValid = false;
      } else {
         nonBlank++;
         allValid = true;
      }
   }
   if(nonBlank > 0){
      return true;
   }else{
      return false;
   }
}
function IsValid(str,invalidChars){
   var allValid = true;
   for(var i = 0; i < str.length; i++) {
      if(invalidChars.indexOf(str.charAt(i)) != -1){
         allValid = false;
         break;
      }else{
         allValid = true;
      }
   }
   return(allValid);
}

function OnlyValid(str,validChars){
   var allValid = true;
   for(i = 0; i < str.length; i++) {
      if(validChars.indexOf(str.charAt(i)) == -1){
         allValid = false;
         break;
      }else{
         allValid = true;
      }
   }
   return(allValid);
}
function Trim(str){
   str = str.replace(/^\s+/, "");
   str = str.replace(/\s+$/, "");
   return (str);
}
function IsEmpty(fieldname){
   var val = Trim(GetValue(fieldname));
   if(val==""){return true;}else{return false;}
}
function IsNumber(fieldname){
   var strN = GetValue(fieldname);
   if(isNaN(parseInt(strN))){return false;}else{return true;}
}
function AddToList(text){
  list = list + text;
}

function GetValue(fieldname){
   var strV = eval(contactForm+'.'+fieldname+'.value');
   if (typeof(strV)=="string"){
      return Trim(strV);
   }else{
      // select box;
      var strV = eval(contactForm+'.'+fieldname);
      for(i=0;i<strV.length;i++){
         if(strV[i].checked){return strV[i].value;}
      }
      return '';
      //alert('Please supply details for -'+strV.name);
   }
}

function SelectOption1(fieldname){
	var oSelect= eval(contactForm+'.'+fieldname);
	if (oSelect.selectedIndex==0){
		return true;
	}else{
		return false;
	}
}
function SelectValue(fieldname){
	var oSelect= eval(contactForm+'.'+fieldname);
	return oSelect.options[oSelect.selectedIndex].text;
}

var list = "";
var contactForm ='document.forms[\'details\']';

function AddToList(text){
	list = list + text;
}
function submit_details(){
  list = 'Please fill in the following fields:\n';
  var valid=true;
  if(IsEmpty('fname')) {AddToList('-first name \n');valid=false;}
  if(IsEmpty('lname')) {AddToList('-last name \n');valid=false;}
  if(SelectOption1('method')){AddToList('-preferred method of contact\n');valid=false;}
  if(SelectValue('method')=='email'){
    if (IsEmpty('email') || !ValidEmail(GetValue('email'))){AddToList('-email address\n');valid=false;}
  }
  if(SelectValue('method')=='business phone'){
    if(IsEmpty('int_code')||IsEmpty('area_code')||IsEmpty('number')){
      AddToList('-business phone number\n');valid=false;
    }else if(!IsNumber('int_code')||!IsNumber('area_code')||!IsNumber('number')){
      AddToList('-please enter number values for your business phone number \n');valid=false;
    }
  }    
  if(SelectValue('method')=='mobile phone'){
    if(IsEmpty('mob_int_code')||IsEmpty('mob_area_code')||IsEmpty('mob_number')){
      AddToList('-mobile phone number\n');valid=false
    }else if(!IsNumber('mob_int_code')||!IsNumber('mob_area_code')||!IsNumber('mob_number')){
      AddToList('-please enter number values for your mobile phone number \n');valid=false;
    } 
  }
  
  if(SelectOption1('inquiryType')){AddToList('-inquiry type\n');valid=false;}
  if(IsEmpty('inquiry_text')){AddToList('-inquiry details\n');valid=false;}
  if(!valid){
	alert(list);
  }else{
	eval(contactForm+'.submit();');
  }
}
function InvalidCharsForEmail(str){
   var iChars = " *|,\":<>[]{}~`#=$\';()!+/";
   return(IsValid(str,iChars)?true:false);
}
function ValidEmail(email){
   if (email != ""){
      if((!BlankSpaces(email)) || (!InvalidCharsForEmail(email))){
         return false;
      }
      invalidChars = " /:,;";
      if (email == " "){
         return false;
      }
      for (i=0; i<invalidChars.length;i++){
         badChar = invalidChars.charAt(i);
         if (email.indexOf(badChar,0) > -1){
            return false;
         }
      }//end of for loop
      atPos = email.indexOf("@",1);
      if (atPos == -1 ) {
         //alert('not @'+email);
         return false;
      }
      if (email.indexOf("@",atPos+1) >-1) {
         return false;
      }
      periodPos = email.indexOf(".",atPos);
      if (periodPos == -1) {
         return false;
      }
      if (periodPos+3 > email.length) {
         return false;
      }
      for(i=0;i<email.length;i++){
         if((email.charAt(i) == '@') && (email.charAt(i+1) == '.') || (email.charAt(i-1) == '.') && (email.charAt(i) == '@')){
            return false;
         }
      }
   }
   return true;
}
//*/