// JavaScript Document

function filterNewsletter(Actions)
{
	if(Actions == '1')
		getHTML('../grid/newsletter.php','Value=0&pages=1&Subscribe=subscribe','grid')
	else if(Actions == '0')
		getHTML('../grid/newsletter.php','Value=0&pages=1&Subscribe=unsubscribe','grid')
	else
		getHTML('../grid/newsletter.php','Value=0&pages=1&Subscribe=','grid')
		
} // this function to filter newsletter

function deleteNews()
{
	SelectId = document.Frm_grid.selectedId.value ;
	if(SelectId != ""){
		if(confirm("Are you sure about delete this mails?")){
			document.Frm_grid.action = "newsletter.php?del=1";
			document.Frm_grid.method = "post";
			document.Frm_grid.submit();
		}
	}
	else
		alert('Please select the email!');
}// this funtion to delete newsletter.

function showList() {
  sList = window.open("mail_list.php", "list", "scrollbars=1,resizable=0,width=350,height=400,left = 312,top = 234");
}

function checkboxAll(MailCount)
{
	if(document.getElementById('chall').checked){
		for(i=1;i<=MailCount;i++)
		{
			document.getElementById("ch" + i).checked = true;
		}
	}
	else{
		for(i=1;i<=MailCount;i++)
		{
			document.getElementById("ch" + i).checked = false;
		}
		
	}
}

function selectcheck(MailCount)
{
		var selectedmail = new Array();
		var arraycount = 0;
		for(i=1;i<=MailCount;i++)
		{
			if(document.getElementById("ch" + i).checked){
				selectedmail[arraycount] = document.getElementById("ch" + i).value;
				arraycount++;
			}
			
		} //End For
	document.getElementById("mailSelect").value = selectedmail;
}

function ReturnMail()
{
	if (window.opener && !window.opener.closed)
    window.opener.document.Frm_sendMail.send_to.value = document.getElementById("mailSelect").value;
  	window.close();
}

function ValidField()
{
	SendTO = window.document.Frm_sendMail.send_to;
	SendFrom = window.document.Frm_sendMail.send_from;	
	
	if(Trim(SendTO.value)==""){
		alert("Please insert the E-mail!");
		SendTO.focus();
		return false;
	}
	if(Trim(SendFrom.value)==""){
		alert("Please insert the E-mail!");
		SendFrom.focus();
		return false;
	}
				
}

function checkMail(RChecked)
{
	
	txtMail = document.getElementById('txt_mail');
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	
	if(Trim(txtMail.value) == ""){
		alert('Please enter the E-Mail!');
		txtMail.focus();
		document.getElementById(RChecked).checked = false;
		return false;	
	}
	else if(!emailpat.test( Trim(txtMail.value))){
		alert('Please enter a valid email address');
		txtMail.focus();
		document.getElementById(RChecked).checked = false;
		return false;	
	}
	else
		return true;
}

function Subscribe(Type,RChecked)
{
	txtMail = document.getElementById('txt_mail');
	if(checkMail(RChecked)){
		if(Type == "1")	
			location = 'newsletter.php?type=subscribe&mail='+txtMail.value;
		else
			location = 'newsletter.php?type=unsubscribe&mail='+txtMail.value;
		
	}
	 
}
/*function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 312,top = 234');");
}*/
