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 "";
}	
	
	
	
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

