//  v3.0
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//  v3.0
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//v4.0
function MM_findObj(n, d) {
  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 && document.getElementById) x=document.getElementById(n); return x;
}

//v3.0
function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// reloads the window if Nav4 resized
function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function imgRot(s,pt,tm) {
  document.images[s].src = eval(s)[pt].src;
  ++pt;  if ( !eval(s)[pt] ) { pt = 1 };
  setTimeout('imgRot(\"' + s + '\",' + pt + ',' + tm + ')',tm);
}

// Reset input field color when changed
function fldReset() { this.style.backgroundColor=''; this.style.borderColor='#bbbbbb'; }

// display error message, color error field, set 
function setErm(f,m) {
  alert(m);
  f.onchange = fldReset;
  f.style.backgroundColor="#ff9"; 
  f.style.borderColor="#f00"; 
  f.focus(); 
  return false;
}

function chkContact(s) {
   if (s.fname.value=='')		return setErm(s['fname'],	'You must enter your first name to continue.');
   if (s.lname.value=='')		return setErm(s['lname'],	'You must enter your last name to continue.');
   if (s.addr1.value=='')		return setErm(s['addr1'],	'You must enter your street address to continue.');
   if (s.city.value=='')		return setErm(s['city'],	'You must enter your city to continue.');
   if (s.state.value=='')		return setErm(s['state'],	'You must enter your state to continue.');
   if (s.zipcode.value=='')		return setErm(s['zipcode'],	'You must enter your Zip Code to continue.');
   if (s.email.value=='')		return true;
   if (s.email.value.indexOf('@')==-1)	return setErm(s['email'],'Your E-mail address appears to be invalid. Plaese check!');
   if (s.email.value.indexOf('.')==-1)	return setErm(s['email'],'Your E-mail address appears to be invalid. Plaese check!');
   return true;
}

function assignTrade(contractorid,tradeid) {
  window.open('admin_contractortrades_assign.php?contractorid='+contractorid+'&tradeid='+tradeid,'tradeassign','height=320,width=500,scrollbars,resizable'); return false; }

function editAlbum(projectid,picid) {
  window.open('admin_album_edit.php?projectid='+projectid+'&picid='+picid,'album','height=500,width=500,scrollbars,resizable'); return false; }

function editClient(clientid) {
  window.open('admin_clients_edit.php?clientid='+clientid,'client','height=560,width=500,scrollbars,resizable'); return false; }

function editContact(cid) {
  window.open('admin_contact.php?cid='+cid,'contact','height=550,width=730,scrollbars');
  return false;
}

function distCheck(s) {
  var sz = s['MM_EMAILTO[]'].length;
  if (sz==undefined) {
    if (s['MM_EMAILTO[]'].checked==true) {
      open_Broadcast();
      return true;
    }
  }
  else for (var i=0; i<sz; i++) if (s['MM_EMAILTO[]'][i].checked==true) { open_Broadcast(); return true; }
  alert("You must select at least 1 email recipent to continue.");
  return false;
}

function open_Broadcast() {
  window.open('','broadcast','height=500,width=500,scrollbars');
  return false;
}

function allClients() {
  var sz = document.distrib['MM_EMAILTO[]'].length;
  for (var i=0; i<sz; i++) document.distrib['MM_EMAILTO[]'][i].checked=true;
}

function editContractor(contractorid) {
  window.open('admin_contractors_edit.php?contractorid='+contractorid,'contractor','height=560,width=500,scrollbars,resizable'); return false; }

function editContrade(contractorid) {
  window.open('admin_contractortrades_edit.php?contractorid='+contractorid,'contractortrades','height=560,width=500,scrollbars,resizable'); return false; }

function editDoctype(doctypeid) {
  window.open('admin_doctypes_edit.php?doctypeid='+doctypeid,'doctype','height=500,width=500,scrollbars,resizable'); return false; }
  
function editDocument(projectid,doctypeid,documentid) {
  window.open('admin_documents_edit.php?projectid='+projectid+'&doctypeid='+doctypeid+'&documentid='+documentid,'document','height=500,width=500,scrollbars,resizable'); return false; }
  
function editLink(lid) {
  window.open('admin_links_edit.php?lid='+lid,'link','height=250,width=500,scrollbars,resizable'); return false; }
  
function editOrder(staffid) {
  window.open('admin_staff_order.php?staffid='+staffid,'order','height=250,width=400,scrollbars,resizable'); return false; }
  
function editProject(clientid,projectid) {
  window.open('admin_projects_edit.php?clientid='+clientid+'&projectid='+projectid,'document','height=500,width=500,scrollbars,resizable'); return false; }
  
function editStaff(staffid) {
  window.open('admin_staff_edit.php?staffid='+staffid,'staff','height=550,width=700,scrollbars,resizable'); return false; }

function edit_trade(tradeid) {
  window.open('admin_trades_edit.php?tradeid='+tradeid,'trade','height=240,width=500,scrollbars'); return false; }

function editAward(awid) {
  window.open('admin_awards_edit.php?awid='+awid,'award','height=240,width=500,scrollbars'); return false; }

function editTestimonials(tmid) {
  window.open('admin_testimonials_edit.php?tmid='+tmid,'trade','height=400,width=500,scrollbars'); return false; }
