
//Validate search forms for articles and discussions
function validateSearch(form){
	var val = form.keywords.value;
	if (val=="" || val=="Search Discussion Topics" || val=="Enter search phrase" || val=="Search Related Articles"){
		alert("Please enter a key word or phrases to search with");
		return false;
	}
	return true;
}


//Validate newsletter submission
function validateNewsletter(form){
	StrObj = new String(form.email.value); 
  	if (!(StrObj.length >=5 && StrObj.match("@") && StrObj.match("."))){
   		alert("Sorry, this is not a valid email address.");
   		return false;
  	}else{
		//TODO: check channel flags here
  	}
	return true;
}


//Validate a user comment input
function validateComment(form){
	if(form.entry.value.indexOf("http://")>=0){
		alert("Warning - Do not include website URLs in your introduction. Sorry but we must be diligent in fighting SPAM!");
		return false;				
	}else if (form.entry.value.length<16 || form.entry.value.length>1024){		
		alert("Please enter a paragraph between 16-1024 chatacters in length.");
		return false;	
	}else if (!validName(form.commentBy.value)){
		alert("Please enter a valid  name.");
		return false;			
	}				
}

function validateSignup(form){

	var d = new Date();
	var valid_year = d.getFullYear()-18;

	//The necessary format for submitting DOB (hidden field)
	form.DOB.value	= form.dob_month.value + "28" + form.dob_year.value;

	if (!validMinLength(form.UserName.value,4)){
		alert("Please enter a valid username at least 4 characters in length.");
		return false;
	}else if (!validMinLength(form.Password.value,4)){
		alert("Please enter a valid password at least 4 characters in length.");
		return false;
	}else if (!validEmail(form.Email.value)){
		alert("Please enter a valid email address.");
		return false;
	}else if (form.dob_year.value > valid_year){
		alert("You must be 18 years of age to register. Please tell us your actual birthday (month and year).");
		return false;
	}else if (!form.Gender[0].checked && !form.Gender[1].checked){
		alert("Please tell us your gender.");
		return false;
	}else if (!form.Terms.checked){
		alert("You must check the box to accept the terms of use.");
		return false;
	}

}
		
			
/* Limit text input to the specified limit amount. */
function limitText(field){
	limit = 255;
	if (field.value.length>limit){
		field.value = field.value.substr(0,limit-1);
	}
}
	
			
/* Specify status of textarea */
function entryStatus(field,statusSpan){			
	limit = 1024;
	iRemaining = limit - field.value.length;				
	document.getElementById(statusSpan).innerHTML = iRemaining + " Chars Remaining";
}
		
	
/* Open a child window.*/	
function popUp(sLocArg,iHeight,iWidth,bScrolling,bMenubar,windowName) {

    if (iHeight==null) {iHeight=550}
    if (iWidth==null) {iWidth=550}	
    if (bScrolling=='true' || bScrolling==true) {sScroll="yes"}	
	else{sScroll="no"}
	if (bMenubar=='true' || bMenubar==true) {sMenu="yes"}	
    else{sMenu="no"}
	if (windowName==null){windowName='action'}
    sProps = "height="+iHeight+",width="+iWidth+",scrollbars="+sScroll+",menubar="+sMenu;
	
	window.open(sLocArg,windowName,sProps);
}

/* Used by bookmarking/sociable module */		
function shareme(preurl){
	url = preurl + location;
	location.href = url;
}		