//this function use to popup the Preview Quicklinks
function popup() {
	var returnVal;
	tinyMCE.triggerSave(); // This function called for blocking the ERRORS rich text area in ajax functionality
	e1 = document.getElementById('content').value;
	document.getElementById('hidden_content').value = e1;
	returnVal = URLEncode(e1);
	openwindow = window.open('preview.php?preview='+returnVal, 'PopupPage', 'height=400,width=650,scrollbars=yes,resizable=no,left=50,top=50');
	openwindow.focus();
}

//this function use to save the data in database 
function saveQuickLinks() {
	var returnVal;

	tinyMCE.triggerSave(); // This function called for blocking the ERRORS rich text area in ajax functionality
	e1 = document.getElementById('content').value;
	returnVal = URLEncode(e1);
	//document.getElementById('hidden_content').value = returnVal;

	document.getElementById('hidden_content').value = returnVal;
	//quicklins.hidden_parameter.value = 'save';
	document.getElementById('hidden_parameter').value = 'save';
	
	displayQuickLinks.action = "index.php?action=save#adminTop"; 
	document.displayQuickLinks.submit();	
}

// This function encodes the URL if in text there is & comes  // function used in addTask.js & updateTask.js
function URLEncode(text)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = text;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	//document.URLForm.F2.value = encoded;
	return encoded;
}

function signIn() {
	
	if(document.getElementById("username").value == '') {
		alert("Please enter your Username.");
		document.getElementById("username").focus();
		return false;
	}
	if(document.getElementById("password").value == '') {
		alert("Please enter your Password.");
		document.getElementById("password").focus();
		return false;
	}
	//return true;
	
	formSignIn.action = "index.php?action=signIn";
	formSignIn.submit();	
}

//this function use to close the winddow
function closeWindow() {
	//window.opener.document.formName.hdnAction.value = str;
	window.close()
}

function resetVal() {
	window.document.formSignIn.reset();  
}

function popupReadNews(fileName) {
		
	openwindow = window.open(fileName, 'PopupPage', 'height=400,width=650,scrollbars=yes,resizable=no,left=50,top=50');
	openwindow.focus();
}
//this function use to add the new News in database
function addNews() {
	window.location = "index.php?action=newNewsSection"
}