

// STaF Functions for Email this and IM this Functionalities

var IM_global_title;
var IM_global_url;
var IM_default_text_IE = "Your%20friend%20wants%20you%20to%20check%20this%20out:";
var IM_default_text_OT = "Your friend wants you to check this out:";

// To check AIM install in the local machine or not

function canRunAIM() {
	var agt = navigator.userAgent.toLowerCase();
	var isIE = (agt.indexOf("msie") !=  - 1);
	if (!isIE){
		return true;
	}
	var a = document.anchors;
	for (var i = 0; i < a.length; i++){
		if (a[i].name == "aimnotfound"){
			return false;
		}
	}
	return true;
}

// To check AOL Client install in the local machine or not

function canRunAOLClient() {
	var agt = navigator.userAgent.toLowerCase();
	var isIE = (agt.indexOf("msie") !=  - 1);
	if (!isIE){
		return true;
	}
	var a = document.anchors;
	for (var i = 0; i < a.length; i++){
		if (a[i].name == "aolclientnotfound"){
			return false;
		}
	}
	return true;
}

// To send IM through AOL Client Messenger

function sendAOLCLNT() {

	var title = IM_global_title;
	var url = IM_global_url;
	var uAgt = navigator.userAgent.toLowerCase();
	var isAOL = uAgt.indexOf(" aol ") !=  - 1;
	var isIE = uAgt.indexOf("msie") !=  - 1;
	try {
		if (!isAOL){
			if (!isIE){
				document.location = "aol://9293::" + IM_default_text_OT + "<br><a href='" + url + "'>" + title + "</a>";
			} else {
				document.location = "aol://9293::" + IM_default_text_IE + "%3cbr%3e%3ca href='" + url + "'%3e" + title + "%3c%2fa%3e";
			}
		} else {
			document.location = 'aol://9293::' + IM_default_text_OT + '<br><a href="' + url + '">' + title + '</a>'
		}

	}
	catch (e){
		AIMExpress.start();
	}
}

// To send IM through AIM

function sendAIM() {

	var title = IM_global_title;
	var url = IM_global_url;
	var title = title.replace(/  /g, "+");
	var uAgt = navigator.userAgent.toLowerCase();
	var isIE = uAgt.indexOf(" msie ") !=  - 1;
	var isAOLBrowser = uAgt.indexOf(" america online browser ") !=  - 1;
	if (!isIE){
		var message = IM_default_text_OT + '<br><a href="' + url + '">' + title + '</a>';
	} else if (isAOLBrowser){
		var message = IM_default_text_OT + '<br><a href="' + url + '">' + title + '</a>';
	} else {
		var message = IM_default_text_IE + "%3cbr%3e%3ca+href=%22" + escape(url) + "%22%3e" + title + "%3c%2fa%3e";
	}
	message = escape(message);
	try {
		document.location = 'aim:GoIm?message=' + message;
	}
	catch (e){
		// sendAOLCLNT();
		AIMExpress.start();
	}
}

// If user is not using AOL Client then 
// send IM thro AIM if exists else if AOLClient exists then 
// send IM thro AOLClient else launch AIM Express and send IM

// If user in using the AOL Client then send IM thro AOL Client Instant Messenger


function sendIM(title, url) {
	if (title == ''){
		title = 'Click here to checkout';
	}
	IM_global_title = title;
	IM_global_url = url;
	var uAgt = navigator.userAgent.toLowerCase();
	var isAOL = uAgt.indexOf(" aol ") !=  - 1;
	var isIE = uAgt.indexOf(" msie ") !=  - 1;
	if (!isAOL){
		if (!isIE){
			sendAIM();
		} else {
			if (!canRunAIM()){
				// if (!canRunAOLClient()) {
				AIMExpress.start();
				// } else {
				// sendAOLCLNT ();
				// }
			} else {
				sendAIM();
			}
		}
	}
	else {
		sendAOLCLNT();
	}
}

// To launch the STAF User Console

function openstaf(title, url, channel) {
	window.open("http://sendtoafriend.aol.com?type=disp&channelurl=" + url + "&title=" + title + "&channel=" + channel + "&url=" + url + "", null, "height=420,width=296,statusbar=0,toolbar=no,menubar=no,location=no")
}


tiiAolStafObject = function () {}
tiiAolStafObject.prototype.im = function (pageTitle, pageURL, channelName) {

	if (typeof pageTitle == 'undefined' || pageTitle == '') {	
		pageTitle = document.title;
	}

	if (typeof pageURL == 'undefined' || pageURL == '') {	
		pageURL = document.location;
	}

	if (typeof channelName == 'undefined' || channelName == '') {	
		channelName = '';
	}

	sendIM(pageTitle, pageURL, channelName);
}

tiiAolStafObject.prototype.email = function (pageTitle, pageURL) {

	if (typeof pageTitle == 'undefined' || pageTitle == '') {	
		pageTitle = document.title;
	}

	if (typeof pageURL == 'undefined' || pageURL == '') {	
		pageURL = document.location;
	}

	openstaf(pageTitle, pageURL);

}

tiiAolStafObject.prototype.print = function () {window.print();}
tiiAolStafObject.prototype.getDetectionObject = function () {document.write('<div style="display: none;"><object classid="clsid:BAEB32D0-732D-11d2-8BF4-0060B0A4A9EA" width="1" height="1"><a name="aimnotfound"></a></object></div>');}

tiiAolStaf = new tiiAolStafObject();
