function getPLZ(cr_id_order_list_i_)
{
return cr_id_order_list_i_.substring(0,cr_id_order_list_i_.indexOf(",&nbsp;"));
}
function getCr_id(cr_id_order_list,i)
{
var start=cr_id_order_list[i].indexOf("&nbsp;<i><b>")+"&nbsp;<i><b>".length;
var cr_id=cr_id_order_list[i].substring(start,cr_id_order_list[i].indexOf("</b>, "));
if(cr_id.indexOf("span")>-1)
{
var start=cr_id.indexOf("\">")+"\">".length;
cr_id=cr_id.substring(start,cr_id.indexOf("</span>"));
}
return cr_id;
}
function getCr_id2(cr_id_order_list_i_)
{
var start=cr_id_order_list_i_.indexOf("&nbsp;<i><b>")+"&nbsp;<i><b>".length;
var cr_id=cr_id_order_list_i_.substring(start,cr_id_order_list_i_.indexOf("</b>, "));
if(cr_id.indexOf("span")>-1)
{
var start=cr_id.indexOf("\">")+"\">".length;
cr_id=cr_id.substring(start,cr_id.indexOf("</span>"));
}
return cr_id;
}

function is_blocked(cr_id_order_list_i_)
{
  if (typeof(cr_id_order_list_blocked)!='undefined'&&typeof(MASK_COURIER_BLOCK_BLOCKED)!='undefined') {
    if(MASK_COURIER_BLOCK_BLOCKED=="1") {
      cr_id = getCr_id2(cr_id_order_list_i_);
      for (var i = 0; i < cr_id_order_list_blocked.length; i++)
        if (cr_id_order_list_blocked[i] == cr_id)
          return true;
    }
  }
  return false;
}

var refresh_done=false;
function is_in_cr_id_order_list_customer(cr_sid)
{
for(var j=0;j<cr_id_order_list_customer.length;j++)
{
if(cr_id_order_list_customer[j]==cr_sid){
return true;
}
}
return false;
}
function update_cr_id_list(jb_id,ad_zipcode,hq_id_string)
{
var php_params="jb_id="+jb_id+"&zipcode="+ad_zipcode+"&hq_id_string="+hq_id_string;
if(jb_id=='')
php_params="zipcode="+getJobList(0,jl_ad_zipcode);
tempWin=mkPopupWin(
"function startReload()\n"+
"{\n"+
"  checkDone();\n"+
"  self.location.href=\"../jobs/get_couriers.php?"+php_params+"\";\n"+
"}\n"+
"\n"+
"//--"+">\n"+
"<\/script>\n"+
"<\/head>\n"+
"<body onLoad=\"startReload()\">\n"+
"  <table border=0 align=center height=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n"+
"    <tr>\n"+
"      <td align=center valign=center>\n"+
"        <b>Hole Daten...</b>\n"+
"      <\/td>\n"+
"    <\/tr>\n"+
"  <\/table>\n"+
"<\/body>\n"+
"<\/html>\n",0,0);
refresh_done=true;
}
var lfdNr=1;
function mk_cr_id_list_content(cr_id_order_list_no,jb_id,ad_zipcode)
{
var lfdNrStr="";
var content="";
var cr_id_order_list_length;
var customer_courier_list=false;
if(typeof(cs_jbedit_cr)!='undefined')
{
if(cs_jbedit_cr==1)
{
customer_courier_list=true;
}
}
if(cr_id_order_list_no==1)
cr_id_order_list_length=cr_id_order_list.length;
if(cr_id_order_list_no==2)
cr_id_order_list_length=cr_id_order_list2.length;
if(cr_id_order_list_length==0)
content="[Kein&nbsp;Eintrag&nbsp;vorhanden]";
var curPLZ="***START***";
var spacer="<tr><td><img src=\"../images/empty.gif\" width=\"1\" height=\"4\" alt=\" \"></td></tr>";
var cr_id_order_list_i_="";
for(i=0;i<cr_id_order_list_length;i++)
{
curBestAnchorStart="";
curBestAnchorEnd="";
curSelectedStart="";
curSelectedEnd="";
if(cr_id_order_list_no==1)
cr_id_order_list_i_=cr_id_order_list[i];
if(cr_id_order_list_no==2)
cr_id_order_list_i_=cr_id_order_list2[i];
if(cr_id_order_list_i_.substr(0,1)=="#")
{
content=content+spacer+spacer+
"<tr><td align=left valign=center>"+
cr_id_order_list_i_.substr(1)+
"<hr>\n"+
"<\/td><\/tr>";
}else{
if(cr_id_order_list_i_.substr(0,1)=="*")
{
content=content+spacer+spacer+
"<tr><td align=left valign=center>"+
cr_id_order_list_i_.substr(1)+
"<\/td><\/tr>";
}else{
if(!customer_courier_list||(customer_courier_list&&is_in_cr_id_order_list_customer(getCr_id2(cr_id_order_list_i_))))
{
if(curPLZ!=getPLZ(cr_id_order_list_i_)&&jb_id!="")
{
content=content+spacer;
curPLZ=getPLZ(cr_id_order_list_i_);
}
var jb_id_param="";
if(jb_id!=''&&ad_zipcode!='')
jb_id_param="'"+jb_id+"',";
lfdNrStr=lfdNr.toString();
if(lfdNr<10)
lfdNrStr="0"+lfdNrStr;
lfdNr++;
var cr_id_order_list_i_temp = "";
cr_id_order_list_i_temp = cr_id_order_list_i_.replace(/\*/,"");
if(customer_courier_list){
cr_id_order_list_i_temp = cr_id_order_list_i_temp.replace(/<a href="javascript:popupWindow\('\.\.\/admin\/jb_detail\.php\?job_id=[0-9]+','Auftrag','scrollbars=yes,width=800,height=500'\);">/g,"");
//cr_id_order_list_i_temp = cr_id_order_list_i_temp.replace(/<\/span><\/i><\/a>/,"</span></i>");
}
content=content+curBestAnchorStart+
"<tr><td align=left valign=center>"+lfdNrStr+". &nbsp;"+
"<a href=\"../locating/locating.php?f_cr_sid="+getCr_id2(cr_id_order_list_i_)+"\" target=\"_blank\">"+"O"+"<\/a>"+
"&nbsp;&nbsp;&nbsp;"+
(is_blocked(cr_id_order_list_i_) ? "" : 
"<a href=\"javascript:setCourier("+jb_id_param+"'"+getCr_id2(cr_id_order_list_i_)+"');\">")+
curBestAnchorStart + curSelectedStart + cr_id_order_list_i_temp + curSelectedEnd + curBestAnchorEnd + "<\/a>"
"\n"+
"<\/td><\/tr>";
}
}
}
}
content=content+spacer+spacer;
return content;
}
function mk_cr_id_list(jb_id,ad_zipcode,hq_id_string)
{
var widthPopupWin=1012;
var heightPopupWin=700;
var leftPopupWin=(screen.width / 2)-(widthPopupWin / 2)-5;
var topPopupWin=(screen.height / 2)-(heightPopupWin / 2)-50;
var popupWin;
var content="";
var curSelectedStart="";
var curSelectedEnd="";
var curBest="";
var curBestAnchorStart="";
var curBestAnchorEnd="";
if(auto_refresh=="0"&&jb_id!=''&&ad_zipcode!=''){
if(!refresh_done){
update_cr_id_list(jb_id,ad_zipcode,hq_id_string);
return;
}else{
refresh_done=false;
}
}
lfdNr=1;
content=content+mk_cr_id_list_content(1,jb_id,ad_zipcode);
if(MASK_COURIER_SORT_BY_OCCUPIED=="1")
{
content=content+mk_cr_id_list_content(2,jb_id,ad_zipcode);
}
setCourierFunction_vht_id_str="vht_id_str = new Array();\n";
for(var _cr_sid_ in vht_id_str)
setCourierFunction_vht_id_str=setCourierFunction_vht_id_str+"vht_id_str[\""+_cr_sid_+"\"] = \""+vht_id_str[_cr_sid_].replace(/\n\n/,"\\n\\n")+"\";\n";
setCourierFunction=
"function setCourier(jb_id,cr_sid)\n"+
"{\n"+
setCourierFunction_vht_id_str+
"  addmsg = vht_id_str[cr_sid];\n"+
"  var penalty = 0;\n"+
"  if (this.document.reset_cr_availabletime_form.reset_cr_availabletime.checked) {\n"+
"    addmsg = \"\\n(Freimeldezeit von \" + this.document.reset_cr_availabletime_form.cur_cr_sid.value + \" wird aktualisiert)\" +  addmsg;\n"+
"    penalty = 1;\n"+
"  }"+
"  if (confirm(\"Kurier \" + cr_sid + \" dem Auftrag \" + jb_id + \" zuweisen?\" + addmsg)) {\n"+
"    this.opener.setCourier(jb_id,cr_sid,penalty);\n"+
"    self.close();\n"+
"  };\n"+
"};\n";
if(jb_id==''||ad_zipcode=='')
{
setCourierFunction=
"function setCourier(cr_sid)\n"+
"{\n"+
"  opener.parent.job_options.document.tourOptions.cr_id_order.value = cr_sid;\n"+
"  opener.parent.job_options.document.tourOptions.cr_id_order_hidden.value = cr_sid;\n"+
"  self.close();\n"+
"  opener.checkCr_id_order();\n"+
"  opener.parent.job_options.document.forms.tourOptions.cr_id_order.focus();\n"+
"};\n";
if(ad_zipcode=='calculator')
setCourierFunction=
"function setCourier(cr_sid)\n"+
"{\n"+
"  opener.cur_popupWin.document.forms[0].tmp_add_sid.value = cr_sid;\n"+
"  self.close();\n"+
"  opener.cur_popupWin.document.forms[0].tmp_add_sid.focus();\n"+
"};\n";
}
    if (ad_zipcode.substring(0, 11) == 'cr_id_order')
      setCourierFunction =
        "function setCourier(cr_sid)\n" +
        "{\n" +
        "  opener.parent.job_options.document.getElementsByName('" + ad_zipcode + "')[0].value = cr_sid;\n" + 
        "  opener.saveCr_id_order(" + ad_zipcode.substring(11) + ");\n" +
        "  opener.parent.job_options.document.getElementsByName('" + ad_zipcode + "')[0].focus();\n" +
        "  self.close();\n" +
        "};\n";
heightPopupWin+=8;
popupWin=window.open("about:blank","",
"dependent=yes,width="+widthPopupWin+",height="+heightPopupWin+
",left="+leftPopupWin+",top="+topPopupWin+",scrollbars=yes");
popupWin.document.open();
popupWin.document.writeln(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"+
"<html lang=\"de\">\n"+
"<head>\n"+
"<meta http-equiv=\"pragma\" content=\"no-cache\">\n"+
"<meta http-equiv=\"expires\" content=\"0\">\n"+
"<title>votian: Auftragserfassung - Liste der Transporteure<\/title>\n"+
"<link rel=\"stylesheet\" type=\"text/css\" href=\"../css/phoenix.css.php\">\n"+
"<script type=\"text/javascript\">\n"+
"<!-"+"-\n"+
"function reloadMe() {\n"+
"  opener.setTimeout(\"mk_cr_id_list('"+jb_id+"' , '"+ad_zipcode+"' , '"+hq_id_string+"')\",100);\n"+
"  self.close();\n"+
"}\n"+
"// Opens a new (popup-)window with specified parameters\n"+
"function popupWindow(url,title,config) {\n"+
"  popup = window.open(url,title,config);\n"+
"}\n"+
setCourierFunction+
"\n"+
"-"+"->\n"+
"<\/script>\n"+
"<\/head>\n"+
"<body bgcolor=\"#FFFFFA\" leftmargin=\"1\" topmargin=\"1\" marginwidth=\"0\" marginheight=\"0\" link=\"#990000\" vlink=\"#990000\" alink=\"#990000\">\n"+
"  <table border=0 align=center width=100% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n"+
"    <tr>\n"+
"      <td align=center valign=center>\n"+
"      &nbsp;<\/td>\n"+
"    <\/tr>\n"+
"    <tr>\n"+
"      <td align=center valign=center>\n"+
"  <table border=2 align=center width=96% cellspacing=0 cellpadding=0 vspace=0 hspace=0 bgcolor=\"#FFFFFF\">\n"+
"    <tr>\n"+
"      <td align=center valign=center>\n"+
"  <table border=0 align=center width=96% cellspacing=0 cellpadding=0 vspace=0 hspace=0>\n"+
content+
"  <\/table>\n"+
"      <\/td>\n"+
"    <\/tr>\n"+
"  <\/table>\n"+
"      <\/td>\n"+
"    <\/tr>\n"+
"  <\/table>\n"+
"<\/body>\n"+
"<\/html>\n");
popupWin.document.close();
}
