/* Event Functions */

// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

// Get the obj that starts the event
function getElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.currentTarget;
	}
}
// Get the obj that triggers off the event
function getTargetElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.target;
	}
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
	if (typeof obj.onselectstart != 'undefined'){
		addEvent(obj,"selectstart",function(){ return false;});
	}
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// Get the start position of the caret in the object
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToStart",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
// sets the caret position to l in the object
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}

/*    Escape function   */
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function curLeft(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}
/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

/* Object Functions */
function changeOrderDisplay1(){
}
function replaceHTML(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}

function submitSearch(){
if(document.searchReleventRecentBean.order.value=='Recent' || document.searchReleventRecentBean.order.value=='tagNameTobeReplaced.shtml'){
document.searchReleventRecentBean.process.value='recentArtByTag';
document.searchReleventRecentBean.action="/netwokingTag.jsp"

document.searchReleventRecentBean.submit();
}else if(document.searchReleventRecentBean.order.value=='Relevant' || document.searchReleventRecentBean.order.value=='tagNameTobeReplaced-relevant.shtml'){
 document.searchReleventRecentBean.process.value='relevantArtByTag'
 document.searchReleventRecentBean.action="/netwokingTag.jsp"

document.searchReleventRecentBean.submit();
}else
{
window.location=document.searchReleventRecentBean.order.value;
}
}
/* old method
function submitSearch(){

if(document.searchReleventRecentBean.order.value=='Recent'){
document.searchReleventRecentBean.process.value='recentArtByTag';
}else{
 document.searchReleventRecentBean.process.value='relevantArtByTag'
}

document.searchReleventRecentBean.action="/netwokingTag.jsp"

document.searchReleventRecentBean.submit();
}
*/

function callByPageNo(){
document.pagingForm.action="/netwokingTag.jsp"
document.pagingForm.submit();

}
function validate()
{
 if(removeAllSpaces(document.form1.userID.value)=="")
 {
  alert("Please Enter your user Name");
  document.form1.userID.focus();
  return false;
 }
 if(removeAllSpaces(document.form1.password.value)=="")
 {
  alert("Please Enter your password");
  document.form1.password.focus();
  return false;
 }
 return true;
}

function removeLeadingSpaces(str)
{
   var whitespace = new String(" \\t\\n\\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1)
    {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)  j++;
      s = s.substring(j, i);
    }
   return s;
}
//######################################################################################################
// This method is used to remove Trailing spaces.
// It takes argument of the string which Trailing Spaces has to removed.
function removeTrailingSpaces(str)
{
   var whitespace = new String(" \\t\\n\\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }
   return s;
}
//######################################################################################################
// Removes both Leading and Trailing blanks.
//
function removeAllSpaces(str)
{
   str = removeLeadingSpaces(str); //Remove Leading Spaces
   str = removeTrailingSpaces(str); //Remove Trailing Spaces
   return str;
}
function frmreset(){
document.form1.reset();

return false;
}




function getTagValue(){

var tagValue="";
if(document.searchbytopic123.tag.value=='Search by topic' || document.searchbytopic123.tag.value==''){
alert('Please enter search topic');
document.searchbytopic123.tag.focus();

return false;

}

tagValue=document.searchbytopic123.tag.value;

document.searchbytopic123.searchTag.value=tagValue;
document.searchbytopic123.submit();

}
var finalRsspath="topic";
var sitename="http://www.merinews.com";
function showRssPage(){
var finalloc="recent";
//alert(document.searchReleventRecentBean.order.value);
var myarray=document.searchReleventRecentBean.order.value.split("-relevant.shtml");
//alert(myarray.length);
if (myarray.length==2) finalloc="relevant";
//alert(document.getElementsByName("tagConverted")[0].value);
//var url=sitename+"/"+finalRsspath+"/"+document.getElementsByName("tagConverted")[0].value+"-"+finalloc+".xml";
var url=sitename+"/"+finalRsspath+"/"+document.getElementsByName("tagConverted")[0].value+".xml";
//alert(url);
window.location=url;
}
function showRssEmailPage(){
}
function showRssSubscribePage(){
}


////////////for dynamic loading js
var loadedobjects="";
function setValuesForhelp(){
var tvalueobj=document.getElementsByName('tag')[0];
var tvalue=document.getElementsByName('tag')[0].value;
document.getElementById("tagids").innerHTML='<input name="tag" type="text" value="" size="17" id=\'tb\' onfocus=";if (this.value==\'Search by topic\') this.value=\'\';" onblur="if (this.value==\'\')this.value=\'Search by topic\'" />';
setTimeout(function() { document.getElementsByName('tag')[0].focus();document.getElementsByName('tag')[0].value=tvalue; }, 1000);
var obj = actb(document.getElementById('tb'),customarray);
tvalueobj.style.backgroundImage="";
 helpprepared=true;
}
var customarray;
function checkWhetherJsloaddedornot(){
 if (customarray==undefined){
  window.setTimeout('checkWhetherJsloaddedornot()', '9000');
  }
  else{
   setValuesForhelp();
  }
}
function iframeAds(){
var iframeAds1="<iframe src='/home/components/ads/adDisplay.jsp' height='90' width='728' scrolling='no' frameborder='0' align='right' marginheight='0' marginwidth='0' ></iframe>"
document.getElementById("myhomeads").innerHTML=iframeAds1;
}
window.onload=function (){
if (document.getElementById("myhomeads")=='null' || document.getElementById("myhomeads")==null){
}else{
iframeAds();
}

}
//ajax for tag help
var xmlHttpTag;
function createXmlHttpObject(){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttpTag = new XMLHttpRequest();     // Firefox, Safari, ...
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttpTag = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    } 
  return xmlHttpTag;
 }

xmlHttpTag=createXmlHttpObject();
var helpprepared=false;
function loadobjs(myfile){
if (!helpprepared){
var tvalueobj=document.getElementsByName('tag')[0];
tvalueobj.style.backgroundImage="url(/mnc/images/preparinghelp.gif)";
tvalueobj.style.backgroundRepeat="no-repeat";
tvalueobj.style.backgroundPosition="right";

xmlHttpTag.open("POST", "/mncArticleList.do?choice=getTagHelp",  true); 
xmlHttpTag.onreadystatechange =processStateChangeTaghelp;
xmlHttpTag.send(null); 
 }

}

function processStateChangeTaghelp(){
  if(xmlHttpTag.readyState  == 4 && xmlHttpTag.status  == 200) {
    var allVlauesforTags=xmlHttpTag.responseText;
   customarray=allVlauesforTags.split(",");
   setValuesForhelp();
  
   }
}






