// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function goengine( enSourceURL ) {
    
    winName = "traduceloMT";
    
    var myWin = window.open( 'http://www.traduceloahora.org/demand?mtlang=enes&translate=' + enSourceURL + '', winName);
	myWin.focus();
}

function tryit(){
	
	enSourceURL = document.forms[0].myURL.value;
	langSelect = document.forms[0].myLangSelect.value;
	winName = "traduceloMT";
    
	var myWin = window.open( '../translation/translate_site?translate=' + encodeURIComponent(enSourceURL) + '&langSelect=' + langSelect, winName);
    //var myWin = window.open( 'http://www.traduceloahora.org/demand?mtlang=enes&translate=' + enSourceURL + '', winName);
	myWin.focus();
}

function validate_url(form){
	url = form.myURL.value;
	console.log("url value is: ", url )
	url_regex = /^(http(s)?:\/\/)?([\w-\.]+)(\/|\/([\w_#.:+?=&%!@\-\/]+))?$/i
	// url_regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	console.log("does the url match?", url_regex.test(url))
	return false;	
}

function tryit_too(enSourceURL){
	winName = "traduceloMT";
    
	var myWin = window.open( '../translation/translate_site?translate=' + enSourceURL + '&langSelect=enes', winName);
    //var myWin = window.open( 'http://www.traduceloahora.org/demand?mtlang=enes&translate=' + enSourceURL + '', winName);
	myWin.focus();
}

/*
 * myElement = Element to be enabled or disabled
 * ableValue = Value which should be met if myElement is to be enabled
 * currValue = Value of whatever element if being tested against ableValue to determine if myElement should be enabled or disabled
 */
function ability(myElement, ableValue, currValue){
	
	if(currValue != ableValue){
		myElement.disabled = true;
	}else{
		myElement.disabled = false;
	}
	
}

function clearComments(){
	var myComments = $('comment_text');
	
	if(myComments.value == 'Enter Comments Here.' || myComments.value == 'Comment Sent.'){
		myComments.value = "";
	}
}

function showRating(rating){
	var myScore = $('your_rating');
	myScore.innerHTML = "Your Rating: " + rating;
}

function resetRating(score){
	var myScore = $('your_rating');
	if(score == 5){
		myScore.innerHTML = "Your Rating: Excellent";
	}else if(score == 4){
		myScore.innerHTML = "Your Rating: Good";
	}else if(score == 3){
		myScore.innerHTML = "Your Rating: Fair";
	}else if(score == 2){
		myScore.innerHTML = "Your Rating: Poor";
	}else if(score == 1){
		myScore.innerHTML = "Your Rating: Very Poor";
	}else{
		myScore.innerHTML = "Your Rating: Not Rated";
	}
}



function spin_comments(){
	var myComments = $('comments');
	myComments.innherHTML = "Sending Comments!";
}

function unspin_comments(){
	var myComments = $('comment_text');
	var commentDiv = $('comments');
	myComments.value = "Comment Sent.";
}

function applyAdmin(){
	if ($('admin_invite').checked){
		$('invite_total').disabled = true;
		$('invite_cc_span').style.display = "block";
	}else{
		$('invite_total').disabled = false;
		$('invite_cc_span').style.display = "none";
	}
}

function show_search_opts(){
	$('show_adv_opts').style.display = "none"
	$('hide_adv_opts').style.display = "block"
	$('adv_search_opts').style.display = "block";
}

function hide_search_opts(){
	$('hide_adv_opts').style.display = "none"
	$('adv_search_opts').style.display = "none";
	$('show_adv_opts').style.display = "block"
}

function fixSize() {
      // The body represents the outer-most frameset for frameset documents.
      document.body.rows = window.frames.ta_bar.document.body.scrollHeight + ", *"
      // Walk into the header frame and get the scrollHeight  
      // this represents the height of the contents in pixels. 
  }
  
function highlight_code() {
	//alert("highlighting");
    //dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
    //str = str.replace(/^[ ]+(.*)$/, '$1');
	dp.SyntaxHighlighter.HighlightAll('code');
}

function show_date_filter(){
	$('show_filters').style.display = "none"
	$('hide_filters').style.display = "block"
	$('date_filter_div').style.display = "block";
}

function hide_date_filter(){
	$('hide_filters').style.display = "none"
	$('date_filter_div').style.display = "none";
	$('show_filters').style.display = "block"
}

function clear_filter(){
	$('s_date').value = "";
	$('e_date').value = "";
}

function set_contact_type_selected(mySelection){
	
	$('contact_type_selected').value = mySelection;
	
}

function update_mtlang(){
	document.getElementById("hidden_mtlang").value = document.getElementById("text_lang_select").value;
}

function setForm(on, off)
{
	document.getElementById(off + '_partial').style.display = 'none';
	document.getElementById(on + '_partial').style.display = 'block';
	
	document.getElementById(on + '_translate_link').parentNode.className = 'active_tab';
	document.getElementById(off + '_translate_link').parentNode.className = 'inactive_tab';
	
	document.getElementById(off + '_translate_link').parentNode.parentNode.style.backgroundColor = "#3D647D";
	document.getElementById(off + '_translate_link').parentNode.parentNode.style.borderBottomColor = "#000";
	
	document.getElementById(on + '_translate_link').parentNode.parentNode.style.backgroundColor = "#EFF3E7";
	document.getElementById(on + '_translate_link').parentNode.parentNode.style.borderBottomColor = "#EFF3E7";
	
	document.getElementById(on + '_tab_left').className = 'left_tab_active';
	document.getElementById(on + '_tab_right').className = 'right_tab_active';
	
	document.getElementById(off + '_tab_left').className = 'left_tab_inactive';
	document.getElementById(off + '_tab_right').className = 'right_tab_inactive';
}

function show_translation(){
	elem = document.getElementById('translation_result');
	if (elem.style.display != 'block') {
		elem.style.display = 'block';
	}
	document.getElementById("translation_result_box").innerHTML = "<img src='/images/ta2/spinner.gif'  width='30px' height='30px' />";
}
function hide_translation(){
	document.getElementById('translation_result').style.display = "none";	
	document.getElementById('translation_result_box').innerHTML = "";

}




