// JavaScript functions
function checkContact()
{
 document.forms[0].firstName.value=trimSpaces(document.forms[0].firstName.value);
 document.forms[0].lastName.value=trimSpaces(document.forms[0].lastName.value);
 document.forms[0].email.value=trimSpaces(document.forms[0].email.value);
 if(document.forms[0].lastName.value.length<=0)
  { 
    alert("Enter your last name");
	document.forms[0].lastName.focus();
	return false;
  }  
  if(document.forms[0].firstName.value.length<=0)
  { 
    alert("Enter your first name");
	document.forms[0].firstName.focus();
	return false;
  }
if(document.forms[0].email.value.length<=0)
  {
    alert("Enter your email id");
	document.forms[0].email.focus();
	return false;
  }
 else
  {
   if(!checkEmail(document.forms[0].email.value))
   {
	document.forms[0].email.focus();
	return false;
   }
  }
 document.forms[0].message.value=trimSpaces(document.forms[0].message.value);
 if(document.forms[0].message.value.length<=0)
  {
    alert("Enter your Message");
	document.forms[0].message.focus();
	return false;
  } 
  document.forms[0].frmAction.value="add";
  document.forms[0].submit();
  }

function checkDelContact(toDo)
{
   rowSelected=false;
 	itemCount = document.forms[0].elements["subscriberid[]"].length;
		if(itemCount > 0) 
		{
			for(ids = 0; ids < itemCount; ids ++) 
			{
				 if(document.forms[0].elements["subscriberid[]"][ids].checked = true)
				 	   { 
						   rowSelected=true;
						   break;
					  }
			}
		}
		else 
		{
				 if(document.forms[0].elements["subscriberid[]"].checked = true)
				 	   { 
						   rowSelected=true;
					  }
		}
	
	if(!rowSelected)
	  {
	   alert("Select a user ");
	   return false;
	  }
  if(toDo=="remove")
   {
    
	document.forms[0].action='showContactList.php';
    document.forms[0].frmAction.value="remove";
    document.forms[0].submit()
   }
  else
   {
   
       document.forms[0].action='selectNewsLetter.php';
	   document.forms[0].submit() 

   }   
}

function printWindow() {
	window.print();
}
function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}
function printCoupon(couponid,flag){
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;

	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	

	window.open("../php/showCouponFrame.php?flag=" + flag + "&couponid=" + couponid, "printCoupon", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}
function checkCouponMail() {
	senderName = trimSpaces(document.forms[0].senderName.value);
	senderEmail = trimSpaces(document.forms[0].senderEmail.value);
	receiverEmail = trimSpaces(document.forms[0].receiverEmail.value);
	if(senderName.length <= 0) {
		alert("You have to enter your name.");
		document.forms[0].senderName.focus();
		return false;
	}
	if(senderEmail.length <= 0) {
		alert("You have to enter your email address.");
		document.forms[0].senderEmail.focus();
		return false;
	}
	if(!checkEmail(senderEmail)) {
		document.forms[0].senderEmail.focus();
		return false;
	}
	if(receiverEmail.length <= 0) {
		alert("You have to enter your friend's email address.");
		document.forms[0].receiverEmail.focus();
		return false;
	}
	if(!checkEmail(receiverEmail)) {
		document.forms[0].receiverEmail.focus();
		return false;
	}
	document.forms[0].frmAction.value = "yes";
}
