//requires Dojo safe compression

if (window != top) {
	top.location.href = location.href;
}

var creditfinanceplus_GA_ID = "UA-141875-13";

function recordOutboundLink(link, category, action, optvalue) {
	
	try {
		_gaq.push(['_trackEvent', category, action, optvalue]);
		setTimeout('document.location = "' + link.href + '"', 100)
	} catch(err){}
}

function toggleHelp(show, divID) {
	if (show) $(divID).fadeIn("fast"); //jquery effect
	//divID.style.display = "block";
	else $(divID).fadeOut("fast"); //jquery effect
}

function toggleDisplay(divID) {
	if (divID.style.display == "none") $(divID).fadeIn("fast"); //jquery effect
	//divID.style.display = "block";
	else $(divID).fadeOut("fast"); //jquery effect
}

function toggleButtonContent(divID, content1, content2) {
	if (divID.value == content1) divID.value = content2;
	else divID.value = content1;
}

function expandLink(sub_element, parent_link) {
	
	if (sub_element.style.display == "none") {
		$(sub_element).slideDown("slow"); //jquery effect
		parent_link.style.backgroundPosition = "-11px 0px";
	}
	else {
		$(sub_element).slideUp("fast"); //jquery effect
		parent_link.style.backgroundPosition = "0px 0px";
	}
}

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://www.delicious.com/save?url=" + current_page + "&title=" + current_title_utf8);
	else if (destination == "facebook") window.open("http://www.facebook.com/sharer.php?u=" + current_page + "&t=" + current_title_utf8);
	else if (destination == "stumbleupon") window.open("http://www.stumbleupon.com/submit?url=" + current_page + "&title=" + 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://www.delicious.com/save?url=" + current_page + "&title=" + current_title_utf8);
	else if (destination == "facebook") window.open("http://www.facebook.com/sharer.php?u=" + current_page + "&t=" + current_title_utf8);
	else if (destination == "stumbleupon") window.open("http://www.stumbleupon.com/submit?url=" + current_page + "&title=" + current_title_utf8);
	else if (destination == "twitter") window.open("http://twitter.com/home?status=" + current_title_utf8 + " " + current_page);

}

