var position, request;

var left;

var top;

var a;

var b;

var presenter;

var header;

var content;

var thread_cur_id;

var button_cur_id;

var show_thread_cur_id;

var show_limit_cur_id;



function getPageSize(){

	var de = document.documentElement;

	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;

	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;	

	arrayPageSize = [w,h];	

	return arrayPageSize;

}



function detectBrowser() {

	var userAgent = navigator.userAgent.toLowerCase();	

	if (userAgent.indexOf('msie')!=-1)

	{

		axe = userAgent.substr(eval(userAgent.indexOf('msie') + 5), 1);		

		if(axe < 7)		

	    	return true;		

	}

	return false;

}



function PostData(url, parameters) {

	request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		request = new XMLHttpRequest();

		if (request.overrideMimeType) {		

		request.overrideMimeType('text/html');

		}

	} else if (window.ActiveXObject) { // IE

	 try {

		request = new ActiveXObject("Msxml2.XMLHTTP");

	 } catch (e) {

		try {

		   request = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (e) {}

	 }

	}

	

	if (!request) {		

	 	NotificationMessage('Http request could not be generated. Please try again later...');

		DeleteNotification();

	 	return false;

	}

	request.onreadystatechange = ProcessPostRequest;

	request.open('POST', url, true);

	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	request.setRequestHeader("Content-length", parameters.length);

	request.setRequestHeader("Connection", "close");

	request.send(parameters);

}



function ProcessPostRequest() {

  if (request.readyState == 4) {

	 if (request.status == 200) {		 

		 result = request.responseText;

		/* document.getElementById('showResponse').innerHTML = result;

		 document.getElementById('fldShouts').value = '';

		 document.getElementById('show_limit').innerHTML = '144 characters left';

		 document.getElementById('fldShouts').disabled = false;

		 document.getElementById('btnShout').disabled = false;*/

		 document.getElementById(show_thread_cur_id).style.color = "#10af24";

		 document.getElementById(show_thread_cur_id).innerHTML = result;

		 document.getElementById(thread_cur_id).value = '';

		 document.getElementById(show_limit_cur_id).innerHTML = '144 characters left';

		 document.getElementById(thread_cur_id).disabled = false;

		 document.getElementById(button_cur_id).disabled = false;

	 }		

  }

}



function GetFormData(url, cur_id, cond)

{	

	var getrequest = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		getrequest = new XMLHttpRequest();

		if (getrequest.overrideMimeType) {		

		getrequest.overrideMimeType('text/html');

		}

	} else if (window.ActiveXObject) { // IE

	 try {

		getrequest = new ActiveXObject("Msxml2.XMLHTTP");

	 } catch (e) {

		try {

		   getrequest = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (e) {}

	 }

	}

	if (!getrequest) {	

	 	NotificationMessage('Http request could not be generated. Please try again later...');

		DeleteNotification();

	 	return false;

	}

	

	getrequest.open('GET', url, true);

	getrequest.onreadystatechange = function() {

		if(getrequest.readyState == 4) {

		  	result1 = getrequest.responseText;

			//alert("Resyult is: " + result1);

			//document.getElementById(cur_id).innerHTML = result1;

			if(cond == "sidebar"){

				var new_cur_id = "showLikeResponse"+cur_id;

				var new_cur_id_down = "samyak-t-down"+cur_id;

				var new_cur_id_up = "samyak-t-up"+cur_id;

			}

			else{

				var new_cur_id = "showLikeResponseMain"+cur_id;

				var new_cur_id_down = "samyak-tt-down"+cur_id;

				var new_cur_id_up = "samyak-tt-up"+cur_id;

			}

			//alert("new cur id is: " + new_cur_id);

			if(result1 == "successlike" || result1 == "successdislike"){

				document.getElementById(new_cur_id).style.paddingTop = "5px";

				document.getElementById(new_cur_id).style.color = "#10af24";

				document.getElementById(new_cur_id).innerHTML = "<span style='color:#009900'>Thank you for your vote.</span>";

			}

			else if(result1 == "failuredislike"){

				document.getElementById(new_cur_id).innerHTML = "<span style='color:#990000'>You have already voted for it.</span>";

			}

			else if(result1 == "failurelike"){

				document.getElementById(new_cur_id).innerHTML = "<span style='color:#990000'>You have already voted for it.</span>";

			}

			

			if(result1 == "successlike"){

				document.getElementById(new_cur_id_up).innerHTML = parseInt(document.getElementById(new_cur_id_up).innerHTML) + 1;

			}

			else if(result1 == "successdislike"){

				document.getElementById(new_cur_id_down).innerHTML = parseInt(document.getElementById(new_cur_id_down).innerHTML) + 1;

			}

		}

	};	

	getrequest.send(null);

}



function GetFileData(url, obj, cond)

{	

	var getrequest = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...

		getrequest = new XMLHttpRequest();

		if (getrequest.overrideMimeType) {		

		getrequest.overrideMimeType('text/html');

		}

	} else if (window.ActiveXObject) { // IE

	 try {

		getrequest = new ActiveXObject("Msxml2.XMLHTTP");

	 } catch (e) {

		try {

		   getrequest = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (e) {}

	 }

	}

	 

	if (!getrequest) {		

	 	NotificationMessage('Http request could not be generated. Please try again later...');

		DeleteNotification();

	 	return false;

	}	

	

	getrequest.open('GET', url, true);

	getrequest.onreadystatechange = function() {

		if(getrequest.readyState == 4) {

		  	result = getrequest.responseText;

		}

	};	

	getrequest.send(null);

}



function addShout(frm)

{

	frm.onsubmit = function(){return false;};

	thread_cur_id = "fldShouts";

	button_cur_id = "btnShout";

	show_thread_cur_id = "showResponse";

	show_limit_cur_id = "show_limit";

	

	PostData("http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/insert.php", "task=insert&val="+frm.fldShouts.value);

	document.getElementById('fldShouts').disabled = 'disabled';

	document.getElementById('btnShout').disabled = 'disabled';

	document.getElementById('showResponse').innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

}



function likeit(shoutOutId,cond)

{

	GetFormData("http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/insert.php?task=like&shoutOutId="+shoutOutId, shoutOutId, cond);

	if(cond == "sidebar"){

		var curid = "showLikeResponse"+shoutOutId;

		//alert("Cur id is: " + curid);

		document.getElementById(curid).innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

	}

	else{

		var curid = "showLikeResponseMain"+shoutOutId;

		//alert("Cur id is: " + curid);

		document.getElementById(curid).innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

	}

	

}



function dislikeit(shoutOutId,cond)

{

	GetFormData("http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/insert.php?task=dislike&shoutOutId="+shoutOutId, shoutOutId, cond);

	if(cond == "sidebar"){

		var curid = "showLikeResponse"+shoutOutId;

		document.getElementById(curid).innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

	}

	else{

		var curid = "showLikeResponseMain"+shoutOutId;

		document.getElementById(curid).innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

	}

}



function showHideComments(frm,shoutOutId,cond)

{

	var show_cur_id = "samyak-comment-id"+shoutOutId;

	//var hide_cur_id = ""+shoutOutId;

	if(cond == "show"){

		document.getElementById(show_cur_id).style.display = "block";

		document.getElementById(show_cur_id).style.paddingBottom = "10px";

	}

	else{

		frm.onsubmit = function(){return false;};

		document.getElementById(show_cur_id).style.display = "none";

	}

}



function addShoutThread(shoutId,frm)

{

	frm.onsubmit = function(){return false;};

	if(frm.fromThread.value == "Y"){

		thread_cur_id = "fldShoutsAgain";

		button_cur_id = "btnShoutAgain";

		show_thread_cur_id = "showResponseChildAgain";

		show_limit_cur_id = "show_limitChildAgain";

		var samyak_comment_cur_id = "commentIdAgain";

	}

	else{

		thread_cur_id = "fldShoutsChild"+shoutId;

		button_cur_id = "btnShout"+shoutId;

		show_thread_cur_id = "showResponseChild"+shoutId;

		show_limit_cur_id = "show_limitChild"+shoutId;

		var samyak_comment_cur_id = "samyak-comment-id"+shoutId;

	}

	//globalCurId = show_thread_cur_id;

	//alert(document.getElementById(thread_cur_id).value);

	PostData("http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/insert.php", "task=addthread&shoutId="+shoutId+"&val="+document.getElementById(thread_cur_id).value);

	document.getElementById(thread_cur_id).disabled = 'disabled';

	document.getElementById(button_cur_id).disabled = 'disabled';

	document.getElementById(button_cur_id).disabled = 'disabled';

	if(samyak_comment_cur_id != "commentIdAgain")

		document.getElementById(samyak_comment_cur_id).style.display = 'none';

	document.getElementById(show_thread_cur_id).style.paddingTop = "5px";

	document.getElementById(show_thread_cur_id).innerHTML = '<img src="http://www.livetradingnews.com/wp-content/plugins/samyak-shout-out/loader.gif" alt="Loading..." align="middle" />';

}



function getObject(obj) {

  var theObj;

  if(document.all) {

    if(typeof obj=="string") {

      return document.all(obj);

    } else {

      return obj.style;

    }

  }

  if(document.getElementById) {

    if(typeof obj=="string") {

      return document.getElementById(obj);

    } else {

      return obj.style;

    }

  }

  return null;

}



function toCount(entrance,exit,text,characters) {

  var entranceObj=getObject(entrance);

  var exitObj=getObject(exit);

  var length=characters - entranceObj.value.length;

  if(length <= 0) {

    length=0;

    text='<span class="disable"> '+text+' </span>';

    entranceObj.value=entranceObj.value.substr(0,characters);

  }

  exitObj.innerHTML = text.replace("{CHAR}",length);

}
