/*
Hong-Thai Nguyen
AXiMAG company
Switch translation only/both translation + source
feb. 5, 2010
*/
function changeFrameTarget(num) {
	var content_frame_element = parent.document.getElementById("imag_frame_content");
	if (num == 1)
		content_frame_element.cols = "100,0";
	else if (num == 2)
		content_frame_element.cols = "50,50";
}

/*
Hong-Thai Nguyen
AXiMAG company
Change color when show reability
feb. 5, 2010
*/
function changeColor() {
	var isShow = false; // Show color ?
	// Show/hide the summary
	//TODO
	var contribution_summary_element = document.getElementById("imag_contribution_summary_mark");
	
	if (contribution_summary_element && contribution_summary_element.getAttribute("isShow") == "1") {
		contribution_summary_element.setAttribute("isShow", "0");
		isShow = false;
	} else {
		contribution_summary_element.setAttribute("isShow", "1");
		isShow = true;
	}
	
	// Change color page
	switch_style(isShow);
	changeCookieShow();
	return;
}

/*
Hong-Thai Nguyen
AXiMAG company
Change language, call only in language select object
feb. 5, 2010
*/
function changeLanguage(imag_base_url, url, sl) {
	var urlLoc = imag_base_url + "?u=" + url + "&sl=" + sl + "&tl=" + this.options[this.selectedIndex].value;
	parent.window.localtion = urlLoc;
	return;
}


/*
Hong-Thai Nguyen
AXiMAG company
Show legend of translation types
feb. 5, 2010
*/
function showLegend() {
	alert("Red: Machine Translation; Orange: Freelancer; Green: Post-editor & Translation Memory");
	// showWarningOutOn('');
}

	
function switch_style (isShow) {
  var i, link_tag ;
  var targetPagerame = parent.document.getElementById("imag_content_target");
  var targetPageDocument = targetPagerame.contentWindow.document;
  for (i = 0, link_tag = targetPageDocument.getElementsByTagName("span_imag") ; i < link_tag.length ; i++ ) {
  	var classNametarget = link_tag[i].getAttribute("class");
    if (classNametarget != null && classNametarget.indexOf("imag-target-") >= 0) {
    	var pos = classNametarget.indexOf("-withcolor");
		if (isShow == true) {
			if (pos < 0)
				link_tag[i].className = classNametarget + "-withcolor";
		} else {
			if (pos >=0) {
				var classNameNoColor = classNametarget.substring(0, pos);
				link_tag[i].className = classNameNoColor;
			}
		}
    }
  }
  return;
}

function showWarningOutOn(urlOut) {
	document.getElementById('imag_warning_out').style.display='block';
	document.getElementById('imag_fade_background').style.display='block';
}

function showWarningOutOff() {
	document.getElementById('imag_warning_out').style.display='none';
	document.getElementById('imag_fade_background').style.display='none'
}

function redirectWindows(url_redirect) {
	parent.window.location = url_redirect;
}

function verifyCheckCondition() {
	if(document.register.condition.checked == false) {
		alert("You have to check in the rules & condition agreement !");
	} else {
		document.register.submit();
	}
}

function goBackOrClose() {
	if (history.length && history.length>1) {
		history.go(-1);
	} else {
		window.close();
	}
}

// Cookies operations
function getcookie(c_name) {
	if (parent.document.cookie.length>0) {
		c_start=parent.document.cookie.indexOf(c_name + "="); 
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=parent.document.cookie.indexOf(";",c_start); 
		
			if (c_end==-1) c_end=parent.document.cookie.length; 
				return unescape(parent.document.cookie.substring(c_start,c_end));
		} 
	} 
	return ""; 
} 

function setcookie(c_name,value,expiredays) {
	var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays); 
	parent.document.cookie=c_name+ "=" +escape(value)+((expiredays==null)? "" : ";expires="+exdate.toGMTString()); 
}

function changeCookieShow() {
	if(getcookie('imag_show_sep')==null || getcookie('imag_show_sep')==""){ 
		setcookie('imag_show_sep', 'false', 365); 
	} else {
		if (getcookie('imag_show_sep') == "true") {
			setcookie('imag_show_sep', 'false', 365); 
		} else  {
			setcookie('imag_show_sep', 'true', 365); 
		}
	}
}

function getcookieCurrentDocument(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "="); 
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start); 
		
			if (c_end==-1) c_end=document.cookie.length; 
				return unescape(document.cookie.substring(c_start,c_end));
		} 
	} 
	return ""; 
} 

function setcookieCurrentDocument(c_name,value,expiredays) {
	var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays); 
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null)? "" : ";expires="+exdate.toGMTString()); 
} 


function changeCookieShowCurrentDocument() {
	if(getcookieCurrentDocument('imag_show_sep')==null || getcookieCurrentDocument('imag_show_sep')==""){ 
		setcookieCurrentDocument('imag_show_sep', 'false', 365); 
	} else {
		if (getcookieCurrentDocument('imag_show_sep') == "true") {
			setcookieCurrentDocument('imag_show_sep', 'false', 365); 
		} else  {
			setcookieCurrentDocument('imag_show_sep', 'true', 365); 
		}
	}
}

function changeShowRadio() {
	if (this.checked=true)
		changeCookieShowCurrentDocument();
}

/*
	Mettre cligntant le texte
*/
function clignotement(){
    if (document.getElementById("UserGamePosition").style.display=="block")
       document.getElementById("UserGamePosition").style.display="none";
    else
       document.getElementById("UserGamePosition").style.display="block";
}
// mise en place de l appel régulier de la fonction toutes les 0.5 secondes
// setInterval("clignotement()", 500); 

/*
	Affichage le règlement du jeu en différente langues
*/
function choose_fr() {
	choose_regle_lang("fr");
	
}

function choose_en() {
	choose_regle_lang("en");
}

function choose_zh() {
	choose_regle_lang("zh");
}

function choose_regle_lang(lang) {
	var textareaElement = document.getElementById("regle_jeu");
	var divTextElement = document.getElementById("regle_" + lang);
	if (textareaElement && divTextElement) {
		textareaElement.innerHTML = divTextElement.innerHTML;
	}
}
