function validateNewsReader()
{
   if(document.getElementById('entergroup').style.display=='block')
       {
    if(document.getElementById("group_name"))
        {
            group_name =document.getElementById("group_name").value;
            if(group_name=='')
                {
                   alert('Please enter the group name');
		document.add_news_reader.group_name.focus();
		return false ;
                }
        }}
    if(document.getElementById("name"))
        {
            emailval =document.getElementById("name").value;
            if(emailval=='')
                {
                   alert('Please enter the Email address');
		document.add_news_reader.name.focus();
		return false ;
                }
        }

        return true;
}
function changegroup(selectedval)
{
    if(selectedval=='new')
        {
            document.getElementById('entergroup').style.display="block";
            document.getElementById('selectcombo').style.display="none";
            document.add_news_reader.group_name.focus();
        }
        else
            {
                  document.getElementById('entergroup').style.display="none";
                  document.getElementById('selectcombo').style.display="block";
            }
}


function ValidateAddArticle(theform)
{
		if(theform.category.value=='' || theform.category.value=='0') {
		alert('Please select a category')
		theform.category.focus()
		return false
	}

		if(theform.section.value=='') {
		alert('Please enter a Section name for this category')
		theform.section.focus()
		return false
	}

		if(theform.template.value=='' || theform.template.value=='0') {
		alert('Please select a template for the article layout')
		theform.template.focus()
		return false
	}

		if(theform.inc_gallery.checked==true) {
			if(theform.gallery_image1.value=='') {
			alert('Please upload an image for your gallery')
			theform.gallery_image1.focus()
			return false
		}
	}

		if(theform.header_select.value=='1') {
			if(theform.folder_select.value=='0' || theform.folder_select.value==''){
			alert('Please select a folder to copy the header images from')
			theform.folder_select.focus()
			return false
		}
	}

		if(theform.header_select.value=='0') {
			if(theform.ssimg1.value==''){
			alert('Please select at least one image for your page header')
			theform.ssimg1.focus()
			return false
		}
	}

	return true
}

function validateAddMember(theform)
{
		if(theform.name.value=='') {
		alert('Please enter a Name')
		theform.name.focus()
		return false
	}

		if(theform.family_name.value=='') {
		alert('Please enter a Family Name')
		theform.family_name.focus()
		return false
	}

		if(theform.username.value=='') {
		alert('Please enter a Username')
		theform.username.focus()
		return false
	}

		if(theform.password.value=='') {
		alert('Please enter a Password')
		theform.password.focus()
		return false
	}

		if(theform.address.value=='') {
		alert('Please enter an Address')
		theform.address.focus()
		return false
	}

		if(theform.house_no.value=='') {
		alert('Please enter a House number')
		theform.house_no.focus()
		return false
	}

		if(theform.zip.value=='') {
		alert('Please enter the Zip code')
		theform.zip.focus()
		return false
	}

		if(theform.city.value=='') {
		alert('Please enter a City')
		theform.city.focus()
		return false
	}

		if(theform.country.value=='') {
		alert('Please enter a Country')
		theform.country.focus()
		return false
	}

		if(theform.gender.value=='' || theform.gender.value=='0') {
		alert('Please select a Gender')
		theform.gender.focus()
		return false
	}

		if(theform.dob.value=='') {
		alert('Please enter a Date of birth')
		theform.dob.focus()
		return false
	}

		if(theform.telephone.value=='') {
		alert('Please enter a Telephone number')
		theform.telephone.focus()
		return false
	}

		if(theform.country_code.value=='') {
		alert('Please enter a Country code')
		theform.country_code.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter an Email address')
		theform.email.focus()
		return false
	}
	return true
}


function validateRegMember(theform)
{
   
		if(theform.name.value=='') {
		alert('Please enter a Name')
		theform.name.focus()
		return false
	}

		if(theform.family_name.value=='') {
		alert('Please enter a Family Name')
		theform.family_name.focus()
		return false
	}

		if(theform.username.value=='') {
		alert('Please enter a Username')
		theform.username.focus()
		return false
	}

		if(theform.user_chk.value=='1') {
		alert('Please use a different Username')
		theform.username.focus()
		return false
	}

		if(theform.password.value=='') {
		alert('Please enter a Password')
		theform.password.focus()
		return false
	}

		if(theform.address.value=='') {
		alert('Please enter an Address')
		theform.address.focus()
		return false
	}

		if(theform.house_no.value=='') {
		alert('Please enter a House number')
		theform.house_no.focus()
		return false
	}

		if(theform.zip.value=='') {
		alert('Please enter the Zip code')
		theform.zip.focus()
		return false
	}

		if(theform.city.value=='') {
		alert('Please enter a City')
		theform.city.focus()
		return false
	}

		if(theform.country.selectedIndex=='0') {
		alert('Please choose a Country')
		theform.country.focus()
		return false
	}

		if(theform.gender.value=='' || theform.gender.value=='0') {
		alert('Please select a Gender')
		theform.gender.focus()
		return false
	}

		if(theform.dob.value=='') {
		alert('Please enter a Date of birth')
		theform.dob.focus()
		return false
	}

		if(theform.telephone.value=='') {
		alert('Please enter a Telephone number')
		theform.telephone.focus()
		return false
	}

		if(theform.country_code.value=='') {
		alert('Please enter a Country code')
		theform.country_code.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter an Email address')
		theform.email.focus()
		return false
	}
 if(theform.user_email.value == 1)
           {
               alert('Email Address already exists. Please provide a new one')
				theform.user_email.focus()
				return false
           }
		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}
        

		if(theform.agree[0].checked==false && theform.agree[1].checked==false) {
		alert('Please specify if you want to give additional contribution')
		theform.agree[0].focus()
		return false
	}

		if(theform.agree[0].checked==true) {
			if(theform.other_term[0].checked==false && theform.other_term[1].checked==false && theform.other_term[2].checked==false) {
				alert('Please select the type of contribution')
				theform.other_term[0].focus()
				return false
			}
			if(theform.extra_contrib.value=='') {
				alert('Please indicate the amount you wish to contribute')
				theform.extra_contrib.focus()
				return false
			}
	}
        
      
	return true;
}

function validateDonate(theform)
{
		if(theform.name.value=='') {
		alert('Please enter a Name')
		theform.name.focus()
		return false
	}

		if(theform.family_name.value=='') {
		alert('Please enter a Family Name')
		theform.family_name.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter an Email address')
		theform.email.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}

		if(theform.other_term[0].checked==false && theform.other_term[1].checked==false && theform.other_term[2].checked==false) {
		alert('Please indicate if your contribution is for once only, monthly or yearly')
		theform.other_term[0].focus()
		return false
	}

	return true
}


function ValidateAddUser(theform)
{
		if(theform.name.value=='') {
		alert('Please enter your First Name')
		theform.name.focus()
		return false
	}

		if(theform.family_name.value=='') {
		alert('Please enter your Family Name')
		theform.family_name.focus()
		return false
	}

		if(theform.username.value=='') {
		alert('Please enter your username')
		theform.username.focus()
		return false
	}

		if(theform.password.value=='') {
		alert('Please enter your password')
		theform.password.focus()
		return false
	}

		if(theform.address.value=='') {
		alert('Please enter your Address')
		theform.address.focus()
		return false
	}

		if(theform.house_no.value=='') {
		alert('Please enter your House No')
		theform.house_no.focus()
		return false
	}

		if(theform.zip.value=='') {
		alert('Please enter your Zip Code')
		theform.zip.focus()
		return false
	}

		if(theform.city.value=='') {
		alert('Please enter your City')
		theform.city.focus()
		return false
	}

		if(theform.country.value=='') {
		alert('Please enter your Country')
		theform.country.focus()
		return false
	}

		if(theform.gender.options[1].selected==false && theform.gender.options[2].selected==false) {
		alert('Please enter your Gender')
		theform.gender.focus()
		return false
	}

		if(theform.dob.value=='') {
		alert('Please enter your Date of Birth')
		theform.dob.focus()
		return false
	}

		if(theform.telephone.value=='') {
		alert('Please enter your Telephone')
		theform.telephone.focus()
		return false
	}

		if(theform.country_code.value=='') {
		alert('Please enter your Country Code')
		theform.country_code.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}

	return true
}

function ValidateAA(theform)
{
		if(theform.category.selectedIndex=='0') {
		alert('Please select a Category')
		theform.category.focus()
		return false
	}

		if(theform.section.value=='') {
		alert('Please enter a Section for the article')
		theform.section.focus()
		return false
	}

		/*if(theform.template.selectedIndex=='0') {
		alert('Please select a Template style to use')
		theform.template.focus()
		return false
	}*/

		if(theform.header_select.selectedIndex=='1') {
			if(theform.folder_select.selectedIndex=='0') {
				alert('Please select a folder to copy header images from')
				theform.folder_select.focus()
				return false
			}
	}

	return true
}


function Validateorder(theform)
{
	var form=document.forms['theform'];
	var length=form.length;
	for (var i=0; i<length; i++)
 	{
    	if (form.elements[i])
    	{
			//Check object here...
			if (form.elements[i].selectedIndex == '0')
			{
			//	form.elements[i].selectedIndex == '1'
			//	var opt = explode('::', form.elements[i].select.value);
			//	var opt_type = opt[0];
			//	var type_val = opt[1];
				alert('You must '+form.elements[i].value);
				form.elements[i].focus()
				return false
			}
    	}
 	}
	return true
}

function ValidateSpread(theform)
{
		if(theform.name.value=='') {
		alert('Please enter your Name')
		theform.name.focus()
		return false
	}

		if(theform.email.value=='') {
		alert('Please enter your Email address')
		theform.email.focus()
		return false
	}

		if(theform.email.value!='') {
			if(emailValidator(theform.email)==false) {
			alert('The Email address is not valid. Please enter a valid Email address')
			theform.email.focus()
			return false
		}
	}

		if(theform.email_to.value=='') {
		alert('Please enter the email address of your friends')
		theform.email_to.focus()
		return false
	}
	return true
}


function emailValidator(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,10}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		return false;
	}
}

function explode( delimiter, string, limit ) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']

    var emptyArray = { 0: '' };

    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }

    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }

    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }

    if ( delimiter === true ) {
        delimiter = '1';
    }

    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}
function chkEmail()
{
    var username = document.getElementById('email').value;
        if(username != '')
            {
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('useremailDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
                    
                        if(ajaxRequest.responseText == 'true')
                            {
                                return 'success';
                            }
                            else
                                {
                                    return false;
                                }


		}
	}
	
	var queryString = "?email=" + username;
	ajaxRequest.open("GET", "chk_email.php" + queryString, true);
	ajaxRequest.send(null);
            }
}