/* 
 *	Application wide Settings
 *  -------------------------
 */

var noText = "Clipboard does not contain any text";
var repText = "This clipboard text has been changed using java script";
var chgTextAlert = "Your clipboard text has been changed. Check it by pasting it in notepad";
var sendFailMsg = "There was some problem in sending the clipboard text to the email address ";
var sendPassMsg = "Your clipboard text has been emailed to ";

var g_ajaxpage = "ajaxback.php";
var loadingmessage = "<span class=\"loading\"><img src=\"pics/pinging.gif\" height=\"17\" width=\"18\"><em>Pinging</em></span>";


//  -------------------------  -------------------------

function writeText() {
	var content = getText();
	if (content == null) {
		content = noText;
	}

	document.getElementById('ctext').value = content;
}

function changeText() {
	setText(repText);
	alert(chgTextAlert);
	writeText();
}

function sendText() {
	var email = document.getElementById('email').value ;
	var content = getText();
	if (content == null) {
		content = noText;
	}
	
	content = escape(content);
	var http = getHTTPObject();

	var url =  g_ajaxpage + "?action=sendtext&e=" + email + "&txt=" + content;

	http.open("POST", url, true);

	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.responseText == "0") {
				alert (sendPassMsg + email + ". Check your email in few minutes")	;
			} else {
				alert (sendFailMsg + email)	;
			}
		}
	}

    http.send(null);
}

/*----------------------------------------------------------
 * Library Functions
 */

function getText() {
	var content = clipboardData.getData("Text");
	return content;	
}

function setText(text) {
	clipboardData.setData("Text", text);
}

// Wrapper for XMLHttp

function getHTTPObject()
{
	var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
	try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
@else
	xmlhttp = false;
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
