var xmlHttpTemp;
function createXmlHttpObjects(){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttpTemp=new XMLHttpRequest();
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttpTemp=   new ActiveXObject("Microsoft.XMLHTTP");//cj month//viewer choice//dedate (skype)
    } 
 }

//createXmlHttpObjects();
//view and comments
function calculateViewsCommentsJS(myarticleid){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttpTemp=new XMLHttpRequest();
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttpTemp=   new ActiveXObject("Microsoft.XMLHTTP");//cj month//viewer choice//dedate (skype)
    } 
xmlHttpTemp.open("POST", "/mncArticleList.do?choice=articleViewsComments&articleID="+myarticleid+"&updateView=update",  true);
xmlHttpTemp.onreadystatechange =processStateChangeViews;
//xmlHttpRecent.setRequestHeader("Connection", "close");
xmlHttpTemp.send(null); 
//processStateChangeViews();

}
function processStateChangeViews(){
  if(xmlHttpTemp.readyState  == 4 && xmlHttpTemp.status  == 200) {
  var res=xmlHttpTemp.responseXML;
  if (res!=null && res.getElementsByTagName("hits")[0]!=null){
    var objView=res.getElementsByTagName("hits");
    var objComment=res.getElementsByTagName("comments");
    document.getElementById("newviewsid").innerHTML=objView[0].childNodes[0].nodeValue;
    document.getElementById("newcommentsid").innerHTML=objComment[0].childNodes[0].nodeValue;


    document.cookie="mycomments"+document.getElementById("artidarticle").value+"="+document.getElementById("newcommentsid").innerHTML+"; path=/" ;
    document.cookie="myviews"+document.getElementById("artidarticle").value+"="+document.getElementById("newviewsid").innerHTML+"; path=/" ;
    document.cookie="article_cokkie"+document.getElementById("artidarticle").value+"="+document.getElementById("artidarticle").value+"; path=/" ;
   
   }
    
   }
}

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 makeNetWorkingTagFile(aa,ab){
}
/*
var catID='ss';
var urlTag='ss';
alert('dd');
temp+='<td width="88%" class="art_topicmatter1"><a href="javascript:getCategoryName('+catID+',\''+urlTag+'\');" class="art_topicmatter1">';
alert(aaaa);
function getCategoryName(ssaaa,aaasssaa){
alert('dd1');
}
*/

//for session

///No editing beyond here required/////
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
return returnvalue;
}



function loadupdate(myarticleid){ 
calculateViewsCommentsJS(myarticleid)}

function calculateViewsComments(myarticleid){
//alert("cokk"+get_cookie('article_cokkie')+myarticleid);
//calculateViewsCommentsJS(myarticleid)
if (get_cookie("article_cokkie"+myarticleid)==""){
loadupdate(myarticleid);
 
}else{
 //alert(fetch_Cookie("myviews"+myarticleid));
  document.getElementById("newcommentsid").innerHTML=fetch_Cookie("mycomments"+myarticleid) ;
  document.getElementById("newviewsid").innerHTML=fetch_Cookie("myviews"+myarticleid) ;
}
}


function fetch_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
var totalcjarticleComing=0;

function displayCJarticles(){
//alert(totalcjarticleComing);
var winloction=window.location+'';
document.getElementById("articleIDcalled").value=winloction.split("/")[5].split(".")[0];
 if  (document.getElementById("cjarticleid"+document.getElementById("articleIDcalled").value)=='null' || 
      document.getElementById("cjarticleid"+document.getElementById("articleIDcalled").value)==null){
      //alert('w');
      if (totalcjarticleComing==0 || totalcjarticleComing>5){
      //alert('d');
      document.getElementById("cjarticleid"+document.getElementById("articleIDhiddenCJ").value).style.display="none";
      document.getElementById("cjarticleid"+document.getElementById("articleIDhiddenCJ").value).style.visibility="hidden";
      }
  }  else {
      //alert('k');
      document.getElementById("cjarticleid"+document.getElementById("articleIDcalled").value).style.display="none";
      document.getElementById("cjarticleid"+document.getElementById("articleIDcalled").value).style.visibility="hidden";
  }
}
//sorting
var viewSort;

function setSort(viewsort) {
	viewSort = viewsort;
	var url = "/articleList.do?choice=ViewerChoice&viewSort=" + viewSort;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("POST", url, true);
	req.onreadystatechange = getArticles;
	req.send(null);	
 }
 
function getArticles() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			populateArticles();
		}
	}
}
 
function populateArticles() {

	var Div = document.getElementById('v-content');
		var newDiv=document.getElementById('newDiv');
		//alert(newDiv);
		if(newDiv != null)
			Div.removeChild(newDiv);
		
		var ul = document.createElement('ul');
		ul.id="newDiv";
		
		//alert(req.responseText);
	var articles =  req.responseXML.getElementsByTagName("articles")[0];
	//alert('articles:' + articles);
	for (loop = 0;loop<articles.childNodes.length; loop++) {
	//alert((article.getElementsByTagName("articleId")[0]).firstChild.nodeValue);
		var article = articles.childNodes[loop];
		var articleId = (article.getElementsByTagName("articleId")[0]).firstChild.nodeValue;
		//alert(articleId);
		var title = "";
		if(article.getElementsByTagName("title")[0].hasChildNodes()){
			for(var i = 0; i < article.getElementsByTagName("title")[0].childNodes.length; i++){
				title += getNodeText(article.getElementsByTagName("title")[0].childNodes[i]);
			}
		}
		
		var userName = (article.getElementsByTagName("userName")[0]).firstChild.nodeValue;
		var cmpImageTag = "";
		if(article.getElementsByTagName("cmpImageTag")[0].hasChildNodes()){
			for(var i = 0; i < article.getElementsByTagName("cmpImageTag")[0].childNodes.length; i++){
				cmpImageTag += getNodeText(article.getElementsByTagName("cmpImageTag")[0].childNodes[i]);
			}
		}
		
		if(cmpImageTag == 'null')
			cmpImageTag = "";
	
		var userName = (article.getElementsByTagName("userName")[0]).firstChild.nodeValue;
		var views = (article.getElementsByTagName("views")[0]).firstChild.nodeValue;
		var comments = (article.getElementsByTagName("comments")[0]).firstChild.nodeValue;

		
		var li = document.createElement("li");
		
		var html = "<a href=\"/catFull.jsp?articleID=" + articleId + "\" class='g-lefttext'>"+ title + "</a>"+ cmpImageTag ;
		li.innerHTML=html;
		//alert(html);
		ul.appendChild(li);

  		document.getElementById("changesortorder").innerHTML="<a href='/allArticles.do?choice=Viewer&pageNo=1&viewSort="+viewSort+"' class='wj-more'>more...</a>";
	}
	
	Div.appendChild(ul);
	// text
	var weekCol = document.getElementById("week");
	var monthCol = document.getElementById("month");
	var quarterCol = document.getElementById("quarter");
	
	// links
	var weekLink = document.getElementById("weekLink");
	var monthLink = document.getElementById("monthLink");
	var quarterLink = document.getElementById("quarterLink");

	if(viewSort == 7){
		weekCol.className = "#EFEFEF";
		weekLink.href = "JavaScript:";
		weekLink.className = "mahroon";
		
		monthCol.className = "#EFEFEF";
		monthLink.href = "JavaScript:setSort(30);";
		monthLink.className = "bs";
		
		quarterCol.className = "#EFEFEF";
		quarterLink.href = "JavaScript:setSort(90);";
		quarterLink.className = "bs";
	}
	
	if(viewSort == 30){
		weekCol.className = "#EFEFEF";
		weekLink.href = "JavaScript:setSort(7);";
		weekLink.className = "bs";

		monthCol.className = "#EFEFEF";
		monthLink.href = "JavaScript:";
		monthLink.className = "mahroon";

		quarterCol.className = "#EFEFEF";
		quarterLink.href = "JavaScript:setSort(90);";
		quarterLink.className = "bs";
	}
	
	if(viewSort == 90){
		weekCol.className = "#EFEFEF";
		weekLink.href = "JavaScript:setSort(7);";
		weekLink.className = "bs";
		
		monthCol.className = "#EFEFEF";
		monthLink.href = "JavaScript:setSort(30);";
		monthLink.className = "bs";
		
		quarterCol.className = "#EFEFEF";
		quarterLink.href = "JavaScript:";
		quarterLink.className = "mahroon";
	}
}


function getNodeText(node){
	if(node.tagName){
		var txt = "<" + node.tagName;
		var attributes = node.attributes;
		for(var i = 0; i < attributes.length; i++){
			txt += " " + attributes[i].nodeName + "=\"" + node.attributes[i].nodeValue + "\"";
		}
		if(node.hasChildNodes()){
			txt += ">";
			for(var i = 0; i < node.childNodes.length; i++){
				txt += getNodeText(node.childNodes[i]);
			}
			txt += "</" + node.tagName + ">";
		}
		else {
			txt += "/>";
		}
		return txt;
	}
	if(node.data){
		return node.data;
	}
	return "";
}

//sorting end


function getCommentsByArticle(articleId, start, end, noOfComments ) {
    articleId=document.getElementById("artidarticle").value;//from hidden variable
    //alert(start);
	start = document.getElementById(start).value;
	//alert("start+end:"+start+end);
	if(parseInt(noOfComments) < (Number(start)+Number(end))){
	document.getElementById('moreComment').innerHTML="";
	}else{
		document.getElementById('moreComment').innerHTML="<a href=\"javascript:setStart();javascript:getCommentsByArticle('"+articleId+"','start',"+end+","+noOfComments+");\" class='round more' id='more' rel='next'>more comments("+noOfComments+") </a>";
	}
	//alert(start);
	var	url = "/mncArticle.do?detail=CatFullCommentsTempalteAjax&articleID="+articleId+"&start="+start+"&end="+end;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("POST", url, true);
	req.onreadystatechange = getComments;
	req.send(null);	
 }
 
 function getComments() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			populateComments();
		}
	}
}
 
function populateComments() {
//alert(req.responseText);
	var comments =  req.responseXML.getElementsByTagName("comments")[0];
	var html="";
	
	

	
	for (loop = comments.childNodes.length-1; loop>=0; loop--) {
		var comment = comments.childNodes[loop];
		var articleId = (comment.getElementsByTagName("articleId")[0]).firstChild.nodeValue;
		var commentId = (comment.getElementsByTagName("commentId")[0]).firstChild.nodeValue;
		var commenterName = (comment.getElementsByTagName("commenterName")[0]).firstChild.nodeValue;
		var description = (comment.getElementsByTagName("description")[0]).firstChild.nodeValue;
		var date = (comment.getElementsByTagName("date")[0]).firstChild.nodeValue;
	
		var replycomment = comment.childNodes[loop];
		
	     
		html +=' <table border="0" cellspacing="0" cellpadding="0" >';

		html +=' <tr><td align="center" valign="top" ><div class="call"><table width="90%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FAFAFA">';
		html +=' <tr><td width="4%">&nbsp;</td><td width="94%">';
		html +=' <div align="justify">'+description+'</div>';
		html +=' </td><td width="2%">&nbsp;</td></tr><tr><td height="3" colspan="3"></td></tr><tr>';
		html +=' <td align="left" valign="top" class="cj">&nbsp;</td><td align="left" valign="top" class="cj">';
		html +=' <div class="art-post-cmnts1"><div class="art-post-cmnts1-1">';
		html +=' <span class="art-post-date">'+cutAllStringNew(commenterName.replace(/find/g,"/'"),30)+'</span> <span class="grey123"> |</span> ';
		html +=' <span class="art-post-date">'+date+'</span></div>';
		html +=' <div class="art-post-cmnts1-2">';
		html +=' <a class="cj-art"';
		html +=' href="JavaScript:displayComment('+commentId+', \'Reply to Comment\', \'Reply\',\'ReplyComment\');"';
		html +=' onmouseover="window.status=\'Reply to Comment\'; return true; "';
		html +=' onmouseout="window.status=\'\'; return true;"> Reply to Comment</a><span class="grey"> |</span>';
		html +=' <a class="cj-art"';
		html +=' href="JavaScript:displayComment('+commentId+', \'New Comment\', \'Comments\', \'AddComment\');"';
		html +=' onmouseover="window.status=\'New Comment\'; return true; "';
		html +=' onmouseout="window.status=\'\'; return true;"> New Comment</a><span class="grey"> |</span>';
		html +=' <a class="cj-art"';
		html +=' href="JavaScript:displayComment('+commentId+', \'Report Abuse\', \'Reason\', \'ReportAbuse\');"';
		html +=' onmouseover="window.status=\'Report Abuse\'; return true; "';
		html +=' onmouseout="window.status=\'\'; return true;"> Report Abuse</a>';
		html +=' </div></div></td><td>&nbsp;</td></tr></table></div></td></tr>';
		html +=' <tr><td align="left" valign="top">&nbsp;</td></tr>';
		
				
		
		html +=' <tr><td><div class="art-land-post-cnt8"><div id="'+commentId+'" style="display:none;" width="80%">';
		html +=' <div class="art-land-post-cnt9">';
		html +=' <form action="/commentSave.do" name="AddComment"  method="get"	id="form'+commentId+'">';
		html +=' <input id="method" type="hidden" name="method" value=""/> ';
		html +=' <input	type="hidden" name="commentId"	value="'+commentId+'">	';			
		html +=' <table width="95%" border="0" cellspacing="0" cellpadding="0" bordercolor="#E9E9E9" bgcolor="#F8F8F8">';
		html +=' <tr><td  id="title'+commentId+'" valign="top" align="left" class="art-reply" ></td>';
		html +=' </tr><tr><td height="10"></td></tr>';
		html +=' <input type="hidden" name="articleId" value="'+articleId+'" />';
		html +=' <input type="hidden" name="title" value="hello" />';
		html +=' <tr><td align="left" valign="top" class="posted">';
		html +=' <table width="100%" border="0" cellspacing="1" cellpadding="1">';
		html +=' <tr>';
		html +=' <td height="28" align="left" valign="top">';
		html +=' <input name="commenterName" type="text" class="links" ';
		html +=' value="Name" size="15" maxLength=60 onfocus="if(this.value==\'Name\') this.value=\'\';" /></td>';
		html +=' <td align="left" valign="top">&nbsp;</td>';
		html +=' <td width="71%" rowspan="2" align="left" valign="top">';
		html +=' <textarea name="description" cols="45" rows="3" class="links" onfocus="if(this.value==\'Comments\') this.value=\'\';" >Comments</textarea></td>';
		html +=' </tr><tr>';
		html +=' <td width="24%" align="left" valign="top">';
		html +=' <input name="email" type="text" class="links" ';
		html +=' value="Email" size="15" maxLength=60 onfocus="if(this.value==\'Email\') this.value=\'\';" /></td>';
		html +=' <td width="5%" align="left" valign="top">&nbsp;</td>';
		html +=' </tr>';
		html +=' <tr>';
		html +=' <td align="left" valign="top">&nbsp;</td>';
		html +=' <td align="left" valign="top">&nbsp;</td>';
		html +=' <td align="left" valign="top">';
		html +=' <table border="0" cellspacing="0" cellpadding="2">';
		html +=' <tr>';
		html +=' <td width="140" align="left" valign="top">';
		html +=' <div id="verifyImageCommentidCC" style="display: inline;">';
		html +=' <img id="imageIframe" name="imageIframe" src="/jcaptcha" width="140" height="23" /></div>';
		html +=' </td>';
		html +=' <td width="122" align="left" valign="top"><input name="verifyImageText" type="text" class="links" size="15" maxlength=5/></td>';
		html +=' <td width="47" align="right" valign="top">';
		html +=' <a style="cursor: pointer;" class="wj-arttext-post" ';
		html +=' onclick="getTrimed();validateCommentForm(\'form'+commentId+'\',\'Comments\')">';
		html +=' Post</a>';
		html +=' </tr>';
		html +=' </table>';
		html +=' </table>';
		html +=' </td>';
		html +=' </tr>';
		html +=' <tr>';
		html +=' <td height="2" bgcolor="white"></td>';
		html +=' </tr>';
		html +=' </table>';
		html +=' </div></form></DIV></div></td></tr>';
			  		      
			            
		
		
		
		
		        
		

		//alert(comment.childNodes.length);
		if(comment.childNodes.length > 5){
			for(loop1 = comment.childNodes.length-1; loop1>=5; loop1--){
				var replycomment = comment.childNodes[loop1];
				
				var replyCmtName = (replycomment.getElementsByTagName("replyCmtName")[0]).firstChild.nodeValue; 
				var replyCmtDesc = (replycomment.getElementsByTagName("replyCmtDesc")[0]).firstChild.nodeValue;
				var replyCmtDate = (replycomment.getElementsByTagName("replyCmtDate")[0]).firstChild.nodeValue;
				
				//alert(replyCmtDesc);
				html +=' <tr><td align="right" valign="top" > ';
				html +=' <div class="art-land-post-cnt6ii">';
				html +=' <table width="90%" align="right" border="0"><tr><td>';
				html +=' <div class="art-land-post-cnt6i">';
				html +=' <div class="art-post-cmntsi">'+replyCmtDesc+'</div>';
				html +=' <div class="art-post-cmnts1i">';
				html +=' <div class="art-post-cmnts1-2"><span class="art-post-date">'+replyCmtName;
				html +=' </span> <span class="grey123"> |</span> <span class="art-post-date">'+replyCmtDate+'</span></div>';
				html +=' </div></div></td></tr></table></div></td></tr>   ';
		
				
			}
		}
		html +=' </table>';
		}
		//alert(html);
		
		
		
		var tr = document.createElement("tr");
		var td = document.createElement("td");
		var tbody = document.createElement("tbody");
		td.innerHTML=html;
	
	tr.appendChild(td);
	tbody.appendChild(tr);
		var addHere = document.getElementById('addHere');
		addHere.appendChild(tbody);
		

	}
	
//cj div  show	
xpos = 20;
ypos = 70;

function setVisible(obj)
{
//setTimeout("placeIt('layer1')",500);
 obj = document.getElementById(obj);
 obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
 obj.style.left = (cursor.x -15) + 'px' ;
 obj.style.top = (cursor.y -15)+ 'px' ;

}
function placeIt1(obj)
{
 obj = document.getElementById(obj);
 if (document.documentElement)
 {
  theLeft = document.documentElement.scrollLeft;
  theTop = document.documentElement.scrollTop;
 }
 else if (document.body)
 {
  theLeft = document.body.scrollLeft;
  theTop = document.body.scrollTop;
 }
 theLeft += xpos;
 theTop += ypos;
 obj.style.left = theLeft + 'px' ;
 obj.style.top = theTop + 'px' ;
 setTimeout("placeIt('layer1')",500);
}


function hideElement (element) {
if (element.style) {
element.style.visibility = 'hidden';
}
}

function hideCjdiv(myobj,e){
if(!e)	e=window.event;

if (mouseLeaves(myobj, e)) {hideElement(myobj);}
}

function mouseLeaves (element, evt) {
if (typeof evt.toElement != 'undefined' && typeof element.contains !=
'undefined') {
return !element.contains(evt.toElement);
}
else if (typeof evt.relatedTarget != 'undefined' && evt.relatedTarget) {
return !contains(element, evt.relatedTarget);
}
}
function contains (container, containee) {
while (containee) {
if (container == containee) {
return true;
}
containee = containee.parentNode;
}
return false;
}
var cursor = {x:0, y:0};
function getPosition(e) {
    e = e || window.event;
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


function callRss(){
window.location="http://www.merinews.com/rss/"+document.getElementById("articlecathidden").value+"/rss2.xml";
}
//for rating
   function handleover1(){
   
        document.imgWhite1.src="images/bstar.gif"; 
     }
    function handleout1(){
        document.imgWhite1.src="images/wstar.gif";
     }
    function handleover2(){
        handleover1();
        document.imgWhite2.src="images/bstar.gif";
       }
    function handleout2(){
        handleout1();
        document.imgWhite2.src="images/wstar.gif";
        }
    function handleover3(){
        handleover1();
        handleover2();
        document.imgWhite3.src="images/bstar.gif";
        }
   function handleout3(){
        handleout1();
        handleout2();
        document.imgWhite3.src="images/wstar.gif";
        }
   function handleover4(){
        handleover1();
        handleover2();
        handleover3();
        document.imgWhite4.src="images/bstar.gif";
        }
   function handleout4(){
        handleout1();
        handleout2();
        handleout3();
        document.imgWhite4.src="images/wstar.gif";
        }
   function handleover5(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       document.imgWhite5.src="images/bstar.gif";
       }
   function handleout5(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       document.imgWhite5.src="images/wstar.gif";
       }
   function handleover6(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       handleover5();
       document.imgWhite6.src="images/bstar.gif";
       }
   function handleout6(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       handleout5();
       document.imgWhite6.src="images/wstar.gif";
       }
  function handleover7(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       handleover5();
       handleover6();
       document.imgWhite7.src="images/bstar.gif";
       }
   function handleout7(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       handleout5();
       handleout6();
       document.imgWhite7.src="images/wstar.gif";
       }
   function handleover8(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       handleover5();
       handleover6();
       handleover7();
       document.imgWhite8.src="images/bstar.gif";
       }

   function handleout8(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       handleout5();
       handleout6();
       handleout7();
       document.imgWhite8.src="images/wstar.gif";
       }
  function handleover9(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       handleover5();
       handleover6();
       handleover7();
       handleover8();
       document.imgWhite9.src="images/bstar.gif";
       }
   function handleout9(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       handleout5();
       handleout6();
       handleout7();
       handleout8();
       document.imgWhite9.src="images/wstar.gif";
       }
   function handleover10(){
       handleover1();
       handleover2();
       handleover3();
       handleover4();
       handleover5();
       handleover6();
       handleover7();
       handleover8();
       handleover9();
       document.imgWhite10.src="images/bstar.gif";
       }
   function handleout10(){
       handleout1();
       handleout2();
       handleout3();
       handleout4();
       handleout5();
       handleout6();
       handleout7();
       handleout8();
       handleout9();
       document.imgWhite10.src="images/wstar.gif";
       }    

	// function to send XML request for updating the article rating
	function updateRating(articleId,rating) {
		var url = "/article.do?detail=SetRating&articleID=" + articleId + "&rating="+ rating;
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		req.open("POST", url, true);
		req.onreadystatechange = getStatusRating;
		req.send(null);	
	}

 	// function to check the status of XML request
	function getStatusRating() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				populateRating();
			}
		}
	}

	// function to populate the html table with XML request details
	function populateRating(){
		myTable = document.getElementById("article_rating");
		myTable.innerHTML="";
		
		var childDiv1 = document.createElement("DIV");
		//childDiv1.id= "article_ratethis";
	    //childDiv1.innerHTML="";
		
		var updateRating =  req.responseXML.getElementsByTagName("updateRating")[0];
		var rating = (updateRating.getElementsByTagName("rating")[0]).firstChild.nodeValue;
		var totalVotes = (updateRating.getElementsByTagName("totalVotes")[0]).firstChild.nodeValue;
		var noOfFullImage = (updateRating.getElementsByTagName("noOfFullImage")[0]).firstChild.nodeValue;
		var noOfBlankImage = (updateRating.getElementsByTagName("noOfBlankImage")[0]).firstChild.nodeValue;
		var smallStar =  (updateRating.getElementsByTagName("smallStar")[0]).firstChild.nodeValue;
		var mediumStar = (updateRating.getElementsByTagName("mediumStar")[0]).firstChild.nodeValue;
		var bigStar = (updateRating.getElementsByTagName("bigStar")[0]).firstChild.nodeValue;
		content = '';
		var i = 0;
		
		var childDiv2 = document.createElement("DIV");
		//childDiv2.id= "rating_bg"
		
		for(i = 0; i < noOfFullImage; i++){
			content += '<IMG SRC="/mnc/images/ratfull.gif" name="imgWhite12" width="12" height="11" border="0">';
		}
		if(smallStar != 'null'){
			content += '<IMG SRC="/mnc/images/ratlesfull.gif" name="imgWhite12" width="12" height="11" border="0">';
		}
		if(mediumStar != 'null'){
			content += '<IMG SRC="/mnc/images/rathalf.gif" name="imgWhite12" width="12" height="11" border="0">';
		}
		if(bigStar != 'null'){
			content += '<IMG SRC="/mnc/images/ratfull.gif" name="imgWhite12" width="12" height="11" border="0">';
		}						
		var j = 0;
		for(j = 0; j < noOfBlankImage; j++){
			content += '<IMG SRC="/mnc/images/ratnone.gif" name="imgWhite12" width="12" height="11" border="0">';
		}
		childDiv2.innerHTML = content;
		var childDiv3 = document.createElement("DIV");
		//childDiv3.id= "rating_msg"
        childDiv3.innerHTML = "<span class='cj-art-rate'><strong>Rate :</strong>&nbsp;" +content+"&nbsp;"+ rating + "&nbsp;/ " + totalVotes + " votes </span>";
        //myTable.appendChild(childDiv1);
        //myTable.appendChild(childDiv2);
        myTable.appendChild(childDiv3);
	}
       
       
//trim js

<!--
/*@ Author Shambhu Kumar Mehta
Trim function  used for removing the spaces from begining and end of all non-empty textfield and text area of entire  document irrespective  forms. Prefred to call this method at first of each validation functions. This function calls the Trim() method described next .This method doesn't return anything*/

function getTrimed()
{
	var formNo=document.forms.length;

	for (j=0;j<formNo;j++)
	{

		var max = document.forms[j].elements.length;
		for(var i=0; i< max; i++)
		{
			if (document.forms[j].elements[i].type =="textarea" || document.forms[j].elements[i].type =="text")
			{
				trim(document.forms[j].elements[i]);
			}
			
		}
	}
}
/* This method is for removing the white spaces from the begining and end of a given Object . Doesn't return anything */
<!--Pass the input objet reference-->

function trim(item) {
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++){
    if (item.value.charAt(index) != ' '){
		tmp += item.value.charAt(index);
     }else {
      if (tmp.length > 0){
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1){
			tmp += item.value.charAt(index);
        }
      }
    }
  }
	item.value = tmp;
}
//-->
//debate
var senderName;  
var senderEmail;
var urlNew="";

function showArticle(id){
alert("HiiiiiiiiFFFFFFFFF");
  
   document.getElementById(id).style.display = 'none';
   
   alert( document.getElementById(id).style.display);
}

function toggleDisplay(id){

var me = document.getElementById(id);
if (me.style.display=="none"){

me.style.display="block";
me.focus();
}
else if (me.style.display=="block"){

document.getElementById(id).style.display='none';
//me.style.display="none";
}else{

me.style.display="block";
me.focus();

}
}
function show123(id, hide){
//alert("HiiiiiiiiFFFFFFFFF");
   document.getElementById(hide).style.display = 'none';
   document.getElementById(id).style.display = 'none';
   
}

function show(id, hide){
//alert("Hiiiiiiiiggggggiiiiiii");
	document.form1.senderName.value ="";
	document.form1.senderEmail.value ="";
	for(i=0; i<document.form1.recepientEmail.length ;i++)
	 {
 		document.form1.recepientEmail[i].value =""; 		
	 }
	 for(i=0; i<document.form1.recepientName.length ;i++)
	 { 		
 		document.form1.recepientName[i].value ="";
	 }
   document.getElementById(hide).style.display = 'none';
   document.getElementById(id).style.display = 'block';
 //  validateMail1();
   
  
}
function validateMail1(id, hide)
{
//alert("Validaie mail function");
 getTrimed();
 var flag=0;
 	if(document.form1.senderName.value ==""){
	        alert("Please enter your name");
			document.form1.senderName.focus();	      
	  return false;
	 } 
	
	 if(notValidEmail(form1.senderEmail)){
	        alert("Please enter your valid email");
			document.form1.senderEmail.focus();
	      
	  return false;
	 }
 for(i=0; i<document.form1.recepientName.length && document.form1.recepientName[i].value == "";i++);
	 if(i == document.form1.recepientName.length )
	 {
	   alert("Please enter any one recipient name");
	   document.form1.recepientName[0].focus();
	   return false;
	 }
 for(i=0; i<document.form1.recepientEmail.length ;i++)
 {
	   if(document.form1.recepientEmail[i].value != "")
	   {
	    if(notValidEmail(form1.recepientEmail[i])){
	        alert("Please enter valid email");
			document.form1.recepientEmail[i].focus();
	      
	      return false;
	     }else
	     {
	     if(document.form1.recepientName[i].value ==""){
	        alert("Please enter name");
			document.form1.recepientName[i].focus();
	      
	       return false;
	       } 
	     }
	   flag =1;
	   }
 }
		 if(flag ==0)
		 {
		   alert("Please enter any one email address");
		   document.form1.recepientEmail[0].focus();
		   return false;
		 } 
 senderName = document.form1.senderName.value;
 senderEmail = document.form1.senderEmail.value;
 //description=document.form2.description.value;
 urlNew="";
		  for(i=0; i<document.form1.recepientEmail.length && document.form1.recepientEmail[i].value!="" ;i++)
		  {
		 // alert(urlNew)		 ;
		  urlNew=urlNew+"&recepientName="+document.form1.recepientName[i].value+"&recepientEmail="+document.form1.recepientEmail[i].value;
		//  alert(urlNew)		 ;
		  }
 sendDebate();
 //if(flag ==1){
 //alert("guiuiyuiyiy8o");
 show123(id, hide);
//}
return false;
} 

function sendDebate() {
	//	alert("We r in send Debate Method");
		var url = "mncDebateFor.do?method=SendDebate&senderName="+ senderName + "&senderEmail="+ senderEmail + urlNew;

        alert(url)		 ;
		if (window.XMLHttpRequest) {
		
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		  // req.open("POST", url, true);
		  //req.send();
		}
		
		req.open("POST", url, true);
		//alert("11111111111111111111");
		req.onreadystatechange = getStatusHumour1;
		//alert("22222222222222222");
		req.send(null);	
		//alert("33333333333333333333");
	}

	function getStatusHumour1() {
	//alert("44444444444444444444");
		if (req.readyState == 4) {
	//alert("555555555555555555555");
			if (req.status == 200) {
			resetHumourForm();
		//alert("6666666666666666666666");
		  }
				
		}
	}
function resetHumourForm(){
		 //removeForm();
	}
	
function randomPhoto(){
//alert("random photo");
var url = "/image.do?method=RandomHome";
if (window.XMLHttpRequest) {

		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("POST", url, true);
	//alert("random photo444");
	req.onreadystatechange = getPhotos;
	req.send(null);	
 }
 
function getPhotos() {
///alert("random photogggggg");
	if (req.readyState == 4) {
		if (req.status == 200) {
			populatePhotos();
		}
	}
}

function populatePhotos() {	
//alert("random photopoppopopopop");
	 myTable = document.getElementById("randomphoto");	 
	// alert("random photopoppopopopop111"+myTable);
	 myTable.innerHTML="";	
	// alert("random photopoppopopopop2222");
	 var childDiv1 = document.createElement("DIV");
	// alert("random photopoppopopopop3333");
	 childDiv1.innerHTML="";	
	// alert("random photopoppopopopop44444");  
	  var photos =  req.responseXML.getElementsByTagName("photos")[0];	  
	//  alert(photos); 
		var i = 0;
	  for (loop = photos.childNodes.length-1; loop>=0; loop--)
	  {
	  var photo = photos.childNodes[loop];	
	  //  var title = (photo.getElementsByTagName("title")[0]).firstChild.nodeValue; 
	  var imageID = (photo.getElementsByTagName("imageID")[0]).firstChild.nodeValue;
	  var thumbImage = (photo.getElementsByTagName("thumbImage")[0]).firstChild.nodeValue;	
		thumbImage=  "<IMG SRC='/upload/imageGallery/thumbImage/"+thumbImage+"' width='100' height='80' border='0' >";	 
	 	childDiv1.innerHTML += "<a href=\"http://www.merinews.com/newPhotoLanding.jsp?imageID=" + imageID + "\" target='_blank'>" + thumbImage + "</a>";
	     
	   //  myTable.appendChild(childDiv1);	
	    //  myTable.appendChild(childDiv2);	  
	  }	
	   myTable.appendChild(childDiv1);
	  childDiv1.innerHTML +=  "<a href='JavaScript:randomPhoto();'><img src='/mnc/images/arrow.gif' border='0' width='33' height='80'/></a>";
	
}	

function getNodeText(node){
	if(node.tagName){
		var txt = "<" + node.tagName;
		var attributes = node.attributes;
		for(var i = 0; i < attributes.length; i++){
			txt += " " + attributes[i].nodeName + "=\"" + node.attributes[i].nodeValue + "\"";
		}
		if(node.hasChildNodes()){
			txt += ">";
			for(var i = 0; i < node.childNodes.length; i++){
				txt += getNodeText(node.childNodes[i]);
			}
			txt += "</" + node.tagName + ">";
		}
		else {
			txt += "/>";
		}
		return txt;
	}
	if(node.data){
		return node.data;
	}
	return "";
}	
//cut String
function cutAllString(toMasked,length){
  var masked=toMasked;
  //alert(toMasked);
  if (toMasked.length<=length){
   document.write(toMasked);
   return ;
   }
  masked=toMasked.substring(0, length)+"..";
 if(masked.lastIndexOf(' ')!=-1 || masked.lastIndexOf(',')!=-1){
   var toLength=0;
					if(masked.lastIndexOf(' ')>masked.lastIndexOf(','))
						toLength=masked.lastIndexOf(' ');
					else
						toLength=masked.lastIndexOf(',');
					
					masked=masked.substring(0,toLength)+".."	;
 }
 document.write(masked);
} 
function cutAllStringNew(toMasked,length){
  var masked=toMasked;
  //alert(toMasked);
  if (toMasked.length<=length){
  
   return toMasked;
   }
  masked=toMasked.substring(0, length)+"..";
 if(masked.lastIndexOf(' ')!=-1 || masked.lastIndexOf(',')!=-1){
   var toLength=0;
					if(masked.lastIndexOf(' ')>masked.lastIndexOf(','))
						toLength=masked.lastIndexOf(' ');
					else
						toLength=masked.lastIndexOf(',');
					
					masked=masked.substring(0,toLength)+".."	;
 }
 return masked;
} 

//cut string end
//date Format
/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

function displayPostDate(howmany,hiddenname,hiddendate){
//if (howmany>=4) return;
	var temp="";
	var temp1="";
	
	var year;
	var month;
	var date;
	var hour;
	var min;
	var sec;
	for(var i=0; i<howmany; i++){
		var post1 = document.getElementById(hiddenname+i).value;
		year = Number(post1.substring(0, post1.indexOf("-")));
		post1 = post1.replace(post1.substring(0, post1.indexOf("-"))+"-", "");
		month = Number(post1.substring(0, post1.indexOf("-"))-1);
		post1 = post1.replace(post1.substring(0, post1.indexOf("-"))+"-", "");
		date = Number(post1.substring(0, post1.indexOf(" ")));
		post1 = post1.replace(post1.substring(0, post1.indexOf(" "))+" ", "");
		
		hour = Number(post1.substring(0, post1.indexOf(":")));
		post1 = post1.replace(post1.substring(0, post1.indexOf(":"))+":", "");
		min = Number(post1.substring(0, post1.indexOf(":")));
		post1 = post1.replace(post1.substring(0, post1.indexOf(":"))+":", "");
		sec = Number(post1.substring(0, post1.indexOf(".")));
		var postDate = new Date(year, month, date, hour, min, sec);
		var aTag = document.getElementById(hiddendate+i);
		aTag.innerHTML=calculate(howmany,postDate,myDate);
		//aTag.innerHTML=month;
		}
	}
	
	function p (i)
{
	return Math.floor(i / 10) + "" + i % 10;
}

function init ()
{
	var form = document.getElementById('form');
	var date = new Date();
	var s = p(date.getMonth() + 1) + "/" + p(date.getDate()) + "/" + date.getFullYear() + " " + p(date.getHours()) + ":" + p(date.getMinutes()) + ":" + p(date.getSeconds());
	if (form.date1.value == "")
		form.date1.value = s;
	if (form.date2.value == "")
		form.date2.value = s;
}

function trunc (i)
{
	var j = Math.round(i * 100);
	return Math.floor(j / 100) + (j % 100 > 0 ? "." + p(j % 100) : "");
}

function calculate (howmany,date1 , date2)
{
	var date1 = new Date(date1);
	var date2 = new Date(date2);
	var sec = date2.getTime() - date1.getTime();
	//alert(date1+":"+date2+":"+sec);
	if (isNaN(sec))
	{
		alert("Input data is incorrect!");
		return;
	}
	if (sec < 0)
	{
		alert("The second date ocurred earlier than the first one!");
		return;
	}

	var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;

	//form.result_h.value = trunc(sec / hour);
	//form.result_m.value = trunc(sec / minute);
	//form.result_s.value = trunc(sec / second);

	var days = Math.floor(sec / day);
	sec -= days * day;
	var hours = Math.floor(sec / hour);
	sec -= hours * hour;
	var minutes = Math.floor(sec / minute);
	sec -= minutes * minute;
	var seconds = Math.floor(sec / second);
	//alert(hours);
	
	/*if(days > 0 && days <2){
		return days + " day" + (days != 1 ? "s" : "") + " ago";
	}else if(days >=2){
	*/
	//alert(date1.format("d mmm, yyyy HH:MM:ss")+" IST");
	if (howmany==1)	return date1.format("d mmm, yyyy HH:MM:ss")+" IST";
	else return date1.format("d mmm, yyyy");
	/*
	else if(hours>0){
		return hours + " hour" + (hours != 1 ? "s" : "") + " ago";
	}else if(minutes>0) {
		return minutes + " minute" + (minutes != 1 ? "s" : "") + " ago";
	}else if(seconds > 0){
		return seconds + " second" + (seconds != 1 ? "s" : "") + " ago";
	}
	
	return days + " day" + (days != 1 ? "s" : "") + ", " + hours + " hour" + (hours != 1 ? "s" : "") + ", " + minutes + " minute" + (minutes != 1 ? "s" : "") + ", " + seconds + " second" + (seconds != 1 ? "s" : "");
	//alert(days + " day" + (days != 1 ? "s" : "") + ", " + hours + " hour" + (hours != 1 ? "s" : "") + ", " + minutes + " minute" + (minutes != 1 ? "s" : "") + ", " + seconds + " second" + (seconds != 1 ? "s" : ""));
     */
}
//displayPostDate(4,'post','disDate'); call from respective jsp/html

var tdId;
var formSubmit
var divId;
var verifyResult;
var verifyFlag=true;


function verify(form) {	
	formSubmit = form;
	//alert( "inside  varify method ");
	imageText = form.verifyImageText.value;
	var url = "/verifyImage.do?ImageText=" + imageText;
	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//alert(req.readyState);
	req.open("POST", url, true);
	//alert(req.readyState);
	req.onreadystatechange = getArticles12;
	
	req.send(null);	
	
 }
 
function getArticles12() {
	
	if (req.readyState == 4) {
		
		if (req.status == 200) {
			//alert(req.responseText);
			var text = req.responseText;
			//alert("aaa"+text+"aaa");
			if(text=='true'){
				formSubmit.submit();
			}
			else{
			alert("Please enter correct Verification code");
			 formSubmit.verifyImageText.focus();
			}
		}
	}
}
//
// function to validate input fields of comment form
var imageVertify;
var myForm11;
function validateCommentForm(form, msg ){
myForm11=eval(document.getElementById(form));
   	form = eval(document.getElementById(form));
   	if(form.verifyImageText.value == ""){
		alert("Please enter Verification code");
		form.verifyImageText.focus();
		return false;
	}
	
/*	if(form.verifyImageText.value.toLowerCase() != form.verifyImageName.value.toLowerCase()){
		alert("Please enter correct Verification code");
		form.verifyImageText.focus();
		return false;
	} */
	if(form.commenterName.value == "" || form.commenterName.value == "Name"){
		alert("Please enter Name");
		form.commenterName.focus();
		return false;
	}
	if(form.email.value == "" || form.email.value == "Email"){
		alert("Please enter Email");
		form.email.focus();
		return false;
	}
	else if(!isValidEmail(form.email.value)) {
		alert( "Please enter valid E-mail address");
		form.email.focus();
		return false;
	}
	if(isBlank(form.description.value)){
		alert("Please enter comment");
		form.description.focus();
		return false;
	}
	
	 verifyImVal(form.verifyImageText,"verifyImageCommentidCC");	
	
}

function validateCommentForm2(form, msg ){

   //alert(form);
   	form = eval(document.getElementById(form));
   	myForm11= form;
   	if(form.verifyImageText.value == ""){
		alert("Please enter Verification code");
		form.verifyImageText.focus();
		return false;
	}
	
/*	if(form.verifyImageText.value.toLowerCase() != form.verifyImageName.value.toLowerCase()){
		alert("Please enter correct Verification code");
		form.verifyImageText.focus();
		return false;
	} */
	if(form.commenterName.value == "" || form.commenterName.value == "Name"){
		alert("Please enter Name");
		form.commenterName.focus();
		return false;
	}
	if(form.email.value == "" || form.email.value == "Email"){
		alert("Please enter Email");
		form.email.focus();
		return false;
	}
	else if(!isValidEmail(form.email.value)) {
		alert( "Please enter valid E-mail address");
		form.email.focus();
		return false;
	}
	if(isBlank(form.description.value)){
		alert("Please enter comment");
		form.description.focus();
		return false;
	}
	
	 verifyImVal(form.verifyImageText,"verifyImageCommentid");	
	
}

function showMessage()
{
alert('hiaaa'+verifyFlag+"dddddddd");
if(verifyFlag == "NotSame")
	{
		alert("Please enter correct Verification code");
		// form.verifyImageText.focus();
		return false;
	}

}
function isBlank(val){
	if(val==null || val=="Comments"){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
function isValidEmail(email){
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test(email));
}



function nameDisplay(name){
var CCName=name

var CName=CName.length;


for (i=0;CName>6;i++){
 var sname=CCName.substring(0,6)
 CName=CName-sname;

document.write("The number is " + sname);
document.write("<br />");
}
}

function verifyIm() {	
	//alert( "inside  varify method ");
	var imageText =document.getElementById("verifyImageText").value;
	
	var url = "/verifyImage.do?ImageText=" + imageText;
	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//alert(req.readyState);
	req.open("POST", url, true);
	//alert(req.readyState);
	req.onreadystatechange = getVeriyMessage;
	
	req.send(null);	
	
 }
 var myobjectnew1;
 var whichidtobuildid="";
function verifyImVal(valnewobj,whichidtobuild) {	
myobjectnew1=valnewobj;
whichidtobuildid=whichidtobuild;
	//alert( "inside  varify method ");
	var imageText =valnewobj.value;
	myForm11.verifyImageText.value=valnewobj.value;
	var url = "/verifyImage.do?ImageText=" + imageText;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//alert(req.readyState);
	req.open("POST", url, true);
	//alert(req.readyState);
	req.onreadystatechange = getVeriyMessage2;
	
	req.send(null);	
	
 }
 
 function getVeriyMessage() {
	
	if (req.readyState == 4) {
		
		if (req.status == 200) {
			//alert(req.responseText);
			var text = req.responseText;
			//alert("aaa"+text+"aaa");
			if(text=='true'){
				myForm11.submit();
			}
			else{
			alert("Please enter correct Verification code");
			 checkforVerifyImage();
			 document.getElementById("verifyImageText").focus();
			}
		}
	}
}
 function getVeriyMessage2() {

	if (req.readyState == 4) {
		
		if (req.status == 200) {
			//alert(req.responseText);
			var text = req.responseText;
			//alert("aaa"+text+"aaa");
			if(text=='true'){
				myForm11.submit();
			}
			else{
			//alert(myForm11.id.substring(0,4));
			alert("Please enter correct Verification code");
			if (myForm11.id.substring(0,4)=='form'){
			//if (window.ActiveXObject){
            var randomnumber1=Math.floor(Math.random()*100);
            myobjectnew1.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("td")[0].innerHTML='<div id="verifyImageCommentidCC" style="display: inline;" id="'+randomnumber1+'"><img id="imageIframe" name="imageIframe" src="/jcaptcha?id='+randomnumber1+'" width="140" height="30"></div>';
            //myobjectnew1.parentNode.parentNode.firstChild.firstChild.innerHTML='<img id="imageIframe1" height="30" width="140" name="imageIframe1" src="/jcaptcha?id='+randomnumber+'"/>';
			}else{
            var randomnumber=Math.floor(Math.random()*100);
            document.getElementById("imageIframe1").parentNode.parentNode.innerHTML='<span style="display: inline;"><img id="imageIframe1" height="30" width="140" name="imageIframe1" src="/jcaptcha?id='+randomnumber+'"/></span>';
			}
			 myobjectnew1.focus();
			}
		}
	}
}

function checkforVerifyImage(){

  var rightAds00="<iframe src='/jcaptcha'";
 rightAds00=rightAds00+" align='top' marginheight='0' marginwidth='0' width='140' height='30' frameborder='0' scrolling='no'>";
 rightAds00=rightAds00+"</iframe>";
//document.getElementById(whichidtobuildid).innerHTML=rightAds00;
//document.getElementById("verifyImageCommentidCC").innerHTML=document.getElementById("verifyImageCommentid").innerHTML;

//document.getElementById("").innerHTML='sdfvdf<img id="imageIframe1" name="imageIframe1" src="/jcaptcha" width="140" height="23" />';

//document.forms[0].submit;
}

var totalArticlesForLatestCat=0;

function displayCatarticles(){
//alert(totalArticlesForLatestCat+window.location);
var winloction=window.location+'';
//alert(winloction);
var mytempcalled="";
if (winloction.split("/").length>=5){
  mytempcalled=winloction.split("/")[5].split(".")[0];
  }
else {
      //  alert('fff');
       mytempcalled=winloction.split("=")[1];
       }
//alert(mytempcalled);
 if  (document.getElementById("catnewarticleid"+mytempcalled)=='null' || 
      document.getElementById("catnewarticleid"+mytempcalled)==null){
      //alert('w');
      if (totalArticlesForLatestCat==0 || totalArticlesForLatestCat>4){
      //alert('d');
      document.getElementById("catnewarticleid"+document.getElementById("articleIDhiddenCat").value).style.display="none";
      document.getElementById("catnewarticleid"+document.getElementById("articleIDhiddenCat").value).style.visibility="hidden";
      }
  }  else {
      //alert('k');
      document.getElementById("catnewarticleid"+mytempcalled).style.display="none";
      document.getElementById("catnewarticleid"+mytempcalled).style.visibility="hidden";
  }
}
// To display x=6 photos in landing page 
var nofphotostodisplay=6;
 function displayCatPhotos(idName_prefix,actualphotos){
var ph_index=actualphotos-nofphotostodisplay;
if (ph_index>0){
      for(var ph_index_1=1;ph_index_1<=ph_index;ph_index_1++){
      document.getElementById(idName_prefix+ph_index_1).style.display="none";
      document.getElementById(idName_prefix+ph_index_1).style.visibility="hidden";
      }
}
}
 
