function moveRight(obj) {
	var seltext;
	var selval;
	var myForm = eval("document." + obj.name);
	
  if (myForm.source.options[0] == null) {
  	return false; }
  else {
	  seltext = myForm.source.options[myForm.source.selectedIndex].text;
	  selval = myForm.source.options[myForm.source.selectedIndex].value;
	  myForm.target.options[myForm.target.options.length] = new Option(seltext, selval);
	  myForm.source.options[myForm.source.selectedIndex] = null;
	  myForm.target.options[0].selected = true;
	  if (myForm.source.options[0] == null) {
		  return false;}
    else {
	    myForm.source.options[0].selected = true;}
	}
}

function moveLeft(obj) {
	var seltext;
	var selval;
	var myForm = eval("document." + obj.name);
 
  if (myForm.target.options[0] == null) {
  	return false; }
  else {
	  seltext = myForm.target.options[myForm.target.selectedIndex].text;
	  selval = myForm.target.options[myForm.target.selectedIndex].value;
	  myForm.source.options[myForm.source.options.length] = new Option(seltext, selval);
	  myForm.target.options[myForm.target.selectedIndex] = null;
	  myForm.source.options[0].selected = true;
	  if (myForm.target.options[0] == null) {
		  return false;}
    else {
	    myForm.target.options[0].selected = true;}
	}
}

function moveToRightVal(flag) {
	var seltext;
	var selval;
  if (document.selform.source.options[0] == null) {
  	return false; }
  else {
	  seltext = document.selform.source.options[document.selform.source.selectedIndex].text + ':' + flag;
	  selval = document.selform.source.options[document.selform.source.selectedIndex].value + ':' + flag;
	  document.selform.target.options[document.selform.target.options.length] = new Option(seltext, selval);
	  document.selform.source.options[document.selform.source.selectedIndex] = null;
	  document.selform.target.options[0].selected = true;
	  if (document.selform.source.options[0] == null) {
		  return false;}
    else {
	    document.selform.source.options[0].selected = true;}
	}
}

function moveToRight() {
	var seltext;
	var selval;
  if (document.selform.source.options[0] == null) {
  	return false; }
  else {
	  seltext = document.selform.source.options[document.selform.source.selectedIndex].text;
	  selval = document.selform.source.options[document.selform.source.selectedIndex].value;
	  document.selform.target.options[document.selform.target.options.length] = new Option(seltext, selval);
	  document.selform.source.options[document.selform.source.selectedIndex] = null;
	  document.selform.target.options[0].selected = true;
	  if (document.selform.source.options[0] == null) {
		  return false;}
    else {
	    document.selform.source.options[0].selected = true;}
	}
}

function moveToLeft() {
	var seltext;
	var selval;
 
  if (document.selform.target.options[0] == null) {
  	return false; }
  else {
	  seltext = document.selform.target.options[document.selform.target.selectedIndex].text;
	  selval = document.selform.target.options[document.selform.target.selectedIndex].value;
	  document.selform.source.options[document.selform.source.options.length] = new Option(seltext, selval);
	  document.selform.target.options[document.selform.target.selectedIndex] = null;
	  document.selform.source.options[0].selected = true;
	  if (document.selform.target.options[0] == null) {
		  return false;}
    else {
	    document.selform.target.options[0].selected = true;}
	}
}
	
function concatVal() {
	var len = document.selform.target.options.length;
	for (i = 0;i<len;i++) {
		if (i == 0) {
			document.selform.ccat.value = document.selform.ccat.value +
							document.selform.target.options[i].value;}
		else {
			document.selform.ccat.value = document.selform.ccat.value + ',' +
							document.selform.target.options[i].value;}
	}	
}

function askDelete(desc, id) {
  var agree=confirm("Delete " + desc + "?");
  if (agree) {
    document.deleteRow.RID.value = id;
    document.deleteRow.submit();}
}

function newScreen() {
  index_scr = document.admscreen.screens.selectedIndex;
  scr = document.admscreen.screens.options[index_scr].value;
  document.location.href=scr;
}

function checkRequired () {
	ready = 1;
  if (document.cust_profile.cust_firstname.value == "" ||
      document.cust_profile.cust_lastname.value == "" ||
      document.cust_profile.cust_company.value == "" ||
      document.cust_profile.cust_division.value == "" ||
      document.cust_profile.cust_email.value == "" ||
      document.cust_profile.cust_phone.value == ""){
   	alert ("Please fill-in required fields.");
		ready = 0;}
  return ready;
}

function checkPasswd() { 
  ready = 1;
  if (document.change_passwd.cust_opasswd.value == "") {
   	alert ("Please enter your OLD password.");
   	document.change_passwd.cust_opasswd.focus();
		ready = 0;}
  else if (document.change_passwd.cust_npasswd.value == "" || document.change_passwd.cust_cpasswd.value == "") {
   	alert ("Please enter a new password.");
   	document.change_passwd.cust_npasswd.focus();
		ready = 0;}
  else if (document.change_passwd.cust_npasswd.value != document.change_passwd.cust_cpasswd.value) {
  	alert ("Your new passwords do not match.  Please try again");
  	document.change_passwd.cust_npasswd.value = "";
  	document.change_passwd.cust_cpasswd.value = "";
  	document.change_passwd.cust_npasswd.focus();
  	ready = 0;}
  if (ready == 1) {
    document.change_passwd.submit();}
}

function upAdd() { 
  addWin=window.open("","addWindow","menubar=no,width=650,height=300,alwaysRaised=yes,dependent=yes");
  addWin.document.location.href="tsaddchange";
}

function longWin(app) { 
  longWin=window.open("","longWindow","menubar=no,width=700,height=300,alwaysRaised=yes,dependent=yes");
  longWin.document.location.href=app;
}

function medWin(app) { 
  medWin=window.open("","mediumWindow","menubar=no,width=550,height=300,alwaysRaised=yes,dependent=yes");
  medWin.document.location.href=app;
}

function smWin(app) { 
  smWin=window.open("","smallWindow","menubar=no,width=450,height=300,alwaysRaised=yes,dependent=yes");
  smWin.document.location.href=app;
}

function appWin(app) { 
	appWin=null;
  appWin=window.open("","appWindow","menubar=no,width=450,height=290,alwaysRaised=yes,dependent=yes");
  appWin.document.location.href=app;
}

function checkForm () {
	ready = 1;
	ready = checkRequired();
	if (ready == 1) {
    // Check that passwords match
  	if (document.cust_profile.cust_login.value == "") {
   		alert ("Please provide a login name.");
			ready = 0;} 
	  else if (document.cust_profile.cust_passwd.value == "") {
	   	alert ("Please enter a password.");
	   	document.cust_profile.cust_passwd.focus();
			ready = 0;}
	  else if (document.cust_profile.cust_passwd.value != document.cust_profile.cust_cpasswd.value) {
	  	alert ("Your passwords do not match.");
	  	document.cust_profile.cust_passwd.value = "";
	  	document.cust_profile.cust_cpasswd.value = "";
	  	document.cust_profile.cust_passwd.focus();
	  	ready = 0;}
  }
	// Check if using same address from mailing and physical
	checkAddresses();  
  if (ready == 1) {
  	document.cust_profile.submit();}
}

function profileAddSend() {
	checkAddresses();
  document.cust_profile.submit();
}

function profileUserSend() {
	ready = checkRequired();
	if (ready == 1) {
    document.cust_profile.submit();}
}

function checkAddresses () {
	// Check if using same address from mailing and physical
  if (document.cust_profile.cust_sameadd.checked) {
    document.cust_profile.cust_padd1.value = document.cust_profile.cust_madd1.value;
    document.cust_profile.cust_padd2.value = document.cust_profile.cust_madd2.value;
	  document.cust_profile.cust_padd3.value = document.cust_profile.cust_madd3.value;
    document.cust_profile.cust_pcity.value = document.cust_profile.cust_mcity.value;
    document.cust_profile.cust_pstate.value = document.cust_profile.cust_mstate.value;
    document.cust_profile.cust_pzip.value = document.cust_profile.cust_mzip.value;
	  document.cust_profile.cust_pcountry.value = document.cust_profile.cust_mcountry.value;}
}

function setLink () {
  index_link = document.links.linklist.selectedIndex;
  link = document.links.linklist.options[index_link].value;
}

function openWin() {
  setLink();
	if (link != "null") {
  	linkWindow=window.open("","link","");
  	linkWindow.focus();
  	linkWindow.location.href=link;
 		winopen = 1;}
}

function closelinkWin() {
  if (winopen == 1) {
    linkWindow.close();
    winopen = 0;}
}

// 30apr01 - rbb always open in new window.
function openLink() {
  setLink(); 
  if (link != "null") {
//    if (document.links.spawn.checked) {
      openWin();}
//    else {
//      document.location.href=link;}}
}

function countDown(appname){
 var timestr = "cleanUp('"+appname+"')"; 
 timerID=setTimeout(timestr,3000);
}

function cleanUp (appname){
 opener.location.href=appname;
 window.close();
}

function upVal()
{
  sindex = document.selform.target.options.selectedIndex;
  if (sindex > 0)
  {
  selval = document.selform.target.options[sindex].value;
	seltxt = document.selform.target.options[sindex].text;
	tmpindex = sindex;	
	document.selform.target.options[sindex].value = document.selform.target.options[sindex-1].value
	document.selform.target.options[sindex].text = document.selform.target.options[sindex-1].text
	document.selform.target.options[sindex-1].value = selval;
	document.selform.target.options[sindex-1].text = seltxt;
	document.selform.target.options.selectedIndex = sindex-1;
  }
}

function downVal()
{ 
  sindex = document.selform.target.options.selectedIndex;
  if (sindex < (document.selform.target.options.length - 1))
  {
  selval = document.selform.target.options[sindex].value;
	seltxt = document.selform.target.options[sindex].text;
	tmpindex = sindex;	
	document.selform.target.options[sindex].value = document.selform.target.options[sindex+1].value
	document.selform.target.options[sindex].text = document.selform.target.options[sindex+1].text
	document.selform.target.options[sindex+1].value = selval;
	document.selform.target.options[sindex+1].text = seltxt;
	document.selform.target.options.selectedIndex = sindex+1;
  }
}

function disp() {
  setHiddenVars();
  alert(document.selform.sortorder.value);
}
	
function sendQuote() {
  var mess = "";
  var fields = "";
  
  mess = "TIMSIS Ref#: " + document.rfq.refnum.value + "\n";
  mess = mess + "RFQ# : " + document.rfq.rfqnum.value + "\n\n";
  mess = mess + "Company : " + document.rfq.company.value + "\n";
  mess = mess + "Customer : " + document.rfq.contact.value + "\n";
  mess = mess + "Phone: " + document.rfq.phone.value + "\n";
  mess = mess + "Fax: " + document.rfq.fax.value + "\n";
  mess = mess + "E-mail: " + document.rfq.email.value + "\n\n";
  mess = mess + "Well/Project: " + document.rfq.well.value + "\n";
  mess = mess + "Submitted to: " + document.rfq.site.value + "\n";
  mess = mess + "Response Date: " + document.rfq.req_date.value;
  mess = mess + " " + document.rfq.req_time.value + "\n\n";
  
  for (i = 0; i < 5; i++) {
  	fields = "----------------------------------------------------------\n";	
    fields = fields + "Item " + (i + 1) + ": " + document.rfq.item[i].value + "\n";
    fields = fields + "Qty/Uom: " + document.rfq.qty[i].value + "\n";
    fields = fields + "Size : " + document.rfq.desc[i].value + "\n";
    fields = fields + "Delivery Location: " + document.rfq.dlocation[i].value + "\n";
    fields = fields + "Required FOB Point: " + document.rfq.fob[i].value + "\n";
    fields = fields + "Date needed: " + document.rfq.need_date[i].value;
    fields = fields + " " + document.rfq.need_time[i].value + "\n";
    fields = fields + "Comments: " + document.rfq.comment[i].value + "\n\n";
    document.mailquote.elements[i+6].value = fields;
    if (document.rfq.item[i].value == "") {
    	document.mailquote.elements[i+6].value = "";
    }
  }

  document.mailquote.sender.value = document.rfq.email.value;
  document.mailquote.subject.value = "Request for Quote #" + document.rfq.rfqnum.value;
  document.mailquote.message.value = mess;
  document.mailquote.submit();
}	

function closeWin (refresher) {
	opener.location.href=refresher; 
	window.close();
}