// FUNCTION USED FOR VALIDATING ALL KINDS OF FORM UPDATED ON AUG 10TH BY SHERMILIN
function Validate(frm)
	{
if (document.postevent.EventName.value == '')
{
window.alert('Please enter event name');
document.postevent.EventName.focus () ;
return false;
}

if (document.postevent.EventOrganizer.value == '')
{
window.alert('Please enter  Event Organizer');
document.postevent.EventOrganizer.focus () ;
return false;
}

if (document.postevent.EmailAddress.value == '')
{
window.alert('Please enter your  email address');
document.postevent.EmailAddress.focus ();
return false;
}
	
var str=document.postevent.EmailAddress.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (!filter.test(str))
{
window.alert("Please enter your valid email address!");
 
return false;
}
if (document.postevent.ShortDesc.value == '')
{
window.alert('Please enter  Short Description');
document.postevent.ShortDesc.focus () ;
return false;
}
if (document.postevent.LongDesc.value == '')
{
window.alert('Please enter Long Description');
document.postevent.LongDesc.focus () ;
return false;
}

if(!document.postevent.EventImage.value == '' )
	{
		var fname = document.postevent.EventImage.value.toUpperCase();
		var pos1 = fname.indexOf(".JPG");
		var pos2 = fname.indexOf(".JPEG");
		var pos3 = fname.indexOf(".GIF");
		var pos4 = fname.indexOf(".PNG");
		
		if(pos1==-1 && pos2==-1 && pos3==-1 && pos4==-1)
		{
			window.alert('Invalid Image Type\nPlease use JPEG  or GIF or PNG');
			document.postevent.EventImage.focus();
			return false;	
		}
	}

if(!ValidateNo(document.postevent.Zip.value,"1234567890+- ")) 
    { 
        alert("Please enter proper zip code"); 
        document.postevent.Zip.focus(); 
        return false; 
    }



	if(document.postevent.StartMonth.value=='' || document.postevent.StartDay.value=='' || document.postevent.StartYear.value=='')
	{
		alert("Please select Start Date");
		return false;
	}
	/*if(document.postevent.EndMonth.value=='' || document.postevent.EndDay.value=='' || document.postevent.EndYear.value=='')
	{
		alert("Please select End Date");
		return false;
	}*/
	
	
	if(document.postevent.StartMonth.value!='' && document.postevent.StartDay.value!='' && document.postevent.StartYear.value!='' && document.postevent.EndMonth.value!='' && document.postevent.EndDay.value!='' && document.postevent.EndYear.value!='')
	{
		stdate = new Date(document.postevent.StartYear.value, document.postevent.StartMonth.value, document.postevent.StartDay.value)  
		enddate = new Date(document.postevent.EndYear.value, document.postevent.EndMonth.value, document.postevent.EndDay.value)  
		if(stdate > enddate)
		{
			alert("start date must be less than the end date.");
			return false;
		}
	
	}
if (!document.postevent.PaymentLink.value == '')
{
var theurl=document.postevent.PaymentLink.value;
var tomatch= /http|https:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/   
//var tomatch1= /https:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

 if (!tomatch.test(theurl))  
  {
 alert("URL invalid. Try again.");
 return false; 
 }
else
{
return true;
}

}

	}

function checkSelect(item) 
{
	bLocValid = true;
	if(item.selectedIndex==0)
	{
		bLocValid=false;
	}
	if (item.selectedIndex < 0) 
	{ 
		bLocValid = false;
	}
	if (item.selectedIndex == 0) 
	{
		if (item.options[0].value == '') 
		{ 
			bLocValid = false;
		}
	}
	return bLocValid;
}

//FUNCTION FOR CHECKING NUMMERIC VALUES
function numOnly()
{
	if(window.event.keyCode != 13 && window.event.keyCode<45 || window.event.keyCode>57 || window.event.keyCode == "47" || window.event.keyCode == "46")
	{
		window.event.keyCode=null;
		alert("Please Enter Numeric Values Only");
	}
}

function numdecimalOnly()
{
	if(window.event.keyCode != 13 && window.event.keyCode<45 || window.event.keyCode>57 || window.event.keyCode == "47")
	{
		window.event.keyCode=null;
		alert("Please Enter Numeric Values Only");
	}
}


//FUNCTION FOR CHECKING PASSWORD AND CONFIRM PASSWORD
function validepassword(frm)
{
	var Password=document[frm].elements["Password"].value;
	var ConfirmPass=document[frm].elements["Confirm_pass"].value;

	if (Password!=ConfirmPass)
	{
		alert('Please Confirm Your Password Correctly');
		document[frm].elements["Confirm_pass"].focus();
		
		return false;
	}
	else
	{
		return true;
	}
}

//FUNCTION FOR CHECKING WHETHER THE IMAGES UPLOADED ARE VALID OR NOT
function CheckValidImage(frm,name)
{
	var image=document[frm].elements[name].value;
	var imagelength=document[frm].elements[name].value.length;
	var imageindex=image.lastIndexOf(".") + 1;
	var last=image.substring(imageindex,imagelength);
	if(document[frm].elements[name].value != "")
	{
		if(last != "jpg" && last != "gif" && last != "jpeg" && last != "png" && last != "JPG" && last != "GIF" && last != "JPEG" && last != "PNG")
		{
			alert("Please Upload valid jpg or gif or png file");
			return flag=1;
		}
		else
		{
			return flag=0;
		}
	}
}

//TEXT AREA VALIDATION FUNCTION FOR LIMITED CHARACTER*******************************
function validatetextarea1(frm,FieldName) 
{
	var arealength = document[frm].elements[FieldName].value.length + 1;
	document[frm].ctText.value=arealength;
	if (arealength > 500)
	{
		  alert('Your property description must be 500 characters or less');
		  document[frm].elements[FieldName].focus();
	}
}

function CheckSignUp()
{
   var regEmail = /^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
   if(document.signUpForm.FirstName.value.search(/\S/)==-1)
   {
   alert ("First Name cannot be blank");
   document.signUpForm.FirstName.focus();
   return false;
   }
   if(document.signUpForm.LastName.value.search(/\S/)==-1)
   {
   alert ("Last Name cannot be blank");
   document.signUpForm.LastName.focus();
   return false;
   }
   if(document.signUpForm.EmailAddress.value.search(/\S/)==-1)
   {
   alert ("EmailAddress cannot be blank");
   document.signUpForm.EmailAddress.focus();
   return false;
   }
   if(document.signUpForm.EmailAddress.value!='')
   {
        if(!regEmail.test(document.signUpForm.EmailAddress.value))
		{
			alert("Invalid Email Address");
			document.signUpForm.EmailAddress.focus();
			return false;
		}
   }
   if(document.signUpForm.Phone.value.search(/\S/)==-1)
   {
   alert ("Phone cannot be blank");
   document.signUpForm.Phone.focus();
   return false;
   }
   /*if(document.signUpForm.MessageBody.value.search(/\S/)==-1)
   {
   alert ("Message cannot be blank");
   document.signUpForm.MessageBody.focus();
   return false;
   }*/
  return true;
}
function CharacterOnly(frm,FieldName)
{
	var numeric;
	numeric=FieldName.value;
	for(var j=0; j<numeric.length; j++)
	{
		var alphaa = numeric.charAt(j);
		var hh = alphaa.charCodeAt(0);
	
		if((hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==32)
		{
		}
		else
		{
			
			alert("Please Enter Alphabets Only");
			FieldName.value="";
			FieldName.focus();
			return false;
		}
	}
	
	return true;
}

function keycode()
{
	if(window.event.keyCode == "13")
	{
		searchbyarealoc();
	}
}

function atag() {
  return "<a href='javascript:showCal(\'Calendar3\')'><img src=\'images/calbtn.gif\' border=0 align=absmiddle></img></a>";
}
function disable(val)
{
	if(val == 1)
	{
		document.postevent.RecEventdate1.disabled = true;
		document.postevent.RecEventdate1.value = "";
		document.all.id6.style.display = 'none';
	}
	else
	{
		document.postevent.RecEventdate1.disabled = false;
		document.postevent.RecEventdate1.id = 'req_txt_Recurring End Date';	
		document.all.id6.style.display = '';
	}
}

function disable1(val)
{
	if(val == 1)
	{
		document.postevent.RecEventdate2.disabled = true;
		document.postevent.RecEventdate2.value = "";
		document.all.id7.style.display = 'none';
	}
	else
	{
		document.postevent.RecEventdate2.disabled = false;
		document.postevent.RecEventdate2.id = 'req_txt_Recurring End Date';	
		document.all.id7.style.display = '';
	}

}
function disable2(val)
{
	if(val == 1)
	{
		document.postevent.RecEventdate3.disabled = true;
		document.postevent.RecEventdate3.value = "";
		document.all.id8.style.display = 'none';
	}
	else
	{
		document.postevent.RecEventdate3.disabled = false;
		document.postevent.RecEventdate3.id = 'req_txt_Recurring End Date';	
		document.all.id8.style.display = '';
	}

}

function disabletime(val)
{
	if(val != "")
	{
		document.forms[0].TimeZonevalue.disabled = true;
		document.forms[0].TimeZonevalue.value = "";
	}
	else
	{
		document.forms[0].TimeZonevalue.disabled = false;
		document.forms[0].TimeZonevalue.id = 'req_txt_Time Zone';
		document.forms[0].TimeZone.id = "";

	}
}

function selectAll(list)
{
	if(document.formlist.hidSelect.value==0)
	{
		for (var i=0;i<list.length;i++)
		{
			document.getElementById(list[i]).checked = true
		}
		document.formlist.hidSelect.value=1;
	}
	else
	{
		for (var i=0;i<list.length;i++)
		{
			document.getElementById(list[i]).checked = false
		}
		document.formlist.hidSelect.value=0;
	}
}

function checkDelete()
{
	var chk=false;
	for (var i=0;i<(document.formlist.elements.length);i++)
	{
		if (document.formlist.elements[i].checked == true)
		{
			chk=true;
			if(confirm("Are you wan to delete the marked signups?"))
			{
			 document.formlist.action="modifyEvent.php?act=deletesign";
			 document.formlist.submit();
			}
			break;
		}
	}
	if (chk==false)
	{
		alert ("Please select users.");
		return false;
	}

}
function checkDeleteEvent(type)
{
	var chk=false;
	for (var i=0;i<(document.formlist.elements.length);i++)
	{
		if (document.formlist.elements[i].checked == true)
		{
			chk=true;
			if(confirm("Are you sure you want to delete marked Events"))
			{
				if(type == 'event')
					{
						 document.formlist.action="modifyEvent.php?act=delete";
					}
				else
					{
						document.formlist.action="modifyEvent.php?act=deleteprivateevent";
					 
					}		 
						 document.formlist.submit();
			}
			break;
		}
	}
	if (chk==false)
	{
		alert ("You must first select Events!");
		return false;
	}

}
function signupPrint()
{
 	var chk=false;
	for (var i=0;i<(document.formlist.elements.length);i++)
	{
		if (document.formlist.elements[i].name.substr(0,6)=='Delete' && document.formlist.elements[i].checked == true)
		{
			chk=true;			
			 document.formlist.action="signup_print.php";
			 document.formlist.target="_blank";
			 document.formlist.submit();			
			break;
		}
	}
	if (chk==false)
	{
		alert ("Please select users.");
		return false;
	}	
			
}
function signupPrintConnections(){ // Abdul Manashi
document.formlist.action="signup_print_connections.php";
 document.formlist.target="_blank";
 document.formlist.submit();
}
function signupConnectionsPdf(){ // Abdul Manashi
document.formlist.action="signup_pdf_connections.php";
 document.formlist.target="_blank";
 document.formlist.submit();
}

function changeTarget1(ID){
    var chk=false;
	for (var i=0;i<(document.formlist.elements.length);i++)
	{
	   if (document.formlist.elements[i].name.substr(0,6)=='Delete' && document.formlist.elements[i].checked == true)
	   {
	    chk=true;		
		document.formlist.action = "pdf/signuplist_pdf.php?event_id="+ID;		
		document.formlist.target="_blank";
		document.formlist.submit();		
		break;
	   }
	}
	if (chk==false)
	{
		alert ("Please select users.");
		return false;
	}	
}
function checkmail(id,file)
{
	var chk=false;
	for (var i=0;i<(document.formlist.elements.length);i++)
	{
		if (document.formlist.elements[i].checked == true)
		{
			chk=true;
			//if(confirm("Send mail to all?"))
			//{
				if(file == 'all')
				{
					document.formlist.action = "modifyEvent.php?act=sendall&file=all&id="+id;
				}
				else
				{
					document.formlist.action = "modifyEvent.php?act=sendall&id="+id;
				}
				document.formlist.submit();
			//}
			//break;
		}
	}
	if (chk==false)
	{
		alert ("Please select users you would like to email.");
		return false;
	}

}

function ValidateNo(NumStr, String) 
{ 
    for(var Idx=0; Idx<NumStr.length; Idx++) 
    { 
        var Char = NumStr.charAt(Idx); 
        var Match = false; 

        for(var Idx1=0; Idx1<String.length; Idx1++) 
        { 
            if(Char == String.charAt (Idx1)) 
                Match = true; 
        } 

        if (!Match) 
            return false; 
    } 
	return true;
} 
function checkStartDate()
{
	if(document.postevent.StartMonth.value=='' || document.postevent.StartDay.value=='' || document.postevent.StartYear.value=='')
	{
		alert("Please select Start Date");
		return false;
	}
	
}

function show(val)
{
	if(val == 'Week')
	{
		document.all.id1.style.display = '';
		document.all.id2.style.display = 'none';
		document.all.id3.style.display = 'none';
		document.all.id6.style.display = 'none';
		document.postevent.RepWeek.id = 'req_txt_NO of Weeks';
		document.postevent.RepWeek_days.id = 'req_txt_Recurring day';
	}
	else if(val == 'Month')
	{
		document.all.id2.style.display = '';
		document.all.id1.style.display = 'none';
		document.all.id3.style.display = 'none';
		document.all.id7.style.display = 'none';
		document.postevent.RepMonth.id = 'req_txt_NO of Months';
		document.postevent.repeatflag.id = 'req_txt_Recurring by';
	}
	else if(val == 'Year')
	{
		document.all.id3.style.display = '';
		document.all.id1.style.display = 'none';
		document.all.id2.style.display = 'none';
		document.all.id8.style.display = 'none';
		document.postevent.RepYear.id = 'req_txt_NO of Years';
		
	}
	else
	{
		document.all.id3.style.display = 'none';
		document.all.id1.style.display = 'none';
		document.all.id2.style.display = 'none';
		document.all.id6.style.display = 'none';
		document.all.id7.style.display = 'none';
		document.all.id8.style.display = 'none';
		document.postevent.RepWeek.id = '';
		document.postevent.RepWeek_days.id = '';
		document.postevent.RepMonth.id = '';
		document.postevent.repeatflag.id = '';
		document.postevent.RepYear.id = '';
	}
	//document.all.id2.style.display = '';
}
function chek(pay,signup)
{
	if(pay == 'Y' && signup == 'Y')
	{
		document.all.id9.style.display = '';
		document.postevent.PaymentLink.id = 'req_txt_Payment Link';
	}
	else
	{
		document.all.id9.style.display = 'none';
	}
	if(pay == 'Y' && signup == 'N')
	{
		alert("You must select 'Yes' in SignUp to make Payment");
		document.postevent.SignUpform.focus();
		return false;
	}
	return true;
}
function cheklink(signup,pay)
{
	if(signup == 'N')
	{   document.all.id9.style.display = 'none';
		document.postevent.PaymentLink.id = '';
		//document.all.event_connections_row.style.display = 'none';
		//document.all.EventConnectionOption.selectedIndex=1; // NO
		document.getElementById('sign_up_options_row').style.display='none';
	}
	else if(pay == 'Y' && signup == 'Y')
	{
		document.all.id9.style.display = '';
		document.postevent.PaymentLink.id = 'req_txt_Payment Link';
		//if(document.all.EventConnectionOption.selectedIndex==0)document.all.event_connections_row.style.display = '';
		document.getElementById('sign_up_options_row').style.display='';
	}
	else if(signup == 'Y')
	{
		//document.all.id9.style.display = '';
		document.postevent.PaymentLink.id = 'req_txt_Payment Link';
		//if(document.all.EventConnectionOption.selectedIndex==0)document.all.event_connections_row.style.display = '';
		document.getElementById('sign_up_options_row').style.display='';
	}
}
function deleteEvent(url)
{
	if(confirm("Are you wan to delete the marked signups?"))
		document.location.href=url;
} 


function disablecat(val)
{
	if(val != "")
	{
		document.postevent.EventCategory.disabled = true;
		document.postevent.EventCategory.id = "";
		document.postevent.EventCategory.value = "";
	}
	else
	{
		document.postevent.EventCategory.disabled = false;
		document.postevent.EventCategory.id = "req_select-one_Event Category";
	}
}
function delImage(img,id)
{
	//alert(img);
	if(confirm("Are you sure to want to delete this Image?"))
		document.location.href="modifyEvent.php?act=del&id="+id;
}

function checkStartDate_champaign()
{
	if(document.frmUpdate.StartMonth.value=='' || document.frmUpdate.StartDay.value=='' || document.frmUpdate.StartYear.value=='')
	{
		alert("Please select Start Date");
		return false;
	}
	
}
function enqValidate()
{
	 if(document.form1.tomail.value.search(/\S/)==-1)
	 {
		 alert("Sending email address cannot be blank");
		 return false;
	 }else if(document.form1.Subject.value.search(/\S/)==-1){
		 alert("Subject cannot be blank");
		 return false;
	 }else if(document.form1.Body.value.search(/\S/)==-1){
		 alert("Message cannot be blank");
		 return false;
	 }else{
		 return true;
	 }
}
