//Script validation for displaying the City list in the given state
var statecities=new Array();

function changeCities(box) 
{
	list = statecities[box.options[box.selectedIndex].value];
	if(box.options[box.selectedIndex].value != "" && box.options[box.selectedIndex].value != "choose")
	{
		emptyList(box.form.txt_city);
		fillList( box.form.txt_city, list );
	}
}

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 confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}


function warrior_login(){
	if(document.frm_warrior.txtUsername.value == "")
	{
		alert("Enter the username");
		document.frm_warrior.txtUsername.focus();
		return false;
	}
	if(document.frm_warrior.txtPassword.value == "")
	{
		alert("Enter the password");
		document.frm_warrior.txtPassword.focus();
		return false;
	}
}

function leadership_login(){
	if(document.frm_leadership.txtUsername.value == "")
	{
		alert("Enter the username");
		document.frm_leadership.txtUsername.focus();
		return false;
	}
	if(document.frm_leadership.txtPassword.value == "")
	{
		alert("Enter the password");
		document.frm_leadership.txtPassword.focus();
		return false;
	}
}

function contact_validate(){
	if(document.contact.txtName.value == "")
	{
		alert("Enter the name");
		document.contact.txtName.focus();
		return false;
	}
	if(document.contact.txtTitle.value == "")
	{
		alert("Enter the title");
		document.contact.txtTitle.focus();
		return false;
	}
	if(!validateEmail(document.contact.txtEmail.value,1,1))
	{
		document.contact.txtEmail.focus();
		return false;
	}
	if(document.contact.txtAddress1.value == "")
	{
		alert("Enter the Address line1");
		document.contact.txtAddress1.focus();
		return false;
	}
}

function showState(passcountry){
		if (document.getElementById(passcountry).value == "US"){
			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";
			}
		}
	}

function showState1(passcountry1){
		if (document.getElementById(passcountry1).value == "US"){
			postate = document.getElementById("poststate1");
			if(postate){
				postate.style.display="block";
				postate.style.visibility="visible";
			}
			pootherstate = document.getElementById("postotherstate1");
			if(pootherstate){
				pootherstate.style.display="none";
				pootherstate.style.visibility="hidden";
			}
		}
		else{
			pootherstate = document.getElementById("postotherstate1");
			if(pootherstate){
				pootherstate.style.display="block";
				pootherstate.style.visibility="visible";
			}
			postate = document.getElementById("poststate1");
			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;
}

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
} 

//Prayer Warrior Validate
function warrior_validate(){
	if(document.form1.txt_first.value == "")
	{
		alert("Enter the first name");
		document.form1.txt_first.focus();
		return false;
	}
	if(document.form1.txt_last.value == "")
	{
		alert("Enter the last name");
		document.form1.txt_last.focus();
		return false;
	}
	if(!validateEmail(document.form1.txt_email.value,1,1))
	{
		document.form1.txt_email.focus();
		return false;
	}
	/*if(document.form1.txt_addr1.value == "")
	{
		alert("Enter the address1");
		document.form1.txt_addr1.focus();
		return false;
	}
	if(document.form1.txt_city.value == "")
	{
		alert("Please enter the city");
		document.form1.txt_city.focus();
		return false;
	}

	if(document.form1.Country.value == "")
	{
		alert("Please select the country");
		document.form1.Country.focus();
		return false;
	}
	if(document.form1.Country.value == "US" && document.form1.State.value == "")
	{
		alert("Please Choose the state");
		document.form1.State.focus();
		return false;
	}
	if(document.form1.Country.value != "US" && document.form1.State1.value == "")
	{
		alert("Please enter the State");
		document.form1.State1.focus();
		return false;
	}
	if(document.form1.txt_zip.value == "")
	{
		alert("Enter the zipcode");
		document.form1.txt_zip.focus();
		return false;
	}*/
	/*if(isNaN(document.form1.txt_zip.value))
	{
		alert("Enter the zipcode in numeric value");
		document.form1.txt_zip.focus();
		return false;
	}
	if(document.form1.txt_church.value == "")
	{
		alert("Enter the churh name");
		document.form1.txt_church.focus();
		return false;
	}
	if(document.form1.txt_pastor.value == "")
	{
		alert("Enter the pastor name");
		document.form1.txt_pastor.focus();
		return false;
	}*/
	if(document.form1.txt_prayhome.value == "")
	{
		alert("Enter the prayer home name");
		document.form1.txt_prayhome.focus();
		return false;
	}
	if(document.form1.txt_prayaddr.value == "")
	{
		alert("Enter the prayer home address");
		document.form1.txt_prayaddr.focus();
		return false;
	}
	if(document.form1.txt_praycity.value == "")
	{
		alert("Enter the city");
		document.form1.txt_praycity.focus();
		return false;
	}

	if(document.form1.Country1.value == "")
	{
		alert("Choose the country");
		document.form1.Country1.focus();
		return false;
	}
	if(document.form1.Country1.value == "US" && document.form1.State2.value == "")
	{
		alert("Choose the state");
		document.form1.State2.focus();
		return false;
	}
	if(document.form1.Country1.value != "US" && document.form1.State3.value == "")
	{
		alert("Enter the state");
		document.form1.State3.focus();
		return false;
	}
	if(document.form1.txt_prayzip.value == "")
	{
		alert("Enter the zipcode");
		document.form1.txt_prayzip.focus();
		return false;
	}
	/*if(isNaN(document.form1.txt_prayzip.value))
	{
		alert("Enter the zipcode in numeric value");
		document.form1.txt_prayzip.focus();
		return false;
	}*/
	
	if((document.form1.txt_username.value == "") || (document.form1.txt_username.value.length < 6))
	{
		//alert(document.form1.txt_username.value.length);
		alert("Enter the username with the minimum of 6 characters");
		document.form1.txt_username.focus();
		return false;
	}
	if((document.form1.txt_password.value == "") || (document.form1.txt_password.value.length < 6))
	{
		//alert(document.form1.txt_password.value.length);
		alert("Enter the password with the minimum of 6 characters");
		document.form1.txt_password.focus();
		return false;
	}
}

function churchmember_validate(){
	if(document.frm_member.txt_first.value == "")
	{
		alert("Enter the first name");
		document.frm_member.txt_first.focus();
		return false;
	}
	if(document.frm_member.txt_last.value == "")
	{
		alert("Enter the last name");
		document.frm_member.txt_last.focus();
		return false;
	}
	if(document.frm_member.txt_addr1.value == "")
	{
		alert("Enter the addres line1");
		document.frm_member.txt_addr1.focus();
		return false;
	}
	if(document.frm_member.txt_city.value == "")
	{
		alert("Enter the city");
		document.frm_member.txt_city.focus();
		return false;
	}
	if(document.frm_member.State.value == ""){
			alert("Choose the state");
			document.frm_member.State.focus();
			return false;
	}
	if(document.frm_member.txt_zip.value == "")
	{
		alert("Enter the zipcode");
		document.frm_member.txt_zip.focus();
		return false;
	}

	if (!validateEmail(document.frm_member.txt_email.value,1,1)) 
	{
		 document.frm_member.txt_email.focus();
		 return false;
	}
	if((document.frm_member.txt_username.value == "") || (document.frm_member.txt_username.value.length < 6))
	{
		alert("Enter the user name with the minimum of 6 characters");
		document.frm_member.txt_username.focus();
		return false;
	}
	if((document.frm_member.txt_password.value == "") || (document.frm_member.txt_username.value.length < 6))
	{
		alert("Enter the password with the minimum of 6 characters");
		document.frm_member.txt_password.focus();
		return false;
	}
}


function member_validate(){
	if(document.frm_memregister.txt_church.value == "")
	{
		alert("Choose the church name");
		document.frm_memregister.txt_church.focus();
		return false;
	}
	if(document.frm_memregister.txt_first.value == "")
	{
		alert("Enter the first name");
		document.frm_memregister.txt_first.focus();
		return false;
	}
	if(document.frm_memregister.txt_last.value == "")
	{
		alert("Enter the last name");
		document.frm_memregister.txt_last.focus();
		return false;
	}
	if(document.frm_memregister.txt_addr1.value == "")
	{
		alert("Enter the addres line1");
		document.frm_memregister.txt_addr1.focus();
		return false;
	}
	if(document.frm_memregister.txt_city.value == "")
	{
		alert("Enter the city");
		document.frm_memregister.txt_city.focus();
		return false;
	}
	if(document.frm_memregister.State.value == ""){
			alert("Choose the state");
			document.frm_memregister.State.focus();
			return false;
	}
	if(document.frm_memregister.txt_zip.value == "")
	{
		alert("Enter the zipcode");
		document.frm_memregister.txt_zip.focus();
		return false;
	}

	if (!validateEmail(document.frm_memregister.txt_email.value,1,1)) 
	{
		 document.frm_memregister.txt_email.focus();
		 return false;
	}
	if((document.frm_memregister.txt_username.value == "") || (document.frm_memregister.txt_username.value.length < 6))
	{
		alert("Enter the user name with the minimum of 6 characters");
		document.frm_memregister.txt_username.focus();
		return false;
	}
	if((document.frm_memregister.txt_password.value == "") || (document.frm_memregister.txt_username.value.length < 6))
	{
		alert("Enter the password with the minimum of 6 characters");
		document.frm_memregister.txt_password.focus();
		return false;
	}
}
	
	
function showinfo(){
		if (document.frm_prayerrequest.rdo_request[1].checked){
		ap1=document.getElementById("showattrib");
		    if(ap1){
				ap1.style.display="block";
				ap1.style.visibility="visible";
			}				
		}
		else
		{
			ap1=document.getElementById("showattrib");
			if(ap1){
				ap1.style.display="none";
				ap1.style.visibility="hidden";
			}
		}
}
// Validation For Member Post Prayer request
function postrequest_validate(){
	if(document.frm_prayerrequest.txt_subject.value==""){
		alert("Please enter the Subject");
		document.frm_prayerrequest.txt_subject.focus();
		return false;
	}
	rdo_request="";
	var i=0;
	rdo_requestlength=document.frm_prayerrequest.rdo_request.length;
	if(rdo_requestlength > 1){
		for(Index = 0;Index < rdo_requestlength;Index++){
			if(document.frm_prayerrequest.rdo_request[Index].checked==false){
				i=i+1;
			}
			else{
				rdo_request = document.frm_prayerrequest.rdo_request[Index].value;
			}
		}
	}
	if(i==rdo_requestlength){
		alert("Please select you are Anonymous are not");
		return false;
	}
	if(document.frm_prayerrequest.rdo_request[1].checked==true){
		if(document.frm_prayerrequest.email.value==""){
			alert("Please Enter your Email Id");
			document.frm_prayerrequest.email.focus();
			return false;
		}
		if (!validateEmail(document.frm_prayerrequest.email.value,1,1)) 
		{
			 document.frm_prayerrequest.email.focus();
			 return false;
		}
		if(document.frm_prayerrequest.callinfo.value==""){
			alert("Please enter your Phone Number");
			document.frm_prayerrequest.callinfo.focus();
			return false;
		}
		phone = document.frm_prayerrequest.callinfo;
		if(checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
		}
	}
}
///leadership-updprayerhomes
function prayerhome_validate(){
	if(document.frm_leaderprayerhome.txt_prayhome.value==""){
		alert("Please enter the Home Name");
		document.frm_leaderprayerhome.txt_prayhome.focus();
		return false;
	}
	if(document.frm_leaderprayerhome.txt_prayaddr.value==""){
		alert("Please enter the Home Address");
		document.frm_leaderprayerhome.txt_prayaddr.focus();
		return false;
	}
	if(document.frm_leaderprayerhome.txt_praycity.value==""){
		alert("Please enter the City");
		document.frm_leaderprayerhome.txt_praycity.focus();
		return false;
	}
	if(document.frm_leaderprayerhome.txt_praystate.value==""){
		alert("Please select the State");
		document.frm_leaderprayerhome.txt_praystate.focus();
		return false;
	}
	if(document.frm_leaderprayerhome.txt_prayzip.value==""){
		alert("Please enter the Zipcode");
		document.frm_leaderprayerhome.txt_prayzip.focus();
		return false;
	}
}

//Validation for Events
function addevent_validate(){
	if(document.frm_addevent.heading.value == ""){
		alert("Please enter the Heading");
		document.frm_addevent.heading.focus();
		return false;
	}
	if(document.frm_addevent.eventdate.value == ""){
		alert("Please select the date from Date Picker");
		document.frm_addevent.eventdate.focus();
		return false;
	}
}
		
function upload_validate(){
	if(document.frm_AlbumPictures.hiddenlogo.value == ""){
		if(document.frm_AlbumPictures.filename.value == ""){
		alert("Please Upload the Image");
		document.frm_AlbumPictures.filename.focus();
		return false;
		}
	}
	if(document.frm_AlbumPictures.txtCaption.value == ""){
		alert("Please Enter the Caption");
		document.frm_AlbumPictures.txtCaption.focus();
		return false;
	}
	return true;
}
