/* $Id: fpinfomart.js,v 1.6 2007/10/19 14:20:14 mertensb Exp $ */

/* Check/uncheck all checkboxes */
function ic_set_checkboxes( form, clicker ) {
	var i, state;
	state = clicker.checked;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "keys[]" || form.elements[i].name == "dbs[]" || form.elements[i].name == "magic1" || form.elements[i].name == "magic2" )  {
			form.elements[i].checked = state;
		}
	}
}

function ic_set_checkboxes_all( form, clicker ) {
	var i, state;
	state = clicker.checked;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "keys[]"  || form.elements[i].name == "skeys[]" || form.elements[i].name == "all_magic1" || form.elements[i].name == "all_magic2" || form.elements[i].name == "unique_magic1" || form.elements[i].name == "unique_magic2" )  {
			form.elements[i].checked = state;
		}
	}
}

function ic_set_checkboxes_unique( form, clicker ) {
	var i, state;
	state = clicker.checked;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "keys[]" || form.elements[i].name == "unique_magic1" || form.elements[i].name == "unique_magic2" )  {
			form.elements[i].checked = state;
		}
	}
}

function ic_set_checkboxes_similar( form, clicker ) {
	var i, state;
	state = clicker.checked;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "skeys[]" || form.elements[i].name == "similar_magic1" || form.elements[i].name == "similar_magic2" )  {
			form.elements[i].checked = state;
		}
	}
}

/* New, May 2007, clicker is a link, not checkbox, and ditch Unique option */
function multi_set_checkboxes_all( form ) {
	var i;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "keys[]" )  {
			form.elements[i].checked = true;
		}
	}
}

function multi_set_checkboxes_none( form ) {
	var i;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "keys[]" || form.elements[i].name == "skeys[]" )  {
			form.elements[i].checked = false;
		}
	}
}


function multi_action_on_change( this_one )
{
	other_one = 3 - this_one;

	// set dropdowns to match

	document.getElementById( "action"+other_one ).value = document.getElementById( "action"+this_one ).value;

	// show or hide move_next control
	a = document.getElementById( "action"+this_one ).value.split(":");
/*
	if( a[0] == "clip_add" && document.getElementById( "divmovenext"+this_one ) != "" && document.getElementById( "divmovenext"+other_one ) != "" ) {
		document.getElementById( "divmovenext"+this_one ).style.display = 'block';
		document.getElementById( "divmovenext"+other_one ).style.display = 'block';
	}
	else  {
		document.getElementById( "divmovenext"+this_one ).style.display = 'none';
		document.getElementById( "divmovenext"+other_one ).style.display = 'none';
	}
*/

	document.getElementById( "ic_multi_form" ).submit();

}


function pr_set_checkboxes( form, clicker ) {
	clicker_state = clicker.checked;
	clicker_cat = clicker.value;
	for (i = 0; i < form.elements.length; i++)  {
		if( form.elements[i].name == "s[]" || form.elements[i].name == "cat[]" )  {
			a = form.elements[i].value.split("_");
			s_cat = a[0];
			s_db = a[1];
			if( s_cat == clicker_cat || clicker_cat == "ALL")  {
				form.elements[i].checked = clicker_state;
			}
		}
	}
}

function pr_hide_form( hidden_div_id, yes_radio_id ) {
	if( document.getElementById( yes_radio_id ).checked )
		document.getElementById( hidden_div_id ).style.display = 'block';
	else
		document.getElementById( hidden_div_id ).style.display = 'none';
}

function pr_check_length( text_id, warn_id, id2, id3 ) {
	var max_count = 255;
	var warn_count = 240;
	var text_box = document.getElementById( text_id );
	var text_value = text_box.value.replace(/(\r\n|\r|\n)/g, "\n");
	var char_count = text_value.length;

	var char_count2 = document.getElementById( id2 ).value.replace(/(\r\n|\r|\n)/g, "\n").length;
	var char_count3 = document.getElementById( id3 ).value.replace(/(\r\n|\r|\n)/g, "\n").length;

	var warn_label = document.getElementById( warn_id );
	var save_button = document.getElementById( 'save_button' );

	if( char_count > max_count ) {
		text_box.style.background = '#ff6666';
		warn_label.innerHTML = '<font color="#990000">ERROR: Too long ['+char_count+'/'+max_count+']</font>';
	}
	if( char_count > warn_count && char_count <= max_count ) {
		text_box.style.background = '#ffff99';
		warn_label.innerHTML = '<font color="#cc6600">WARNING: ['+char_count+'/'+max_count+']</font>';
	}
	if( char_count <= warn_count )  {
		text_box.style.background = '#ffffff';
		warn_label.innerHTML = '['+char_count+'/'+max_count+']';
	}
	if((char_count > max_count) || (char_count2 > max_count) || (char_count3 > max_count )){
		save_button.disabled = true;
	}
	else{
		save_button.disabled = false;
	}
}

var hit_warnings_shown = new Array();
function toggle_hit_warning(hit_warning_id)
{
	if( hit_warnings_shown[hit_warning_id] )  {
		document.getElementById(hit_warning_id ).style.display = 'none';
		hit_warnings_shown[hit_warning_id]=false;
	}
	else  {
		document.getElementById( hit_warning_id ).style.display = 'block';
		hit_warnings_shown[hit_warning_id]=true;
	}
}


/* Pop-up help screens */
function ic_popup_help( help_id ) {
	window.open("/help/help_popup.php?id=" + help_id, help_id,       'menubar=1,resizable=1,scrollbars=1,width=350,height=400')
}

function ar_clear_sourceform( ) {
	for (i = 0; i < document.ARSourceForm.elements.length; i++)  {
			document.ARSourceForm.elements[i].checked = false;
			if(document.ARSourceForm.elements[i].name == "selection_name")
				document.ARSourceForm.selection_name.value = '';
	}
}

function ar_set_unset_cat( catid, clicker){
		clicker_state = clicker.checked;
	for (i = 0; i < document.ARSourceForm.elements.length; i++)  {
		if( document.ARSourceForm.elements[i].name == "db[]"){
			a = document.ARSourceForm.elements[i].id.split("_");
			if( a[0] == catid || catid == "ALL") {
				document.ARSourceForm.elements[i].checked = clicker_state;
		 		}
		}
	}
	}

	function searching(){
		location.href='#';
		document.getElementById('content').style.visibility = 'hidden';
		document.getElementById('progress').style.visibility = 'visible';
		setTimeout('wait()', 1);
	}

	function wait(){
		document.getElementById("working").src="/img/working_100x40.gif";
	}

	function hilight_on_off() {

		green_color = new Array("D5FFD5","CDFFCD","B3FFB3","90FF90","6FFF6F","4DFF4D","41FF41","2BFF2B","00FE00","00F700","00E400","00C300");
		red_color   = new Array("FFBCBC","FFBBBB","FFAEAE","FFAAAA","FFA9A9","FF9999","FF9393","FF8888","FF7272","FF6F6F","FF6666","FF5555");

		for (i = 0; ; i++){
			if(document.getElementById("nsent" + i.toString()) == null){
				break;
			}
			if(document.getElementById("nsent" + i.toString()).style.backgroundColor == "" ){
				document.getElementById("nsent" + i.toString()).style.backgroundColor = red_color[parseInt(document.getElementById("nsent" + i.toString()).title )];
			}
			else{
				document.getElementById("nsent" + i.toString()).style.backgroundColor = "";
			}
		}
		for (i = 0; ; i++){
			if(document.getElementById("psent" + i.toString()) == null){
				break;
			}
			if(document.getElementById("psent" + i.toString()).style.backgroundColor == "" ) {
				document.getElementById("psent" + i.toString()).style.backgroundColor = green_color[parseInt(document.getElementById("psent" + i.toString()).title)];
			}
			else{
				document.getElementById("psent" + i.toString()).style.backgroundColor = "";
			}
		}
}

function NewWin(screen,feature)  {
	window.open(screen, "", feature);
}


function pr_create_http_request_object()
{
	var obj;
    try {
      // For Internet Explorer.
      obj = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch(e) {
      try {
        // Gecko-based browsers, Safari, and Opera.
        obj = new XMLHttpRequest();
      }
      catch (e) {
        // Browser supports Javascript but not XMLHttpRequest.
        obj = false;
      }
    }
    return obj;
}


// FAST SEARCH ENGINE RESULTS
function fast_handle_http_response()
{
	if( (fast_http.readyState == 4) )  {
		if( fast_http.status == 200 )  {
			document.getElementById("fast_"+fast_id).innerHTML = fast_http.responseText;
		}
		else  {
			document.getElementById("fast_"+fast_id).innerHTML = "Error fetching content, status = "+fast_http.status;
		}
		fast_next_profile();
	}
}


function fast_next_profile()
{
	fast_id = fast_list.shift();
	if( fast_id >0 )  {
		var url = "/fast/fast_pr_front_ajax.php?p="+fast_id+"&dup="+pr_dup+"&date="+pr_result_date;
		fast_http = pr_create_http_request_object();
		fast_http.open( "GET", url );
		fast_http.onreadystatechange = fast_handle_http_response;
		fast_http.send( null );
	}
}

//SOLR SEARCH ENGINE NEXT RESULTS 
function solr_handle_http_response()
{
	return;
}

function solr_fetch_next()
{
	solr_http = pr_create_http_request_object();
	solr_http.open( "GET", next_url );
//	solr_http.onreadystatechange = solr_handle_http_response;
	solr_http.send( null );	
}

// COMBINED RESULTS
function combined_handle_http_response()
{
	if( (combined_http.readyState == 4) )  {
		if( combined_http.status == 200 )  {
			document.getElementById("combined_"+combined_id).innerHTML = combined_http.responseText;
		}
		else  {
			document.getElementById("combined_"+combined_id).innerHTML = "Error fetching content, status = "+combined_http.status;
		}
		combined_next_profile();
	}
}


function combined_next_profile()
{
	combined_id = combined_list.shift();
	if( combined_id >0 )  {
		var url = "/pr/pr_combined_front_ajax.php?p="+combined_id+"&date="+pr_result_date;
		combined_http = pr_create_http_request_object();
		combined_http.open( "GET", url );
		combined_http.onreadystatechange = combined_handle_http_response;
		combined_http.send( null );
	}
}



// NEWS
function news_handle_http_response()
{
	if( (news_http.readyState == 4) )  {
		if( news_http.status == 200 )  {
			// Stick whatever is returned by the http request right into the DIV, verbatim
			document.getElementById("news_"+news_id).innerHTML = news_http.responseText;
		}
		else  {
			document.getElementById("news_"+news_id).innerHTML = "Error fetching content, status = "+news_http.status;
		}
		news_next_profile();
	}
}

function news_next_profile()
{
	news_id = news_list.shift();
	if( news_id >0 )  {
		var url = "/pr/pr_news_front_ajax.php?p="+news_id+"&date="+pr_result_date;
		news_http = pr_create_http_request_object();
		news_http.open( "GET", url );
		news_http.onreadystatechange = news_handle_http_response;
		news_http.send( null );
	}
}



// VP VIDEO
function vp_handle_http_response()
{
	if( (vp_http.readyState == 4) )  {
		if( vp_http.status == 200 )  {
//				alert("vp_handle_http_response():\n\ncur_profile_id = "+cur_profile_id+"\n\nresponse(): = "+vp_http.responseText);
			// Stick whatever is returned by the http request right into the DIV, verbatim
			document.getElementById("video_"+cur_profile_id).innerHTML = vp_http.responseText;
		}
		else  {
			document.getElementById("video_"+cur_profile_id).innerHTML = "Error fetching content, status = "+vp_http.status;
		}
		vp_next_profile();
	}
}

function vp_next_profile()
{
	cur_profile_id = vp_list.shift();
	if( cur_profile_id >0 )  {
		var url = "/pr/vp_front_ajax.php?p="+cur_profile_id+"&date="+pr_result_date;
		vp_http = pr_create_http_request_object();
		vp_http.open( "GET", url );
		vp_http.onreadystatechange = vp_handle_http_response;
		vp_http.send( null );
	}
}
