function doApplication(companyID) {
  if(companyID != ""){
    applicationWindow = window.open('application.php?companyID='+companyID,'applicationWindow','width=600,height=600,scrollbars=yes');
    applicationWindow.focus();
    } 
  }

function doPlaceBid() {
  if(doPlaceBid.arguments != ""){
    auctionBidWindow = window.open('bid.php?'+doPlaceBid.arguments[0],'placeBidWindow','width=500,height=240,scrollbars=yes');
    auctionBidWindow.focus();
    } 
  }

function showVideo() {
    videoWindow = window.open('video.php','videoWindow','width=140,height=140');
    videoWindow.focus();
	}

function openWindow() {
  $args=openWindow.arguments;
  thisWindow = window.open($args[1],$args[0],'width='+$args[2]+',height='+$args[3]+',scrollbars='+$args[4]);
  $leftPosition = (1024-$args[2])/2; $topPosition=(768-$args[3]-40)/2;
  thisWindow.moveTo($leftPosition,$topPosition);
  thisWindow.focus();
  }

function formCheck() { //a modification of MM_vaildateForm() v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=formCheck.arguments;
  for (i=0; i<(args.length-2); i+=4) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+=' - '+args[i+1]+' must contain an e-mail address.\n';
      } else if (test.indexOf('isValue')!=-1) { 
        if (val!=args[i+3]) errors+=' - '+args[i+1]+' is not valid.\n';
	  } else if (test.indexOf('isCard')!=-1) { 
        if (makeNumber(val)!=makeNumber(args[i+3])) errors+=' - '+args[i+1]+' is not valid.\n';		
      } else if (test!='R') { num = makeNumber(val);
        if (isNaN(num)) errors+=' - '+args[i+1]+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+=' - '+args[i+1]+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += ' - '+args[i+1]+' is required.\n'; }
  } if (errors) { alert('There\'s somthing wrong with your form:\n'+errors); return false; }
  	else return true;
  }
	
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 bidCheck() {
  var thiBid = document.getElementById(bidCheck.arguments[0]).value;
  //alert(thisBid);
  if (thisBidMinimum >= MM_findObj(bidCheck.arguments[0]).value) {
   alert ('Your bid needs to be greater than the '+bidCheck.arguments[1]+' bid of '+commaCurrency(thisBidMinimum));
   return false; }
   else return true;
  }
  
function etFormCheck() {
  var $count=0,$errors='',$inputs=document.getElementsByTagName('input');
  for ($i=0; $i<$inputs.length; $i++) { if($inputs[$i].getAttribute('type')=='checkbox')
	if($inputs[$i].checked) $count +=1; }
  if($count!=3) $errors+='    - You need to select three companies to request tender information from.\n';
  $fN = makeNumber(document.getElementById('faxNumber').value);
  if(!isset($fN)||$fN<7000000||$fN>8000000) $errors+='    - Please check your fax number has been entered correctly.\n';
  if(document.getElementById('acceptCharge').value != 'ACCEPT') $errors+='    - You must agree to the charges before we can process your request.\n';
  if ($errors) { alert('There seems to be a problem with the information you entered.\n'+$errors); return false; }
  	else return true;
}

function etFormNoFaxCheck() {
  var $count=0,$errors='',$inputs=document.getElementsByTagName('input');
  for ($i=0; $i<$inputs.length; $i++) { if($inputs[$i].getAttribute('type')=='checkbox')
	if($inputs[$i].checked) $count +=1; }
  if($count!=3) $errors+='    - You need to select three companies to request tender information from.\n';
  if(document.getElementById('acceptCharge').value != 'ACCEPT') $errors+='    - You must agree to the charges before we can process your request.\n';
  if ($errors) { alert('There seems to be a problem with the information you entered.\n'+$errors); return false; }
  	else return true;
}

function requestValid() {
  var $errors='',$selects=document.getElementsByTagName('select'); $inputs=document.getElementsByTagName('input');
  for ($i=0; $i<$selects.length; $i++) 
    {if($selects[$i].value == '') $errors = 'You haven\'t completed all of the answers.'; }
  for ($i=0; $i<$inputs.length; $i++) 
	{if($inputs[$i].value == '') $errors = 'You haven\'t completed all of the answers.'; }
  if($errors) alert($errors); else document.forms[requestValid.arguments[0]].submit();
}

function focusForm() {
  $thisField=focusForm.arguments[0];$fields=document.getElementsByTagName('input');
  if(focusForm.arguments[1]) $fields[$thisField].value='';
  $fields[$thisField].select();
  $fields[$thisField].focus();
}

function doSubmit() {
 if (doSubmit.arguments[0].value.length == doSubmit.arguments[1])
 document.forms[doSubmit.arguments[2]].submit();
}

function updateCart() {
  $id = updateCart.arguments[0].substring(3,11);
  $number = MM_findObj(updateCart.arguments[0]).value;
  new Ajax.Updater('cart', 'checkout.php', {parameters:'action=update&id=' + $id + '&number='+ $number, evalScripts:true, asynchronous:true});
}

function doUpdate() {
  new Ajax.Updater(doUpdate.arguments[0], doUpdate.arguments[1], {parameters:doUpdate.arguments[2], evalScripts:true, asynchronous:true});
  }

function rowHighlight() {
  $row = document.getElementById(rowHighlight.arguments[0]);
  if(rowHighlight.arguments[1]=='select') {
    if(document.getElementById($selectedRow)) document.getElementById($selectedRow).className = 'mailRow';
	$row.className = 'selected'; $selectedRow = rowHighlight.arguments[0];
	}
  if(rowHighlight.arguments[1]=='over') $row.className = 'highlight';
  if(rowHighlight.arguments[1]=='out'){ if(rowHighlight.arguments[0] == $selectedRow) $row.className = 'selected';
	else $row.className = 'mailRow';}
  }

function showEditor() {
    if(document.getElementById('preamble'))
	  document.getElementById('preamble').style.display = 'none';
	document.getElementById('editor').style.display = 'inline';}

function showHelp() {
	if(document.getElementById('help').style.display == 'none')
	  document.getElementById('help').style.display = 'block';
	else
	  document.getElementById('help').style.display = 'none'; }

function findRadio() {
  $inputs=document.getElementsByTagName('input');
    for ($i=0;$i<$inputs.length;$i++){
  	if ($inputs[$i].getAttribute('type')=='radio' && $inputs[$i].getAttribute('name') == findRadio.arguments[0] && $inputs[$i].checked) 
	  return($inputs[$i].getAttribute('value'));}
  }
	
function switchMatchText() {
  $d=document.getElementById(switchMatchText.arguments[0]);  $s=$d.options[$d.selectedIndex].value;
  $t=document.getElementById(switchMatchText.arguments[1]);
  if($s != ''){$t.innerHTML = matchData[$s]; return $s;}
  else $t.innerHTML = '&nbsp;';
  }

function switchVenueText() {
  $d=document.getElementById(switchVenueText.arguments[0]);  $s=$d.options[$d.selectedIndex].value;
  $md=document.getElementById('matchList');  $ms=$md.options[$md.selectedIndex].value;
  $t=document.getElementById(switchVenueText.arguments[1]);
  if($s != '') $t.innerHTML = venueData[$ms][$s][2];
  else $t.innerHTML = '&nbsp;';
  }

function createList() {
  $d=document.getElementById(createList.arguments[0]); $d.disabled = false; $i=0;
  $s=createList.arguments[1];
  for (keyVar in venueData[$s]) {
	$d.options[$i+2] = new Option(venueData[$s][keyVar][0],venueData[$s][keyVar][1]); $i++ }
   }
   
function markAsRead() {
  for($i=1; $i<4; $i++) {
    $thisSpan = (markAsRead.arguments[0]*10+$i);
	alert($thisSpan);
    document.getElementById($thisSpan).style = "font-weight:normal"; }
}

function showMessage() { 
  if(showMessage.arguments[0] == 'show') { 
    document.getElementById('messageHeader').innerHTML = '<p>' + messageHeaders[showMessage.arguments[1]] + '</p>'; 
	document.getElementById('messageContent').innerHTML = '<p>' + messages[showMessage.arguments[1]] + '</p>' ; }
  if(showMessage.arguments[0] == 'hide') {
    document.getElementById('messageHeader').innerHTML = '&nbsp;';
	document.getElementById('messageContent').innerHTML = '&nbsp;'; }
}


function popPanel(){
  document.getElementById('popupPanel').innerHTML='<p>'+$messages[popPanel.arguments[0]]+'</p>';
  document.getElementById('popupPanel').style.visibility='visible';
  document.body.style.cursor = 'default';
  mouseX = (document.layers) ? e.pageX : document.body.scrollLeft + event.clientX;
  mouseY = (document.layers) ? e.pageY : document.body.scrollTop + event.clientY;
  document.getElementById('popupPanel').style.left=(mouseX - 0);
  document.getElementById('popupPanel').style.top=(mouseY + 10);
  }	


function getMouse() {
  var x = event.clientX + document.body.scrollLeft;
  document.getElementById('popupPanel').style.left=x+xOffset;
  var y = event.clientY + document.body.scrollTop;
  document.getElementById('popupPanel').style.top=y+yOffset;
  }

function hidePanel(){
  document.getElementById('popupPanel').style.visibility='hidden';
  document.body.style.cursor = 'auto';
  }	

