/*This file uses JavaScript functions for this level of access*/

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Create cookie*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function makeCookie(value, name){
	document.cookie = name + "=" +"; expires=Thu, 01-Jan-1970 00:00:01 GMT" + "; path=/";
	var when = new Date();
	when.setTime(when.getTime() + 369 * 24 * 60 * 60 * 1000);
					//  369 * 24 hours from now
	when.setFullYear(when.getFullYear() + 1);
					// One year from now
	document.cookie=name+"="+escape(value)+
		";expires="+when.toGMTString();
	
   document.cookie = name + "=" + escape(value) + "; expires="+ when.toGMTString() + "; path=/";

}
/*Create cookie*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Get cookie*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "en";
}
/*Get cookie*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Create tips*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function tips(hide_tips, show_tips) {
	    var ID="tips_javascript";
		var get_cookie = getCookie('hide_tips');
		//alert(get_cookie);
		var what_to_write = writeTip(get_cookie, hide_tips, show_tips);
		
		if (document.layers) {
			var tipLayer;
			tipLayer = document.layers[ID].document;
			tipLayer.open();
			tipLayer.write(what_to_write);
			tipLayer.close();
		}
		else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
			document.getElementById(ID).innerHTML = what_to_write;
		}
		else if (document.all) document.all[ID].innerHTML = what_to_write

		//  alert(get_cookie);
}
/*Create tips*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Show tips or Hide tips function*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function writeTip(get_cookie, hide_tips, show_tips) {
	 if(get_cookie == '0') {
			  return "<a href=\"javascript:makeCookie(1,'hide_tips'); tips('"+hide_tips+"', '"+show_tips+"');\">"+hide_tips+"</a>";
		  }
		  else {
			  return "<a href=\"javascript:makeCookie(0,'hide_tips'); tips('"+hide_tips+"', '"+show_tips+"');\">"+show_tips+"</a>";
		  }
}
/*Show tips or Hide tips function*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Set the prefered language*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function setLang(lang) {
	makeCookie(lang, "lang");
	var URL = location.href;
	window.location = URL;
}
/*Set the preffered by the user language*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Used in the encyclopedia module to enable the user to see all the videos. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_enc_video_gallery(type, r) {
	makeCookie(type, "enc_main_video_gallery");
	var URL = location.href;
	if(r === true) {}
	else {
		window.location = URL;
	}
}
/*Used in the encyclopedia module to enable the user to see all the videos. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Used in the encyclopedia module to enable the user to see all the images. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_enc_image_gallery(type, r) {
	makeCookie(type, "image_galleries");
	var URL = location.href;
	if(r === true) {}
	else {
		window.location = URL;
	}
	
}
/*Used in the encyclopedia module to enable the user to see all the images. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Used in the encyclopedia module to enable the user to see all the images. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_scientific_galleries_(type, r) {
	makeCookie(type, "scientific_galleires");
	var URL = location.href;
	if(r === true) {}
	else {
		window.location = URL;
	}
	
}
/*Used in the encyclopedia module to enable the user to see all the images. It sets a cookie and then refresh the page where the user is*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Get the path*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function insert_img_thumb_(img_id, area, width, height) {
	//Get a cookie that was created when the user accessed a gallery
	var mod  =  getCookie("image_galleries");

	//Get lang
	var lang =  getCookie("lang");

	//Encyclopedia/Space
	if(mod == "enc_space_imgs") {
		document.getElementById(area).innerHTML='<img src="../rsc/level_users/gallery/encyclopedia/space/'+lang+'/images/thumbs/img_'+img_id+'.jpg" style="width:'+width+'; height:'+height+'" />';
		//Return the src to the image which is used in the mail.php script
		return 'rsc/level_users/gallery/encyclopedia/space/'+lang+'/images/images/img_'+img_id+'.jpg';
	}
	else if(mod == "enc_timeline_imgs") {
		document.getElementById(area).innerHTML='<img src="../rsc/level_users/gallery/encyclopedia/'+lang+'/timeline/images/thumbs/img_'+img_id+'.jpg" style="width:'+width+'; height:'+height+'" />';
		//Return the src to the image which is used in the mail.php script
		return 'rsc/level_users/gallery/encyclopedia/'+lang+'/space/images/images/img_'+img_id+'.jpg';
	}
	else if(mod == "enc_archive_imgs") {
		document.getElementById(area).innerHTML='<img src="../rsc/level_users/gallery/encyclopedia/'+lang+'/archive/images/thumbs/img_'+img_id+'.jpg" style="width:'+width+'; height:'+height+'" />';
		//Return the src to the image which is used in the mail.php script
		return 'rsc/level_users/gallery/encyclopedia/space/images/images/img_'+img_id+'.jpg';
	}
	else if(mod == "enc_maps_imgs") {
		document.getElementById(area).innerHTML='<img src="../rsc/level_users/gallery/encyclopedia/'+lang+'/maps/images/thumbs/img_'+img_id+'.jpg" style="width:'+width+'; height:'+height+'" />';
		//Return the src to the image which is used in the mail.php script
		return 'rsc/level_users/gallery/encyclopedia/'+lang+'/space/images/images/img_'+img_id+'.jpg';
	}
	
	
}
/*Get the path*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Set the font size plus*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_font_size_plus() {
	//Check for min size
	var font_size;
	font_size = getCookie("bso_font_size_");

	if(!font_size) {
		//Set to one
		makeCookie(Math.round(3), "bso_font_size_");
	}
	else if(font_size >= 9) {
		alert("Max");
	}
	else {
		//Increment by one
		makeCookie(Math.round(Math.round(font_size)+1), "bso_font_size_");
	}
	reload();

}
/*Set the font size plus*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Set the font size minus*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_font_size_minus() {
	//Check for min size
	var font_size;
	font_size = getCookie("bso_font_size_");

	if(!font_size) {
		//Set to one
		makeCookie(Math.round(3), "bso_font_size_");
	}
	else if(font_size <= 1) {
		alert("Min");
	}
	else {
		//Increment by one
		makeCookie(Math.round(Math.round(font_size)-1), "bso_font_size_");
	}

	reload();
}
/*Set the font size plus*/////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Reload the page*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function reload() {
	//Reload the page
	var URL = location.href;
	window.location = URL;
}
/*Reload the page*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Set the font family*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function set_font_families_() {
	//Set the font family
	var families_num;
	families_num = getCookie("bso_font_families_num");

	if(!families_num) {
		makeCookie(1, "bso_font_families_num");
	}
	else if(families_num > 7-1) {
		makeCookie(1, "bso_font_families_num");
	}
	else if (families_num >= 1) {
		makeCookie(Math.round(Math.round(families_num)+1), "bso_font_families_num");
	}
	else {
	}


	reload();
}
/*Set the font size plus*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*Save the page*/////////////////////////////////////////////////////////////////////////////////////////////////////////
function doSaveAs() {

	if (document.execCommand){
		document.execCommand("SaveAs", "1", "BSO-archive.html");
    }
    else{
		alert('Some of the BSO\' functions are only available in Internet Exlorer 4.0 and later. Please update your version. Vashiat browser e po star ot IE 4.0. Za da rabotiat functions BSO molia install po nov.');
    }
}
/*Save the page*/////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function LOGINSHA256() {
	document.logInForm.username.value = hex_sha256(document.logInForm.username.value);
	document.logInForm.password.value = hex_sha256(document.logInForm.password.value);
}

////////////////////////////////////////Ajax///////////////////////////////////////////////////////////////////
/*var xmlHttp_cookie

function set_cookie(name, value)
{
	alert("");
xmlHttp_cookie=set_cookie_gettext_GetXmlHttpObject()
if (xmlHttp_cookie==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="../ajax_php/set_cookie.php"
url=url+"?name="+name
url=url+"&value="+value+"&sid="+Math.random()
xmlHttp_cookie.open("GET",url,true)
xmlHttp_cookie.send(null)
} 

function set_cookie_gettext_GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}*/
////////////////////////////////////////Ajax///////////////////////////////////////////////////////////////////

