function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=315,left = 200,top = 160');");
}
function popup_equipmentRFI(listingKey,leadKey) {
        winView = 'titlebar=no,status=no,location=no,toolbar=no,resizable=no,scrollbars=yes,directories=no,screenX=0,screenY=0,height=500,width=460,left=0,top=0,innerHeight=500,innerWidth=460';
        window.open('/_equipment/popup_request.jsp?key=' + listingKey + '&leadKey=' + leadKey, 'popup_request', winView).focus();
}

function popup_equipmentWant() {
        winView = 'titlebar=no,status=no,location=no,toolbar=no,resizable=yes,scrollbars,directories=no,screenX=0,screenY=0,height=500,width=600,left=0,top=0,innerHeight=820,innerWidth=600';
        window.open('/_equipment/want.jsp', 'popup_want', winView).focus();
}

function popup_partsRFI(listingKey,mode) {
        winView = 'titlebar=no,status=no,location=no,toolbar=no,resizable=no,scrollbars=yes,directories=no,screenX=0,screenY=0,height=500,width=460,left=0,top=0,innerHeight=500,innerWidth=460';
        window.open('/parts/popup_request.jsp?key=' + listingKey + '&mode=' + mode, 'popup_request', winView).focus();
}

function popup_partWant() {
        winView = 'titlebar=no,status=no,location=no,toolbar=no,resizable=yes,scrollbars,directories=no,screenX=0,screenY=0,height=500,width=600,left=0,top=0,innerHeight=820,innerWidth=600';
        window.open('/parts/want.jsp', 'popup_want', winView).focus();
}
function validateEquipFF() {
        if ((document.equipmentFF.makeSearch.value.length == 0) &&
            (document.equipmentFF.modelSearch.value.length == 0)) {
		alert("Please fill out Make and/or Model details to find equipment");
		return;
	}
	document.equipmentFF.submit();
}
function validatePartsFF() {
        if ((document.partsFF.makeSearch.value.length == 0) &&
            (document.partsFF.modelSearch.value.length == 0) &&
            (document.partsFF.partNoSearch.value.length == 0)) {
		alert("Please fill out Make/Model or enter a Part # to find parts and attachments");
		return;
	}
	document.partsFF.submit();
}

function postT ()
{

  var f = window.document['searchBar'];

  // Get the currently selected region.
  var reg = f.region.options[f.region.selectedIndex].value;
  
  var stat = f.status.options[f.status.selectedIndex].value;

  // Replace any instance of / with $.
  reg = reg.replace ('/', '$');

  // Go to that URL.
  window.location = '/equipment/' + stat + '/' + reg;

}

function locationPopup (key)
{

  window.open ('getLocations.html?sKey=' + key,
               '_blank',
               'height=300,width=500,scrollbars');

}

function contactPopup (key)
{

  window.open ('getContacts.html?sKey=' + key,
               '_blank',
               'height=300,width=300');

}

function setContact (key,
                     name)
{

  window.opener.document.bdform.contact.value = name;
  window.opener.document.bdform.contactK.value = key;
  window.close ();

}

function checkLocation ()
{

  var f = window.document.locs;

  if ((f.town.value == '')
      &&
      (f.state.value == '')
      &&
      (f.postcode.value == '')
      &&
      (f.country.value == '')
      )
  {

      window.alert ("Please complete at least 1 field.");
      return false;

  }

  return true;

}

function setLocation (key,
                      name)
{

  window.opener.document.bdform.location.value = name;
  window.opener.document.bdform.locationK.value = key;
  window.close ();

}

function popup_BDListing(listingKey) {
        winView = 'titlebar=no,status=no,location=no,toolbar=no,resizable=yes,scrollbars=yes,directories=no,height=400,width=620';
        window.open('/directory/popup_detail.jsp?bdlKey=' + listingKey, 'popup_bdlist', winView).focus();
}

function selectAllCheckBoxesInForm (formName,
                                    namePrefix)
{

  var f = window.document[formName];
  var cBox = f[namePrefix + 'checked'];

  var v = false;

  if (cBox.checked)
  {

    v = true;

  }

  //f['item-checked'].checked = false;

  for (var i = 0; i < f.elements.length; i++)
  {

    var el = f.elements[i];

    if (el.type == 'checkbox')
    {

      if (el.name.indexOf (namePrefix) == 0)
      {

	el.checked = v;

      }

    }

  }

}

function validateSubscriberMailerForm (formName,
                                       from,
                                       subject,
                                       body,
                                       emailPrefix)
{

  var f = window.document[formName];

  if ((f[from].value == '') 
      || 
      (f[subject].value == '') 
      || 
      (f[body].value == '')
     )
  {

     window.alert ('Please ensure that the From, Subject line and Body are completed.');
     return false;

  }

  var cCount = 0;

  for (var i = 0; i < f.elements.length; i++)
  {

    var el = f.elements[i];

    if (el.type == 'checkbox')
    {

      if (el.name.indexOf (emailPrefix) == 0)
      {

	if (el.checked)
        {

	  cCount++;

	}

      }

    }

  }  

  if (cCount == 0)
  {

    window.alert ("Please ensure that at least 1 subscriber is selected.");
    return false;

  }

  return true;

}

function supportedBrowser() 
{

   var v = navigator.appVersion;
   
   if ((v.indexOf("MSIE 5") > -1) 
       || (v.indexOf("MSIE 6") > -1)
      ) 
   {

      return true;

   }

   return false;

}

function launchV2Service (service)
{

   if (!supportedBrowser ()) 
   {

      window.alert ("The advanced features of EquipmentRoad Discovery requires Internet Explorer Version 5 or above.");
      return;

   }
  
   window.open('/discovery/launchDiscoveryService.html?id=' + service,
               '_discovery',
               'width=790,height=500').focus();

}
