// javascript for inclusion in 'lt3' template pages: node view, edit and history.

function show_another_clip(n) {
	var next = n + 1;
	// var butID = 'show_hide_button_' + n;
	// var secID = 'clip_sec_' + next;
	// alert( 'butID ' + butID + 'secID' + secID);
	/* Element.toggle('show_hide_button_' + n);  */
	Element.toggle('clip_sec_' + next);
	return(false);
}

    function delete_tag(item, tname, nid, tid, uid){
            URL = '../delete_tag/'+nid+'/'+tid+'/'+uid;            
            loadUrlInFrame(URL );
            // give visual feedback it's been deleted
            // use this line to hide it, the one below to strike it through
            //document.getElementById(item).style.visibility="hidden";

document.getElementById(item).style.textDecoration="line-through";
            // if we're striking through, hide the X which lets you delete it
            document.getElementById(item+'x').style.visibility="hidden";
            // Strike Through the tag under All Tags as well

document.getElementById(item+'a').style.textDecoration="line-through";
            return false;
    }

   function add_tag(nid) {
   	  var newtags = $F('newtags_'+nid);
//      alert(newtags);
   	  var theNewTags = $('your_taglist_'+nid);
      var pars = encodeURIComponent(newtags);
      new Ajax.Updater('your_taglist_'+nid,
         '../../../../add_tags/' + nid + '/'+pars,
        {
            method: 'get',
            parameters: pars
          });
//     make the newtags field the focus
    //tagfield = [object HTMLInputElement]
    var tagfield = $('newtags_'+nid);
    tagfield.value = '';
    tagfield.select();
//  Update the Main tags as well
    new Ajax.Updater('taglist_'+nid,
         '../../../../update_tags/' + nid,
         {
            method: 'get'
          });

   } 

   function add_tag_block(nid) {
   	  var newtags = $F('newtags_'+nid);
//      alert(newtags);
   	  var theNewTags = $('your_taglist_'+nid);
      var pars = encodeURIComponent(newtags);
      new Ajax.Updater('your_taglist_'+nid,
         '../../../../add_tags_block/' + nid + '/'+pars,
        {
            method: 'get',
            parameters: pars
          });
//     make the newtags field the focus
    //tagfield = [object HTMLInputElement]
    var tagfield = $('newtags_'+nid);
    tagfield.value = '';
    tagfield.select();
//  Update the Main tags as well
//    new Ajax.Updater('taglist_'+nid,
//         '../../../update_tags/' + nid,
//         {
//            method: 'get'
//          });
   }    
   
   
/*ajaxvote.module javascript */
/* Script via http://www.technorealm.co.uk/scripts/mouseovershowtext.html */
//function toggleDiv(id,flagit) {
//  if (flagit=="1"){
//    if (document.layers) document.layers[''+id+''].visibility = "show"
//    else if (document.all) document.all[''+id+''].style.visibility = "visible"
//    else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
//  } 
//  else if (flagit=="0") {
//    if (document.layers) document.layers[''+id+''].visibility = "hide"
//    else if (document.all) document.all[''+id+''].style.visibility = "hidden"
//    else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
//  }
// }

//--></script>


function submit_tags(evt, nid){
   evt = (evt) ? evt : event;
   var charCode = (evt.charCode) ? evt.charCode :
    ((evt.which) ? evt.which : evt.keyCode);
   if (charCode == 13 || charCode == 3) {
       add_tag(nid);
       return false;
   }
}

function submit_tags_block(evt, nid){
   evt = (evt) ? evt : event;
   var charCode = (evt.charCode) ? evt.charCode :
    ((evt.which) ? evt.which : evt.keyCode);
   if (charCode == 13 || charCode == 3) {
       add_tag_block(nid);
       return false;
   }
}


function make_mine(nid){
	// stupid IE shit
    if(window.event) {
    	window.event.returnValue = false;
    	window.event.cancelBubble = true;//stop the event being passed to higher level
    }
	//alert("make_mine(" + nid);
  	location.href =  "?q=sm_make_mine/"+nid;
    return false;
}

function make_not_mine(nid){
	// stupid IE shit
    if(window.event) {
    	window.event.returnValue = false;
    	window.event.cancelBubble = true;//stop the event being passed to higher level
    }
	//alert("make_not_mine(" + nid);
	location.href =  "?q=sm_make_not_mine/"+nid;
    //alert(URL);
   // loadUrlInFrame(URL );
   //alert ("This item is no longer in your media.");
    return false;
}

function flag_item(nid,reason){
    URL = 'flag_item/'+nid + '/' + reason;
    //alert(URL);
    loadUrlInFrame(URL );
    $('js_flag_button_messages').innerHTML = 'The entry has been flagged. Thanks!';
    new Effect.Appear('js_flag_button_messages');
    new Effect.Fade('js_flag_button_messages', { duration: 6.0 });
    if (reason == 'objectionable'){
        objectionable_flag('unflag');
    }
    if (reason == 'bad_link'){
        bad_link_flag('unflag');
    }
    return false;
}

function un_flag_item(nid,reason){
    URL = 'un_flag_item/'+nid + '/' + reason;
    //alert(URL);
    loadUrlInFrame(URL );
    $('js_flag_button_messages').innerHTML = 'The flag has been removed. Thanks!';
    new Effect.Appear('js_flag_button_messages');
    new Effect.Fade('js_flag_button_messages', { duration: 6.0 });
    if (reason == 'objectionable'){
        objectionable_flag('flag');
    }
    if (reason == 'bad_link'){
        bad_link_flag('flag');
    }
    return false;
}

function bad_link_flag(which){
    if (which == 'flag') {
        $('bad_link_flagger').style.visibility="visible";
        $('bad_link_flagger').style.display="block";
        $('un_bad_link_flagger').style.visibility="hidden"
        $('un_bad_link_flagger').style.display="none"
    }
    if (which == 'unflag') {
        $('un_bad_link_flagger').style.visibility="visible";
        $('un_bad_link_flagger').style.display="block";
        $('bad_link_flagger').style.visibility="hidden"
        $('bad_link_flagger').style.display="none"
    }
}

function objectionable_flag(which){
    if (which == 'flag') {
        $('obj_flagger').style.visibility="visible";
        $('obj_flagger').style.display="block";
        $('un_obj_flagger').style.visibility="hidden"
        $('un_obj_flagger').style.display="none"
    }
    if (which == 'unflag') {
        $('un_obj_flagger').style.visibility="visible";
        $('un_obj_flagger').style.display="block";
        $('obj_flagger').style.visibility="hidden"
        $('obj_flagger').style.display="none"
    }
}

function loadUrlInFrame(urlToLoad){
	var data_block = document.getElementById('tag_delete_response');

	//load new page
	data_block.src = urlToLoad;
	return false;
}

function bmo_description_form_submit(nid) {
	var theFormDiv = $('bmo_description_form_div');
	var theDesc = $('bmo_description');
	var theNewDesc = $F('bmo_description_textarea');
	theDesc.innerHTML = theNewDesc;

	theFormDiv.style.display='none';
	theDesc.style.display = '';

    var pars = 'newdesc=' + encodeURIComponent(theNewDesc);
    new Ajax.Updater('bmo_description_status',
    	 'jh_edit_media_description/' + nid + '/',
    	{
    		method: 'post',
    		parameters: pars,
    		onLoading:function(request){$('bmo_description_status').innerHTML = 'Updating...';},
	  	asynchronous:true
	  });

}

function bmo_description_form_cancel() {
	var theFormDiv = $('bmo_description_form_div');
	var theDesc = $('bmo_description');
	theFormDiv.style.display='none';
	theDesc.style.display = '';
}

function bmo_description_edit() {
	var theFormDiv = $('bmo_description_form_div');
	var theEditText = $('bmo_description_textarea');
	var theDesc = $('bmo_description');
	theDesc.style.display='none';
	theEditText.style.height = 100;
	theFormDiv.style.display = '';
}

function setMessageLine(str) {
	$('jsMessageLine').innerHTML ='<span class=jsMessageLineWarning>' +  str + '</span>';
}

function submit_node_edit_form() {
	if($('info_url').value == ''  || $('title') == '') {
		setMessageLine("Both 'title' and 'URL' must be filled out.");
	} else {
		$('node-form').submit();
	}
}

function record_click(base_url, url, nid, uid){

	var pars = '';
	apiurl = base_url+"/addclick?nid=" + nid + "&uid=" + uid+'&url='+encodeURIComponent(url);
	//alert(apiurl);
	ajaxRequest = new Ajax.Request(apiurl, {method: 'get', parameters: pars, onComplete: passThrough});
}

function passThrough( originalRequest )
{
	//Helps debug api errors
	//alert( originalRequest.responseText );
}

