// JavaScript Document for alps web shop
function calldel(m)
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}
function  frontlog()
{
	if(document.Frmlogin.txtUsername.value=="")
	{
	   alert("Enter the Username");
	   document.Frmlogin.txtUsername.focus();
	   return false;
	}
	if(document.Frmlogin.txtPassword.value=="")
	{
	   alert("Enter the Password");
	   document.Frmlogin.txtPassword.focus();
	   return false;
	}	
	
	return true;
}
//forget password 
function password_validate()
{
   if(document.Frmgetpass.txtUser.value=="")
	{
  alert("Please Enter the Username");
  document.Frmgetpass.txtUser.focus();
  return false;s
	}
   if(document.Frmgetpass.txtEmail.value=="")
	{
  alert("Please Enter the Email");
  document.Frmgetpass.txtEmail.focus();
  return false;s
	}
   var res=emailcheck(document.Frmgetpass.txtEmail.value);
		 if(res)
		 {
			 alert("Please enter valid Email Address with correct domain name (i.e).com,.org.in");
			 document.Frmgetpass.txtEmail.focus();
			 flagcheck=false;
			 return false;
		 }
}

//subscribe validations
function newsletter_validation()
{
			if(document.subscribe.fromname.value=="")
			{
			   alert("Enter the name");
			   document.subscribe.fromname.focus();
			   return false;
			}
	 if(!validateEmail(document.subscribe.frommail.value,1,1))
	{
	   document.subscribe.frommail.focus();
	   return false;
	}
}
//subscribe editvalidations
function newsletter_validation1()
{
			if(document.sub_edit.fromname.value=="")
			{
			   alert("Enter the name");
			   document.sub_edit.fromname.focus();
			   return false;
			}
	 if(!validateEmail(document.sub_edit.frommail.value,1,1))
	{
	   document.sub_edit.frommail.focus();
	   return false;
	}
}

//newsvalidations
function news_validation()
{
			if(document.frm_new.txtFromName.value=="")
			{
			   alert("Enter the FromName");
			   document.frm_new.txtFromName.focus();
			   return false;
			}
	 if(!validateEmail(document.frm_new.txtFromEmail.value,1,1))
	{
	   document.frm_new.txtFromEmail.focus();
	   return false;
	}
			if(document.frm_new.txtSubject.value=="")
			{
			   alert("Enter the Subject");
			   document.frm_new.txtSubject.focus();
			   return false;
			}
/*			if(document.frm_new.txtMessage.value=="")
			{
			   alert("Enter the Message");
			   document.frm_new.txtMessage.focus();
			   return false;
			}
*/
}

function changeList( box ) 
{
	list = lists[box.options[box.selectedIndex].value];
	if(box.options[box.selectedIndex].value != "select")
	{
		emptyList( box.form.subCategory );
		fillList( box.form.subCategory,list);
	}
}

function submitCategoryForm() {
	var list = document.form.list;
	theList="";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
	theList += list.options[i].text;
	// a "&" only BETWEEN the items, so not at the end
	if (i != list.options.length-1) theList += "&;";
	}
	document.form.priority.value=theList;
	document.form.action="index.php?task=eventcategoryorder";
	}
	
	//Function Priority
function submitForm() {
	var list = document.form.list;
	theList="";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
	theList += list.options[i].text;
	// a "&" only BETWEEN the items, so not at the end
	if (i != list.options.length-1) theList += "&;";
	}
	document.form.priority.value=theList;
	document.form.action="index.php?do=category&task=categoryorder";
	}


function submitForm1() {
	var list = document.form.list;
	theList="";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
	theList += list.options[i].text;
	// a "&" only BETWEEN the items, so not at the end
	if (i != list.options.length-1) theList += "&;";
	}
	document.form.priority.value=theList;
	document.form.action="index.php?task=subcategoryorder";
	}
function subcategory_validation()
{
		if(document.frm_subcategory.txtCategory.value=="Select")
			{
			   alert("Please select the category name");
			   document.frm_subcategory.txtCategory.focus();
			   return false;
			}
      	if(document.frm_subcategory.txtSubCategory.value=="")
			{
			   alert("Please enter the sub category name");
			   document.frm_subcategory.txtSubCategory.focus();
			   return false;
			}
		if(document.frm_subcategory.txtStatus.value=="")
			{
			   alert("Please select the status");
			   document.frm_subcategory.txtStatus.focus();
			   return false;
			}
}


function admin_validation(){
var txtUsername=document.Login.txtUsername.value;
	 if(txtUsername == "")
			 {
			 alert("User name is empty");
			 document.Login.txtUsername.focus();
			 return false;
			 }
var txtPassword=document.Login.txtPassword.value;
	 if(txtPassword == ""){
			 alert("Password is empty");
			 document.Login.txtPassword.focus();
			 return false;
	}
}

function custsearch_validation(){
	if(document.frm_cust.searchval.value=="")
			{
			   alert("Please enter the search text");
			   document.frm_cust.searchval.focus();
			   return false;
			}
}

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}

function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function popservices(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function showsubcat(catid,mid){
	window.location.href = "index.php?task=addcoupon&catname="+catid+"&m_id="+mid;
}
function addproduct_showsubcat(catid){
	window.location.href = "index.php?task=addcoupon&catname="+catid;
}
function showlengthprice(typename,mid)
{
	alert(mid);
	//window.location.href = "index.php?task=addcoupon&type="+typename+"&m_id="+mid;
}
function showhide(){
		if (!(document.frm_register.chkDelivery.checked)){
		delistyle=document.getElementById("delivery");
		    if(delistyle){
			delistyle.style.display="block";
			delistyle.style.visibility="visible";
			}				
		}
		else
		{
			delistyle=document.getElementById("delivery");
			if(delistyle){
			delistyle.style.display="none";
			delistyle.style.visibility="hidden";
			}
		}
	}
	
//function for poll 
function pollscript() {
	var pollvalue = document.PostNewPoll.polloption.value;
	//window.location.href("index.php?task=poll_add&cnt="+pollvalue);
	document.PostNewPoll.action="index.php?task=poll_add&cnt="+pollvalue;
	document.PostNewPoll.submit();
}
function pollscriptedit(id) {
	var pollvalue = document.PostNewPoll.polloption.value;
	//window.location.href("index.php?task=poll_add&cnt="+pollvalue);
	document.PostNewPoll.action="index.php?task=poll_edit&id="+id+"&cnt="+pollvalue+"&action=true";
	document.PostNewPoll.submit();
}

//validation for General Setting
function generalsetting_validate(){
	if (document.form_general.txt_website.value == "") 
		{
			alert ("Please Enter the Website URL.");
			document.form_general.txt_website.focus();
			return false;
		}
		re = /^(file|http):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc|in|cd|nw)$/i
		 if (!(re.test(document.form_general.txt_website.value))) {
		 alert ("Invalid URL.");
		 document.form_general.txt_website.focus();
		 return false;
		 }
		
	if (document.form_general.txt_numrows.value == "") 
		{
			alert ("Please Enter the number of rows displayed per page.");
			document.form_general.txt_numrows.focus();
			return false;
		}
	recordvalue = document.form_general.txt_numrows.value;
		if((recordvalue == "")  || (recordvalue == 0) || isNaN(recordvalue) ||  (recordvalue.indexOf("-") >= 0) || (recordvalue.indexOf(".") >= 0) || (recordvalue > 65535) ){
			alert ("Please enter the valid number of rows per page.");
			document.form_general.txt_numrows.focus();
			return false;
		}
	if (document.form_general.txt_admintitle.value == "") 
		{
			alert ("Please Enter the Admin title.");
			document.form_general.txt_admintitle.focus();
			return false;
		}
	if (document.form_general.txt_hometitle.value == "") 
		{
			alert ("Please Enter the Home page title.");
			document.form_general.txt_hometitle.focus();
			return false;
		}
}


//Myprofile validation
function myprofile_validate(){
	if (document.form_myprofile.txt_contactperson.value == "") 
		{
			alert ("Please Enter the Contact Person name.");
			document.form_myprofile.txt_contactperson.focus();
			return false;
		}
		if (!validateEmail(document.form_myprofile.txt_email.value,1,1)) 
		{
			document.form_myprofile.txt_email.focus();
			return false;
		}
		if (!validateEmail(document.form_myprofile.txt_email.value,1,1)) 
		{
			document.form_myprofile.txt_email.focus();
			return false;
		}
		if (document.form_myprofile.txt_address1.value == "") 
		{
			alert ("Please Enter the Address1.");
			document.form_myprofile.txt_address1.focus();
			return false;
		}
		if (document.form_myprofile.txt_city.value == "") 
		{
			alert ("Please Enter the City.");
			document.form_myprofile.txt_city.focus();
			return false;
		}
		if (document.form_myprofile.txt_state.value == "") 
		{
			alert ("Please Enter the State.");
			document.form_myprofile.txt_state.focus();
			return false;
		}
		recordvalue = document.form_myprofile.txt_postcode.value;
		if( (recordvalue == "")  || (recordvalue == 0) || isNaN(recordvalue) ||  (recordvalue.indexOf("-") >= 0) || (recordvalue.indexOf(".") >= 0) ){
			alert ("Please enter the valid Postcode.");
			document.form_myprofile.txt_postcode.focus();
			return false;
		}
		if (document.form_myprofile.txt_country.value == "") 
		{
			alert ("Please Enter the Country.");
			document.form_myprofile.txt_country.focus();
			return false;
		}
		if (document.form_myprofile.txt_phone.value == "") 
		{
			alert ("Please Enter the Phone Number.");
			document.form_myprofile.txt_phone.focus();
			return false;
		}
		phone = document.form_myprofile.txt_phone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
		if (document.form_myprofile.txt_username.value == "") 
		{
			alert ("Please Enter the User Name.");
			document.form_myprofile.txt_username.focus();
			return false;
		}
		if (document.form_myprofile.txt_password.value == "") 
		{
			alert ("Please Enter the Password.");
			document.form_myprofile.txt_password.focus();
			return false;
		}
}



//Function to get the color
function ChangeColor(s,dest)
  {
  	var newcolor=showModalDialog("../../include/select_color.html","","resizable: no; help: no; status: no; scroll: no;");
	if(newcolor != null)
	document.getElementById(s).value="#"+newcolor;
	document.getElementById(dest).style.background="#"+newcolor;
  }


function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
//Function for Department
function changecat_events(){
	var catname=document.frm_viewevents.catid.value;
		if (catname=="All"){
				window.location.href="index.php?task=eventview";
		}
		else{
				window.location.href="index.php?task=eventview&calmode="+document.frm_viewevents.catid.value;
		}
	}

//Add More Fields
function insertMoreUpload_form() 
{ 
	var nUploads = parseInt(document.getElementById('NumberOfUploads').value)+1;		 
	var tbody = document.getElementById("tabUpload").getElementsByTagName("tbody")[1]; 
	var row = document.createElement("TR"); 

	//insert second <td>
	var cell2 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell2.setAttribute("valign","middle");
	cell2.setAttribute("align","center");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","labelname" + nUploads);
	eInput.setAttribute("id","Label");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-serif; text-decoration:none;");	
	cell2.appendChild(eInput);
	
	// append all <td> to <tr>
	//insert second <td>
	var cell3 = document.createElement("TD");
	cell3.setAttribute("valign","middle");
	cell3.setAttribute("align","center");
	//File
	/*var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","fieldtype" + nUploads);
	eInput.setAttribute("id","fieldtype" + nUploads);
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");	
	cell3.appendChild(eInput);*/
	
	//File
	listarray = new Array("TextBox","TextArea","ListBox","RadioButton","CheckBox","FileField");
	var eInput = document.createElement("select"); 
	eInput.setAttribute("name","fieldtype" + nUploads);
	eInput.setAttribute("id","Type");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");
		var doc = eInput.ownerDocument;
		if (!doc)
			doc = eInput.document;
		for(listindex = 0; listindex < 6; listindex++){
			var opt = doc.createElement('OPTION');
			opt.value = listarray[listindex];
			opt.text = listarray[listindex];
			eInput.options.add(opt,listindex);
		}

	//eInput.new Option("TextBox","TextBox");
	cell3.appendChild(eInput);
	
	

	var cell4 = document.createElement("TD");
	//cell2.setAttribute("colspan","2");
	cell4.setAttribute("valign","top");
	cell4.setAttribute("align","center");
	//File
	var eInput = document.createElement("INPUT"); 
	eInput.setAttribute("type","text");
	eInput.setAttribute("name","fieldvalue" + nUploads);
	eInput.setAttribute("id","FieldValue");
	eInput.setAttribute("style", "FONT: 11px Verdana, Arial, Helvetica, sans-seri; text-decoration:none; color: #006699;");	
	cell4.appendChild(eInput);
	

	row.appendChild(cell2); 
	row.appendChild(cell3); 
	row.appendChild(cell4); 
	tbody.appendChild(row);
	document.frm_updateform.NumberOfUploads.value = nUploads;
	return false;
}


//image Gallery
function addimg_validate(){
	if (document.addimage.filename.value == "") 
		{
				alert ("Please Browse the Image name.");
				document.addimage.filename.focus();
				return false;
		}
}

 function showState(passcountry){
		if (document.getElementById(passcountry).value == "United States of America"){
			postate = document.getElementById("poststate");
			if(postate){
				postate.style.display="block";
				postate.style.visibility="visible";
			}
			pootherstate = document.getElementById("postotherstate");
			if(pootherstate){
				pootherstate.style.display="none";
				pootherstate.style.visibility="hidden";
			}
		}
		else{
			pootherstate = document.getElementById("postotherstate");
			if(pootherstate){
				pootherstate.style.display="block";
				pootherstate.style.visibility="visible";
			}
			postate = document.getElementById("poststate");
			if(postate){
				postate.style.display="none";
				postate.style.visibility="hidden";
			}
		}
	}


//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

 //Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//script validation for date 
function date_valid(dateissue,dateissue2){
	var stdate=dateissue.split("/");
	var enddate=dateissue2.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}


//Move priority & Select Date
function showEventCalendar(){
		if (document.frm_addevent.rdoEventType[0].checked ){
			onetimest = document.getElementById("onetime");
			
			if(onetimest){
				onetimest.style.display="block";
				onetimest.style.visibility="visible";
			}
			multitimest = document.getElementById("multitime");
			if(multitimest){
				multitimest.style.display="none";
				multitimest.style.visibility="hidden";
			}
		}
		if (document.frm_addevent.rdoEventType[1].checked){
			onetimest = document.getElementById("onetime");
			
			if(onetimest){
				onetimest.style.display="none";
				onetimest.style.visibility="hidden";
			}
			multitimest = document.getElementById("multitime");
			if(multitimest){
				multitimest.style.display="block";
				multitimest.style.visibility="visible";
			}
			
		}
		
	}


//Move the Settings
function move(index,to) {
		var list = document.form.list;
		var total = list.options.length-1;
		if (index == -1) return false;
		if (to == +1 && index == total) return false;
		if (to == -1 && index == 0) return false;
		var items = new Array;
		var values = new Array;
		for (i = total; i >= 0; i--) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
		}
		for (i = total; i >= 0; i--) {
		if (index == i) {
		list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
		list.options[i] = new Option(items[i + to], values[i]);
		i--;
		}
		else {
		list.options[i] = new Option(items[i], values[i]);
		   }
		}
		list.focus();
}



function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length < 1 || month < 1 || month > 12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month==2 && day > daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year < minYear || year > maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
} 
	function pay_search()
	{
	var payname=document.payform.paystatus.value;
	var dof="member";
		if (payname=="All")
			{
				window.location.href="index.php?do=member&task=view_member";
			}
		else
			{
				window.location.href="index.php?paystatus="+document.payform.paystatus.value+"&do=member&task=view_member";
			}
	}
function category_validate(){
		if(document.frm_procategory.txt_catname.value == "")
		{
		   alert("Please enter the Category name");
		   document.frm_procategory.txt_catname.focus();
		   return false;
		}
}
//Validation for subcategory
function subcategory_validate(){
		if(document.form_subcategory.catid.value == "")
		{
		   alert("Please Choose the Category name");
		   document.form_subcategory.catid.focus();
		   return false;
		}
		if(document.form_subcategory.txt_subcatname.value == "")
		{
		   alert("Please Enter the SubCategory name");
		   document.form_subcategory.txt_subcatname.focus();
		   return false;
		}
}

//Validation for coupon
function coupon_validate(){
	if(document.frm_coupon.txt_catname.value == "")
		{
		   alert("Please enter the Category name");
		   document.frm_coupon.txt_catname.focus();
		   return false;
		}
	if(document.frm_coupon.vendor.value == "")
		{
		   alert("Please Select vendor Name");
		   document.frm_coupon.vendor.focus();
		   return false;
		}		
	if(document.frm_coupon.college.value == "")
		{
		   alert("Please Select College Name");
		   document.frm_coupon.college.focus();
		   return false;
		}
	if(document.frm_coupon.title.value == "")
		{
		   alert("Please Enter the title");
		   document.frm_coupon.title.focus();
		   return false;
		}
		
	if(document.frm_coupon.couponinfo.value == "")
		{
		   alert("Please enter the coupon description");
		   document.frm_coupon.couponinfo.focus();
		   return false;
		}
	/*if(document.frm_coupon.couponterm.value == "")
		{
		   alert("Please enter the coupon term");
		   document.frm_coupon.couponterm.focus();
		   return false;
		}*/
	if(document.frm_coupon.price.value == "")
		{
		   alert("Please enter the  coupon price");
		   document.frm_coupon.price.focus();
		   return false;
		}
	if(document.frm_coupon.date.value == "")
		{
		   alert("Please select the Expires Date");
		   document.frm_coupon.date.focus();
		   return false;
		}
	if(document.frm_coupon.bname.value == "")
		{
		   alert("Please enter the  coupon business name");
		   document.frm_coupon.bname.focus();
		   return false;
		}
	if(document.frm_coupon.baddress.value == "")
		{
		   alert("Please enter the coupon business address");
		   document.frm_coupon.baddress.focus();
		   return false;
		}
	if(document.frm_coupon.bcity.value == "")
		{
		   alert("Please enter the  coupon city");
		   document.frm_coupon.bcity.focus();
		   return false;
		}
	if(document.frm_coupon.bstate.value == "")
		{
		   alert("Please enter the coupon state");
		   document.frm_coupon.bstate.focus();
		   return false;
		}
	if(document.frm_coupon.bzip.value == "")
		{
		   alert("Please enter the  coupon zipcode");
		   document.frm_coupon.bzip.focus();
		   return false;
		}
	if(document.frm_coupon.bphone.value == "")
		{
		   alert("Please enter the coupon business phone number");
		   document.frm_coupon.bphone.focus();
		   return false;
		}
	if (document.frm_coupon.bwebsite.value == "") 
		{
			alert ("Please enter the coupon website URL.");
			document.frm_coupon.bwebsite.focus();
			return false;
		}
		re = /^(file|http):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc|in|cd|nw)$/i
		 if (!(re.test(document.frm_coupon.bwebsite.value))) {
		 alert ("Invalid URL.");
		 document.frm_coupon.bwebsite.focus();
		 return false;
		 }
		
	/*if(document.frm_coupon.filethumb.value == "")
		{
		   alert("Please browse the Thumb Image");
		   document.frm_coupon.filethumb.focus();
		   return false;
		}*/
	return true;
}
//vendor vaLIDATIONS
function vendor_validate()
{
		if(document.frm_vendor.business.value == "")
		{
		   alert("Please enter the businessname");
		   document.frm_vendor.business.focus();
		   return false;
		}
		if(document.frm_vendor.contact.value == "")
		{
		   alert("Please enter the contactnumber");
		   document.frm_vendor.contact.focus();
		   return false;
		}
		if(document.frm_vendor.address.value == "")
		{
		   alert("Please Enter the address");
		   document.frm_vendor.address.focus();
		   return false;
		}
		if(document.frm_vendor.city.value == "")
		{
		   alert("Please enter the city name");
		   document.frm_vendor.city.focus();
		   return false;
		}
		if(document.frm_vendor.state.value == "")
		{
		   alert("Please enter the state name");
		   document.frm_vendor.state.focus();
		   return false;
		}
		if(document.frm_vendor.Zip.value == "")
		{
		   alert("Please enter the Zipcode");
		   document.frm_vendor.Zip.focus();
		   return false;
		}
		if(document.frm_vendor.country.value == "")
		{
		   alert("Please enter the country");
		   document.frm_vendor.country.focus();
		   return false;
		}
		if(document.frm_vendor.college.value == "")
		{
		   alert("Please enter the college");
		   document.frm_vendor.college.focus();
		   return false;
		}
		if(document.frm_vendor.username.value == "")
		{
		   alert("Please enter the username");
		   document.frm_vendor.username.focus();
		   return false;
		}
	if(document.frm_vendor.password.value == "")
	{
	   alert("Please enter the password");
	   document.frm_vendor.password.focus();
	   return false;
	}
	if (!validateEmail(document.frm_vendor.email.value,1,1)) 
	{
		document.frm_vendor.email.focus();
		return false;
	}
}
//user vaLIDATIONS
function user_validate()
{
		if(document.frm_user.first.value == "")
		{
		   alert("Please enter the firstname");
		   document.frm_user.first.focus();
		   return false;
		}
		if(document.frm_user.last.value == "")
		{
		   alert("Please enter the lastname");
		   document.frm_user.last.focus();
		   return false;
		}
		if(document.frm_user.address.value == "")
		{
		   alert("Please Enter the address");
		   document.frm_user.address.focus();
		   return false;
		}
		if(document.frm_user.city.value == "")
		{
		   alert("Please enter the city name");
		   document.frm_user.city.focus();
		   return false;
		}
		if(document.frm_user.state.value == "")
		{
		   alert("Please enter the state name");
		   document.frm_user.state.focus();
		   return false;
		}
		if(document.frm_user.Zip.value == "")
		{
		   alert("Please enter the Zipcode");
		   document.frm_user.Zip.focus();
		   return false;
		}
		if(document.frm_user.country.value == "")
		{
		   alert("Please enter the country");
		   document.frm_user.country.focus();
		   return false;
		}
		if(document.frm_user.username.value == "")
		{
		   alert("Please enter the username");
		   document.frm_user.username.focus();
		   return false;
		}
	if(document.frm_user.password.value == "")
		{
		   alert("Please enter the password");
		   document.frm_user.password.focus();
		   return false;
		}
		if (!validateEmail(document.frm_user.email.value,1,1)) 
		{
			document.frm_user.email.focus();
			return false;
		}
}
//newsadd validations 
function news_validateadd()
{
		if(document.frm_news.heading.value == "")
		{
		   alert("Please enter the heading");
		   document.frm_news.heading.focus();
		   return false;
		}
		if(document.frm_news.txt_short.value == "")
		{
		   alert("Please enter the short description");
		   document.frm_news.txt_short.focus();
		   return false;
		}
}
//Fozsadd validations 
function foz_validateadd()
{
		if(document.frm_foz.heading.value == "")
		{
		   alert("Please enter the heading");
		   document.frm_foz.heading.focus();
		   return false;
		}
		/*if(document.frm_foz.txtdesc.value == "")
		{
		   alert("Please enter the  description");
		   document.frm_foz.txtdesc.focus();
		   return false;
		}*/
}
//newsadd validations 
/*function magazine_validateadd()
{
	
		if(document.frm_news.txtdesc.value == "")
		{
		   alert("Please enter the  description");
		   document.frm_news.txtdesc.focus();
		   return false;
		}
		return true;
}*/

//Poll Validation
function pollvalidate() {
	var varSubject=document.PostNewPoll.varSubject.value;
	if (varSubject=="" )
	{ 
		alert ("Please enter the Subject");
		document.PostNewPoll.varSubject.focus();
		return false;
	}	
	var varQst=document.PostNewPoll.varQst.value;
	if (varQst=="" )
	{ 
		alert ("Please enter the Poll Question");
		document.PostNewPoll.varQst.focus();
		return false;
	}	
	var varFromDate=document.PostNewPoll.varFromDate.value;
	if (varFromDate=="" )
	{ 
		alert ("Please enter the From Date");
		document.PostNewPoll.varFromDate.focus();
		return false;
	}	
	currentdate= new Date();
	curmonth = currentdate.getMonth() + 1;
	var curdate =  curmonth + "/" + currentdate.getDate() + "/" + currentdate.getFullYear();		
	if (!date_valid(curdate,varFromDate)) 
	{
			alert ("From date can't be less than today");
			//document.PostNewPoll.varFromDate.value == "";
			document.PostNewPoll.varFromDate.focus();
			return false;
	}

	var varToDate=document.PostNewPoll.varToDate.value;
	if (varToDate=="" )
	{ 
		alert ("Please enter the To Date");
		document.PostNewPoll.varToDate.focus();
		return false;
	}
	/*toDate = new Date(varToDate);
	if(!(fromDate.getYear()<=toDate.getYear() && fromDate.getMonth()<=toDate.getMonth() && fromDate.getDate()<=toDate.getDate()))
	{
		alert("To date can't be less than from date");
		return false;
	}*/
		if(document.PostNewPoll.varFromDate.value != "" && document.PostNewPoll.varToDate.value!="")
		if (!date_valid(document.PostNewPoll.varFromDate.value,document.PostNewPoll.varToDate.value)) 
			{
					alert ("Please choose the  To date is greater than From date");
					document.PostNewPoll.varToDate.value == "";
					document.PostNewPoll.varToDate.focus();
					return false;
			}

	return true;
}

function state_display(box) {
var us_state_value_list = new Array();
var us_state_text_list = new Array();
var in_state_value_list = new Array();
var in_state_text_list = new Array();
var check_state = document.frm_coupon.bstate;
var check_length = document.frm_coupon.bstate.length;
	if(box.options[box.selectedIndex].value != "" && box.options[box.selectedIndex].value != "")
	{
		emptyList(box.form.bstate);
	}

if (document.frm_coupon.country.value == "Canada"){
	 	 in_state_value_list.push('ON','QC','NS','NB','MB','BC','PE','SK','AB','NL');
		   in_state_text_list.push('ON','QC','NS','NB','MB','BC','PE','SK','AB','NL');
	  	 /* in_state_value_list.push('Ontario','Quebec','Nova Scotia','New Brunswick','Manitoba','British Columbia','Prince Edward Island','Saskatchewan','Alberta','Newfoundland');
		   in_state_text_list.push('Ontario','Quebec','Nova Scotia','New Brunswick','Manitoba','British Columbia','Prince Edward Island','Saskatchewan','Alberta','Newfoundland');*/
		   
		   var i;

		   for (i=0; i<in_state_value_list.length; i++)
		   {
			  var opt = document.createElement('OPTION');
			  opt.value = in_state_value_list[i];
				   opt.text = in_state_text_list[i];
			  var instateList = document.frm_coupon.bstate;
			  if(opt.value != "" && opt.text != "")
			  {
			  	instateList[i+1] = opt;
			  }
		   }		 	 
		}
		 else{
		   us_state_value_list.push('Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','Washington D.C.','West Virginia','Wisconsin','Wyoming');
		   us_state_text_list.push('Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','Washington D.C.','West Virginia','Wisconsin','Wyoming');
       var j;
       var opt = document.createElement('OPTION');
	   opt.value="";
	   opt.text="";
       for (j=0; j<us_state_value_list.length; j++)
       {
          var opt = document.createElement('OPTION');
          opt.value = us_state_value_list[j];
          opt.text = us_state_text_list[j];
          var usstateList = document.frm_coupon.bstate;
          usstateList[j+1] = opt;
       }		 	 			 
 	  } 
}

//-->
function emptyList( box ) 
{
	while ( box.options.length ) box.options[0] = null;
}

function fillList( box, arr ) 
{
	for ( i = 0; i < arr[0].length; i++ ) 
	{
		option = new Option( arr[0][i], arr[0][i+1] );
		box.options[box.length] = option;
		i=i+1;
	}
	box.selectedIndex=0;
}

function changeList(box) 
{
	//alert(lists[box.options[box.selectedIndex].value]);
	list = lists[box.options[box.selectedIndex].value];
	if(box.options[box.selectedIndex].value != "select" && box.options[box.selectedIndex].value != "choose")
	{
		emptyList(box.form.cityname);
		fillList( box.form.cityname, list );
	}
}

///Vendor State & country

function vendorstate_display(box) {
var us_state_value_list = new Array();
var us_state_text_list = new Array();
var in_state_value_list = new Array();
var in_state_text_list = new Array();
var check_state = document.frm_vendor.state;
var check_length = document.frm_vendor.state.length;
	if(box.options[box.selectedIndex].value != "" && box.options[box.selectedIndex].value != "")
	{
		emptyList(box.form.state);
	}

if (document.frm_vendor.country.value == "Canada"){
	 	 in_state_value_list.push('ON','QC','NS','NB','MB','BC','PE','SK','AB','NL');
		   in_state_text_list.push('ON','QC','NS','NB','MB','BC','PE','SK','AB','NL');
	  	 /* in_state_value_list.push('Ontario','Quebec','Nova Scotia','New Brunswick','Manitoba','British Columbia','Prince Edward Island','Saskatchewan','Alberta','Newfoundland');
		   in_state_text_list.push('Ontario','Quebec','Nova Scotia','New Brunswick','Manitoba','British Columbia','Prince Edward Island','Saskatchewan','Alberta','Newfoundland');*/
		   
		   var i;

		   for (i=0; i<in_state_value_list.length; i++)
		   {
			  var opt = document.createElement('OPTION');
			  opt.value = in_state_value_list[i];
				   opt.text = in_state_text_list[i];
			  var instateList = document.frm_vendor.state;
			  if(opt.value != "" && opt.text != "")
			  {
			  	instateList[i+1] = opt;
			  }
		   }		 	 
		}
		 else{
		   us_state_value_list.push('AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','PR','RI','SC','SD','TN','TX','UT','VT','VA','WA','DC','WV','WI','WY');
		   us_state_text_list.push('Alabama','Alaska','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Ohio','Oklahoma','Oregon','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virginia','Washington','Washington D.C.','West Virginia','Wisconsin','Wyoming');
       var j;
       var opt = document.createElement('OPTION');
	   opt.value="";
	   opt.text="";
       for (j=0; j<us_state_value_list.length; j++)
       {
          var opt = document.createElement('OPTION');
          opt.value = us_state_value_list[j];
          opt.text = us_state_text_list[j];
          var usstateList = document.frm_vendor.state;
          usstateList[j+1] = opt;
       }		 	 			 
 	  } 
}
function emailcheck(emailvalue)
{
	var flagcheck;

	if ((emailvalue.length > 0 && (emailvalue.indexOf("@",0) == - 1 || emailvalue.indexOf(".",0) == - 1)))  
	{
		flagcheck=true;
	}
	emailval=emailvalue
	apos=emailval.indexOf("@");
	dotpos=emailval.lastIndexOf(".");
	lastpos=emailval.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
	{
		flagcheck=true;
	}
	return flagcheck;
	
}
