if (window != top) {
top.location.href = location.href;
}


function toggleDisplay(divID) {
if (divID.style.display == "none") divID.style.display = "block";
else divID.style.display = "none";
}

function toggleButtonContent(divID, content1, content2) {
if (divID.value == content1) divID.value = content2;
else divID.value = content1;
}

function updateSelectField(select_form, current_field) {
	var field_found = 0;
	
	for (x = 0; x <= select_form.length; x++) {
		if (select_form.options[x].value == current_field) {
		field_found = x;
		break;
		}
	}
	select_form.options.selectedIndex = field_found;
}

function url_encode(inputString) {    

//http://www.permadi.com/tutorial/urlEncoding/
               
  var encodedInputString = escape(inputString);
  encodedInputString=encodedInputString.replace("+", "%2B");
  encodedInputString=encodedInputString.replace("/", "%2F");
  return encodedInputString;
}

function title_encode_utf8(inputString) {
	
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	}
 
}

return Url.encode(inputString);

}

function sharePage(destination) {

//get javascript location and title
//else if disabled, fall back on hard php url in href

var current_page = url_encode(window.location.href);
var current_title = (window.document.title).replace(/\s/gi,"+"); //replace space with +
var current_title_utf8 = title_encode_utf8(current_title); //utf8 encoding

if (destination == "friend") window.open("/send-friend.php?url=" + current_page + "&title=" + current_title);
else if (destination == "delicious") window.open("http://del.icio.us/post?url=" + current_page + "&title=" + current_title_utf8);
else if (destination == "digg") window.open("http://digg.com/submit?phase=2&url=" + current_page);
else if (destination == "facebook") window.open("http://www.facebook.com/sharer.php?u=" + current_page + "&t=" + current_title_utf8);
else if (destination == "myspace") window.open("http://www.myspace.com/Modules/PostTo/Pages/?u=" + current_page + "&t=" + current_title_utf8);
else if (destination == "twitter") window.open("http://twitter.com/home?status=" + current_title_utf8 + " " + current_page);

}

function sharePage_fr(destination) {

//get javascript location and title
//else if disabled, fall back on hard php url in href

var current_page = url_encode(window.location.href);
var current_title = (window.document.title).replace(/\s/gi,"+"); //replace space with +
var current_title_utf8 = title_encode_utf8(current_title); //utf8 encoding

if (destination == "friend") window.open("/fr/envoyer-ami.php?url=" + current_page + "&title=" + current_title);
else if (destination == "delicious") window.open("http://del.icio.us/post?url=" + current_page + "&title=" + current_title_utf8);
else if (destination == "digg") window.open("http://digg.com/submit?phase=2&url=" + current_page);
else if (destination == "facebook") window.open("http://www.facebook.com/sharer.php?u=" + current_page + "&t=" + current_title_utf8);
else if (destination == "myspace") window.open("http://www.myspace.com/Modules/PostTo/Pages/?u=" + current_page + "&t=" + current_title_utf8);
else if (destination == "twitter") window.open("http://twitter.com/home?status=" + current_title_utf8 + " " + current_page);

}

