fcs_css_even={backgroundColor: '#EEEEEE'}
fcs_css_oneven={backgroundColor: '#CCCCCC'}
fcs_css_selected={backgroundColor: 'pink'}
fcs_css_unselected={backgroundColor: ''}
fcs_css_deleted={ 	backgroundColor:'#000', color:'#fff'    }
fcs_css_updated={display:'none',backgroundColor:'yellow'    }

function supplier_edit(keyvalue) {
	supplier_edit_gethtml(keyvalue);
}

function supplier_edit_complete(res) {
    //$.unblockUI();
    $.blockUI({ message: res,
      css: { 
	border:'none', padding:'15px', size:'12.0pt',
        Xopacity:'.3',
	'-webkit-border-radius': '10px','-moz-border-radius': '10px',
	cursor:'auto',
	textAlign: 'left'
      }
    });         
}

function supplier_edit_gethtml(keyvalue) {
    $.blockUI({ message: 'editing '+keyvalue+' ...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'supplier_edit',
            id: keyvalue,
            sid: $('input#sid').get(0).value
            },
            supplier_edit_complete );       
    }
    return checkresult;
}

function region_show(sregionk,slang) {

	var mykey='region_'+sregionk+'.'+slang;
	var mydesc='REGD'+(slang=='it' ? '' : '_'+slang);

	//gets REGION name in given language
   if (false) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_read_field',
            tid: 'region',
            kid: 'regk',
            id: sregionk,
            fid: mydesc,
            sid: $('input#sid').get(0).value
            },
            function(a){
		$('#fcs_product_out').html('<h4>'+a+'</h4>');
	    } 
	);       
   }

 	var a = $.ajax({
		  url: "all_srv.asp?type=record_read_field&tid=region&kid=regk&id="+sregionk+"&fid="+mydesc+"&sid="+$('input#sid').get(0).value,
		  async: false
		 }).responseText;
	$('#fcs_product_out').html('<h4>'+a+'</h4>');

		var imgsrc="regions/icons/"+sregionk+".jpg";
		var b="<img class=fcs_product_region border=0 src='" +imgsrc+ "' />";
		$('#fcs_product_out').append(b);

	//gets REGION description
        $.post('/web/bla/all_srv.asp', {
            type: 'record_read_field',
            tid: 'mymessage',
            kid: 'metitle',
            id: mykey,
            fid: 'metext',
            sid: $('input#sid').get(0).value
            },
            function(a){
		$('#fcs_product_out').append(a);
	    } 
	);       
}

function article_new() {
	record_addnew('article','artcode','01-0112');
}

function article_edit(artcode) {
	record_edit('article','artcode',artcode);
}

function OLDarticle_edit(artcode) {
	article_edit_gethtml( artcode );
        //setTimeout($.unblockUI, 2000); 
}

function article_edit_gethtml_complete(res) {
    //$.unblockUI();
    $.blockUI({ message: res,
      css: { 
	border:'none', padding:'15px', size:'12.0pt',
        xheight:'800px',position:'absolute',top:'0px',
	'-webkit-border-radius': '10px','-moz-border-radius': '10px',
	cursor:'auto',
	textAlign: 'left'
      }
    });         
}

function article_edit_gethtml( artcode ) {
    //$('#fcs_data').html('loading article '+artcode+' ...');
    $.blockUI({ message: 'edit article '+artcode+' ...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'article_edit',
            id: artcode,
                 sid: $('input#sid').get(0).value
            },
            article_edit_gethtml_complete );       
    }
    return checkresult;
}

function article_show_more( artcode ) {
//    $.blockUI({ message: 'reading '+artcode+' ...'});         
//$('#fcs_product_out').html('loading '+artcode+' ...');
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'article_show_more',
            id: artcode,
                 lang: $('#fcs_lang').get(0).value,
                 sid: $('input#sid').get(0).value
            },

function(res) {
    //$.unblockUI();
  if(false){
    $.blockUI({ message: res,
      css: { 
	border:'none', padding:'15px', size:'12.0pt',
        height:'800px',position:'absolute',top:'0px',
	'-webkit-border-radius': '10px','-moz-border-radius': '10px',
	cursor:'auto',
	textAlign: 'left'
      }
    });         
  }
    $('#fcs_product_out').html(res);
}

        );       
    }
    return checkresult;
}

var lastartcode=null

function article_delete(artcode) {
    lastartcode=artcode
    checkresult=confirm("Confirm delete of "+artcode);
    if(checkresult) {
//      $.blockUI({ message: 'deleting '+artcode+' ...',
//      css: { 
//       border:'none', padding:'15px', size:'12.0pt',
//       opacity:'.8','-webkit-border-radius': '10px','-moz-border-radius': '10px'
//      }
//      });         
        $.post('/web/bla/all_srv.asp', {
            type: 'record_delete',
            subtype: 'updatelist',
            tid: 'article',
            kid: 'artcode',
            id: artcode,
            sid: $('input#sid').get(0).value
            },
		function (res) {
		    $('#'+lastartcode).html(res);
		//    $.unblockUI();
		}
	);       
    }
    return checkresult;
}

function article_undelete(artcode) {
    lastartcode=artcode
    checkresult=confirm("Confirm undo delete of "+artcode);
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_delete',
            subtype: 'updatelist',
            tid: 'article',
            kid: 'artcode',
            id: artcode,
            sid: $('input#sid').get(0).value
            },
		function (res) {
		    $('#'+lastartcode).html(res);
		}
	);       
    }
    return checkresult;
}

//GENERIC record manipulation

var lastkeyvalue=null;

function record_delete(tablename,keyname,keyvalue) {
  if (confirm('Do you really want to delete this ?')) {
    lastkeyvalue=keyvalue
    $.blockUI({ message: 'deleting '+keyvalue+' ...',
      css: { 
       xtextAlign: 'left',
       border:'none', padding:'15px', size:'12.0pt',
       xbackgroundColor:'#900', xcolor:'#fff',
       opacity:'.7','-webkit-border-radius': '10px','-moz-border-radius': '10px'
      }
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_delete',
            id: keyvalue,
            kid: keyname,
            tid: tablename,
            sid: $('input#sid').get(0).value
            },
            record_delete_complete );       
    }
    return checkresult;
  }
}

function record_delete_complete(res) {
    $('#'+lastkeyvalue).css(fcs_css_deleted);         
    $('#'+lastkeyvalue).html(res);
    $.unblockUI();
}

function record_addnew(tablename,keyname,keyvalue) {
    $.blockUI({ message: 'preparing to add a new '+tablename+' based on '+keyname+'='+keyvalue+'...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_edithtml',
            subtype: 'new',
            id: keyvalue,
            kid: keyname,
            tid: tablename,
                 lang: $('#fcs_lang').get(0).value,
                 sid: $('input#sid').get(0).value
            },
            record_edit_gethtml_complete );       
    }
    return checkresult;
}

function record_edit(tablename,keyname,keyvalue) {
	record_edit_gethtml(tablename,keyname,keyvalue);
}

function record_editgeo(tablename,keyname,keyvalue) {
	record_editgeo_gethtml(tablename,keyname,keyvalue);
}

function record_edit_gethtml_complete(res) {
    $.blockUI({ message: res,
      css: { 
	top:'30px',
	left:'15%',
	width:'60%',
	height:'80%',
	overflow:'auto',
	border:'none', padding:'15px', size:'12.0pt',
        xopacity:'.3',
	'-webkit-border-radius': '10px','-moz-border-radius': '10px',
	cursor:'auto',
	textAlign: 'left'
      }
    });         
    //enable RTE fields
    //$('.rte-zone').rte("/web/bla/bladenis.css", "/web/bla/rte/");
    //-20090813 setTimeout(jq_async, 2000); 
}

function jq_async() {
    $('.rte-zone').rte("/web/bla/bladenis.css", "/web/bla/rte/");
    $('#SUPDESCL').rte("/web/bla/bladenis.css", "/web/bla/rte/");
    $('#SUPDESCL_NL').rte("/web/bla/bladenis.css", "/web/bla/rte/");
    $('#SUPDESCL_EN').rte("/web/bla/bladenis.css", "/web/bla/rte/");
}

function record_edit_gethtml(tablename,keyname,keyvalue) {
    $.blockUI({ message: 'preparing to edit '+keyvalue+'|'+keyname+'|'+tablename+' ...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_edithtml',
            id: keyvalue,
            kid: keyname,
            tid: tablename,
                 lang: $('#fcs_lang').get(0).value,
                 sid: $('input#sid').get(0).value
            },
            record_edit_gethtml_complete );       
    }
    return checkresult;
}

function record_editgeo_gethtml(tablename,keyname,keyvalue) {
    $.blockUI({ message: 'preparing to edit position of '+keyvalue+'|'+keyname+'|'+tablename+' ...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_editgeohtml',
            id: keyvalue,
            kid: keyname,
            tid: tablename,
                 sid: $('input#sid').get(0).value
            },
function record_edit_complete(res) {
    $.blockUI({ message: res,
      css: { 
top:'30px',
left:'15%',
width:'60%',
height:'600px',
overflow:'auto',
	border:'none', padding:'15px', size:'12.0pt',
        xopacity:'.3',
	'-webkit-border-radius': '10px','-moz-border-radius': '10px',
	cursor:'auto',
	textAlign: 'left'
      }
    });         
}
            
	);       
    }
    return checkresult;
}

function record_select(recid){
  $("#go").click(function(){
    $('#'+recid).animate( { backgroundColor: 'pink' }, 1000)
      .animate( { backgroundColor: 'blue' }, 1000);
  });
}

function record_selected(recid,bchecked){
  if(bchecked){
    $('#'+recid).css(fcs_css_selected);
  } else {
    $('#'+recid).css(fcs_css_unselected);
  };
}

function record_updated(recid){
    $('#'+recid).css(fcs_css_updated);
}

function record_settoken(tokenValue,bchecked,sTargetJQuerySel) {
  var s=""
  s+=tokenValue;
  if (bchecked) {
   $(sTargetJQuerySel).val(fcs_token_add( $(sTargetJQuerySel).get(0).value, s));
  } else {
   $(sTargetJQuerySel).val(fcs_token_delete( $(sTargetJQuerySel).get(0).value, s));
  }
}

function record_update_multikey(tablename,keyname,skeylist,stargetfield,sinputfieldid){
    var atokens = $('#'+skeylist).get(0).value.split(";");
    var o=""
  for (var i=0;i<atokens.length;i++) {
    s=atokens[i];
    if (s!="") {
      o+=(s+" "+"<br />");
	record_updated(s);
    }
  }
  //alert(o);
    $.blockUI({ message: 'preparing to edit '+$('#'+skeylist).get(0).value+'|'+keyname+'|'+tablename+' ...'
    });         
    checkresult=true;
    if(checkresult) {
        $.post('/web/bla/all_srv.asp', {
            type: 'record_update_multikey',
            id: $('#'+skeylist).get(0).value,
            kid: keyname,
            tid: tablename,
            oid: stargetfield,
            ov: $('#'+sinputfieldid).get(0).value,
            sid: $('input#sid').get(0).value
            },
            function(res){$.blockUI({ message:(res)});$('#'+skeylist).val('');setTimeout($.unblockUI,1000);} 
	);       
    }
    return checkresult;
}


// from FCS

var fcs_fieldsep=";"

function fcs_token_add(sInput,sToken) {
  var s=sInput;
  if (s.indexOf(fcs_fieldsep+sToken+fcs_fieldsep)==-1) {
    if (s=="") {s=fcs_fieldsep}
    s=s+sToken+fcs_fieldsep;
  }
  return(s);
}

function fcs_token_add_f(sInput,sToken,fCallBackAdd) {
  var s=sInput;
  if (s.indexOf(fcs_fieldsep+sToken+fcs_fieldsep)==-1) {
    if (s=="") {s=fcs_fieldsep}
    s=s+sToken+fcs_fieldsep;
    fCallBackAdd();
  }
  return(s);
}

function fcs_token_delete(sInput,sToken) {
  var s=sInput;
  var n=-1;
  if ((n=s.indexOf(fcs_fieldsep+sToken+fcs_fieldsep))!=-1) {
    s=s.substr(0,n)+s.substr(n+sToken.length+1)
  }
  if (s==fcs_fieldsep) {s=""}
  return(s);
}


//

$(document).ready(function() {
 $(window).keydown(function(event){
  //alert (event.keyCode);
    // ...
    // different keys do different things
    // Different browsers provide different codes
    // see here for details: http://unixpapa.com/js/key.html    
    // ...
  if (event.keyCode==27) {$.unblockUI();} //ESC unblocks UI
 });


  $("#all_product_toggle").click(function(){
//alert('pippo');
    $('#formular').toggle();
    //$('#articlegroup1').show('slow');
  });

});




