function confirm_delete(name){
 return confirm ("Are you sure that you want to delete \r\n" + name + " ?");
}

function send_data(return_to,params){ // POST method

      //  alert (params);
     document.getElementById('loading').style.display = 'block';

     var timeval = new Date().getTime();
//         var http = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
     var http;
     try {
        http = new ActiveXObject('Msxml2.XMLHTTP');
     }catch (e){
            try {
                   http = new ActiveXObject('Microsoft.XMLHTTP');
            }catch (e2){
                try {
                   http = new XMLHttpRequest();
                }catch (e3) {
                   http = false;
                }
            }
     }
     if (!http){
         alert('Couldn\'t initializate object in your browser.');
         return false;
     }

     var url = HOST_PATH + "jsfunctions.php?timeval=" + timeval;

     http.open("POST", url, true);

     //Send the proper header information along with the request
     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http.setRequestHeader("Content-length", params.length);
     http.setRequestHeader("Connection", "close");

     //Call a function when the state changes.
     http.onreadystatechange = function() {
             if(http.readyState == 4 && http.status == 200){
                   // alert(http.responseText);
                  if (return_to == 'eval'){

                      eval(http.responseText);

                  }else if (return_to != 'nothing'){

                      document.getElementById(return_to).innerHTML = http.responseText;
                  }
                  document.getElementById('loading').style.display = 'none';

                  http = null;
                  url = null;
             }
     }
     http.send(params);
     return false;
}

function cm_over(obj,color){

    obj.style.backgroundColor = color ? color : '#DDDDDD';
}
function cm_out(obj,color){

    obj.style.backgroundColor  = color ? color: '#FFFFFF';
}

/* ********************************* member list functions ******************************** */
var first_loading = false;
function update_weight(name,weight,project_id){

    if (!first_loading) send_data('eval','a=khelper&member_list=1&project_id=' + project_id + '&update_weight=' + name + '&weight=' + weight);
    return false;
}

function get_member_list(project_id,animation){

    send_data('eval','a=khelper&member_list=1&project_id=' + project_id + (animation ? '&first_time=1' : ''));
    return false;
}

function build_member_list(project_id,item_name,bar_id){

    send_data('eval','a=khelper&member_list=1&build_mlist='+ encodeURIComponent(item_name) +'&project_id=' + project_id + '&display_bar=' + bar_id);
    return false;
}

function select_member_list(project_id,obj,row_id){

    if (obj.checked){
         document.getElementById('keyword_' + row_id).className = 'checked_keyword';
    }else{
         document.getElementById('keyword_' + row_id).className = '';
    }

    send_data('eval','a=khelper&member_list=1&select_item='+ encodeURIComponent(obj.value) +'&project_id=' + project_id + ( obj.checked ? '&checked=1' : '') );
    return false;
}

function new_pbar(item_id,percent){

    manualPB2 = new JS_BRAMUS.jsProgressBar(
                $(item_id),
                percent,
                {
                    barImage    : Array(
                        '../img/bar_bg_red.png',
                        '../img/bar_bg_orange.png',
                        '../img/bar_bg_yellow.png',
                        '../img/bar_bg_green.png'
                    )
                }
            );

}

function change_keywords_limit(direction,project_id){

    send_data('eval','a=khelper&member_list=1&change_limits='+ direction +'&project_id=' + project_id);
    return false;
}
/** project summary info */

function get_project_summary(project_id){


    send_data('project_summary','a=projects&mod=summary&project_id=' + project_id);
    return false;
}

/* ************************** content help ********************************** */

/** content help for keyphrases
*/
function kw_help(obj,project_id){

    show_help(obj,'a=khelper&keyword_info=' + encodeURIComponent(obj.innerHTML.replace("&amp;","&")) + '&project_id=' + project_id);
    return false;
}

function hide_help(){

     document.getElementById('content_help').style.display = 'none';
     document.getElementById('content_help').innerHTML = '';
     return false;
}
function show_help(link_obj,params){

          x = findPosX(link_obj);
          y = findPosY(link_obj);

          w = getWindowSize();
          s = getScrollXY();

         if (x - s[0] +200 > w[0]){ // left oriented

             document.getElementById('content_help').style.top = (y+20)+'px';
             document.getElementById('content_help').style.left = (x-220)+'px';

         }else{ // right oriented

             document.getElementById('content_help').style.top = (y+20)+'px';
             document.getElementById('content_help').style.left = (x+20 )+'px';
         }

         send_data ('content_help', (params ? params :''));

         document.getElementById('content_help').style.display = 'block';
     return false;
}

function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;

    return curleft;
}
function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  return [ myWidth, myHeight ];

}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


/******************  end content help *******/

function check_project_status(project_id){

    if (check_status){

         send_data('eval','a=khelper&check_status=1&project_id=' + project_id);
         setTimeout("check_project_status(" + project_id + ")",60000);
    }
    return true;
}

function clipboard(obj_name,html){

  if (html){
   text = document.getElementById(obj_name).innerHTML;
  }else{
   text = document.getElementById(obj_name).value;
  }
  copyToClipboard(text);
  return false;
}


function copyToClipboard(text2copy) {
/*      if (window.clipboardData) {
        window.clipboardData.setData("Text",text2copy);
      } else {
*/
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="'+ HOST_PATH +'js/clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="30" height="30" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
//      }
}

/** get csv,txt,xml button */
function update_get_links(action, type){

        var img_obj = document.getElementById('get_links_image');
        if (action == 'over'){
            img_obj.src = HOST_PATH + 'img/' + type + '-swap.png';
        }else{
            img_obj.src = HOST_PATH + 'img/' + 'file-links.png';
        }
}

/**
 * check all keywords on the  keywords list
 */
function check_all_keywords(checkbox){

    // obj.checked
    if (!$('member_list_area')) return false;
    var obj = $('member_list_area').descendants();
    var project_id = $F('project_id');

    if (checkbox.title == 'Unchecked'){

        checkbox_status = true;
        checkbox.title = 'Checked';

    }else{ //

        checkbox.title = 'Unchecked';
        checkbox_status = false;
    }

    for (i=0;i<obj.length;i++){

        if (obj[i].name && obj[i].name.indexOf('project_keyword') > -1){ // field found

             obj[i].checked = checkbox_status;

             parts = obj[i].name.split('_');
             select_member_list(project_id,obj[i],parts[2]);
        }
    }
    return false;
}

function ShowVideos(){
    var videoString;
    $("#homeVid").empty();
        var s1 = new SWFObject(HOST_PATH + 'flash/video.swf', 'ply', '708', '458', '6', '#FFFFFF');
        s1.addParam('allowfullscreen', 'true');
        s1.addParam('allowscriptaccess', 'always');
        s1.addParam('wmode', 'opaque');
        s1.write('homeVid');

        //$('#homeVid').prepend("<p style=\"padding: 10px\">&nbsp;</p>"); //spacer for IE7
        $('#vidClick').attr("href", "#TB_inline?height=510&width=760&inlineId=homeVid");

    $('#vidClick').click(); // clicks thickbox link
}
function ShowVideos2(){
    var videoString;
    $("#homeVid").empty();
        var s1 = new SWFObject('/flash/kftraining.swf', 'ply', '1092', '802', '6', '#FFFFFF');
        s1.addParam('allowfullscreen', 'true');
        s1.addParam('allowscriptaccess', 'always');
        s1.addParam('wmode', 'opaque');
        s1.write('homeVid');

        //$('#homeVid').prepend("<p style=\"padding: 10px\">&nbsp;</p>"); //spacer for IE7
        $('#vidClick').attr("href", "#TB_inline?height=862&width=1152&inlineId=homeVid");

    $('#vidClick').click(); // clicks thickbox link
}
