/**
 * Ny Content Module JS Files
 * @author Pathfinder Solutions India
 * @link http://www.pathfindersolutions.biz
 * @version 1.0
 * @package YouthActionNet
 * @subpackage Marketplace
 */

/**
 * fnAddRegion function
 * @param string type,string name,int ID,string cssclass,varchar value,bool checked
 * @return bool true or false
 */
function fnOpenCloseControl(stridname , index)
{
	strShowId = stridname + '[' + index + ']';

	if (document.getElementById(strShowId).style.display == "none")
	{
		document.getElementById(strShowId).style.display = "";
	}
	else
	{
		document.getElementById(strShowId).style.display = "none";
	}
}

function fnValidateInput(id)
{
	if (document.getElementById(id).value == "")
	{
		alert('Enter comment text\n');
		return false;
	}
	else
	{
		document.getElementById('id_frmAddcomment').submit();

	}
}


/**
 * fnEmailArticle function
 * @param no, type, divId, userid
 * @return fnEmailArticle
 */	
	function fnEmailArticle(no,type,username,articleid,strMultimediaType )
	{
	  
	 
	    var strErrorMessage = "";
		if ( document.getElementById('id_txtFromEmail').value == "")
		{
			strErrorMessage = strErrorMessage + "Enter Your Email Address. \n";
		}
		
		if ( document.getElementById('id_txtRecepient').value == "")
		{
			strErrorMessage = strErrorMessage + "Enter Recepient Email Address. \n";
		}

		if(document.getElementById('id_txtFromEmail').value != "")
		{
			var emailStr2 = document.getElementById('id_txtFromEmail').value;
			
			if(!fnEmailCheck (emailStr2))
			{
				strErrorMessage = strErrorMessage + "Enter Your Valid  Email Address. \n";
			}
		}

		if(document.getElementById('id_txtRecepient').value != "")
		{
			var emailStr2 = document.getElementById('id_txt'+type+'Recepient').value;
			
			var emailArray = [];
			emailArray = emailStr2.split(",");
			for(var index=0; index < emailArray.length; index++)
			{
				if(!fnEmailCheck (emailArray[index]))
				{
					strErrorMessage = strErrorMessage + "Enter Valid Email Address of recepient. \n";
				}
			}
		}


	  var strFrom = document.getElementById("id_txtFromEmail").value;	
	  var strTo = document.getElementById("id_txtRecepient").value;	
	  //var strMessage = document.getElementById("id_txtMessage").value;	
	  var strSendCopy = "false";
	  if(document.getElementById("id_chkSendMeCopy").checked)
	  {
	  		strSendCopy = 'true';
	  }

	  if (strErrorMessage != "")
  	  {
		alert(strErrorMessage);
		return false;
	  }
 
	  var div = document.getElementById("id_divEmail");
	  div.style.display = "none";
	  Lightbox.hideBox();
      if(strMultimediaType=="PODCAST")
	  {     
	      var strSubject   = username+"\n  invited you to listen to this podcast.";
		  var strSubjectContent = username+"\n  invited you to listen to this podcast at the YouthActionNet Marketplace. ";
	  
	  }
	  if(strMultimediaType=="PICTURE")
	  {
		  var strSubject = username+"\n  has invited you to view this picture.";
		  var strSubjectContent = username+"\n  has invited you to view this picture at the YouthActionNet Marketplace.";
	  }
	  if(strMultimediaType=="VIDEO")
	  {
		var strSubjectContent = username+"\n  has invited you to watch this video at the YouthActionNet Marketplace";
		var strSubject = username+"\n has invited you to watch this video";
	  }
	//  var strSubject = username+"  invited you to view "+strMultimediaType;
	  
	  var strPerMessage = document.getElementById("id_txtMessage").value;	
	  //& creating problem to display whole content text so replacing it with 'and' word
 	  strPerMessage = strPerMessage.replace(/&/g, " and ");
	  strPerMessage = strPerMessage.replace(/\n/g, "<br>");

		if(strErrorMessage=="")
		{      
			  fnAjaxCaller('id_divResponse','multimediadetails','emailmultimedia', '&sender='+strFrom+'&recepient='+strTo+'&subject='+strSubject+'&message='+strSubject+'&personalmsg='+strPerMessage+'&sendcopy='+strSendCopy+'&multimediaID='+articleid, '', '');
		}
	  
	}
	
/**
 * fnHideShowLightBox function
 * @param
 * @return shows Email LightBox and hide Content Div
 */	
	function fnHideShowLightBox()
	{
		//document.getElementById("watchmultimedia").style.display = "none";
		Lightbox.showBoxByID('id_divEmail', 400, 400);
	}