// function to set the div of comment
function displayComment(divId, title, label, target){
	
	var formTitle = "title" + divId;
	var formLabel = "label" + divId;
	
	if(document.getElementById(divId).style['display'] == 'block' && 
	document.getElementById(formTitle).innerHTML == title)
	{
		
		document.getElementById(divId).style['display'] = 'none';
	}
	else{
		
		document.getElementById(divId).style['display'] = 'block';
	}
	
	var formTitle = "title" + divId;
	var formLabel = "label" + divId;
	
	
	document.getElementById(formTitle).innerHTML = title;
	
	//document.getElementById(formLabel).innerHTML = label + ":";
	
	var formName = "form" + divId;
	
	
	
	var inputs = document.getElementById(formName).elements;
	
	var inputByName = inputs["method"];
	
	inputByName.value = target;
	
	//document.getElementById(formName).name = target;
	//document.getElementById(formName).onsubmit = "if(validateCommentForm(this,' + label + ',' + divId + ')){verify(this.form,divId);}";
	buttonName = 'button' + divId;
	document.getElementById(buttonName).name = label;	
}

// function to open new window
function openNewWindow(url, windowName){
	window.open(url,windowName,'status=yes,width=650,height=500,scrollbars=yes');
}

// function to open a new window to view results of poll
function popup(url, windowName){
	window.open(url, windowName, 'left=0,top=0,width=250,height=190,scrollbars=no');	
	return false;
}

// function for search articles by keword by contributor/content
function validateSearchArticleForm(form){
	var keyword = form.keyword.value;
	if(keyword == '' || keyWord == null){
		alert("Please enter Keyword");
		form.keyWord.focus();
		return false;
	}
	var searchOption = form.searchOption.value; 
	if(searchOption == 0){
		alert("Please select Search By option");
		form.searchOption.focus();
		return false;
	}  
	form.submit();
	return true;
}


function validateSearchForm(form){
	var keyword = form.keyword.value;
	if(keyword == '' || keyword == null){
		alert("Please enter Keyword");
		form.keyword.focus();
		return false;
	}
	var choice = form.choice.value; 
	if(choice == 0){
		alert("Please select Search By option");
		form.choice.focus();
		return false;
	}  
	form.submit();
	
	return true;
 

}



function callAction(form){
	var keyword = document.searchArticleForm.keyword.value;
	if(keyword == '' || keyword == null){
		alert("Please enter Keyword");
		document.searchArticleForm.keyword.focus();
		document.searchArticleForm.choice.value ="";
		return false;
	}
	var choice = document.searchArticleForm.choice.value; 
	if(choice == ""){
		alert("Please select Search By option");
		document.searchArticleForm.choice.focus();
		return false;
	}  
	var choice = document.searchArticleForm.choice.value; 
	var action="";
	if(document.searchArticleForm.choice.value  == 'sitesearch' ){
	//alert(document.searchArticleForm.keyword.value);
	//alert(document.searchArticleForm.q);
	document.searchArticleForm.q.value=document.searchArticleForm.keyword.value;
	document.searchArticleForm.action="/googlesearch.jsp"
	//return false;
	}
	else{
       document.searchArticleForm.action="/articleSearch"
	}
	  
	document.searchArticleForm.submit();
	return true;
}

// function for search articles by keword by contributor/content
function validateSearchNewArticle(form){
	var keyword = form.keyword.value;
	if(keyword == '' || keyword == null){
		alert("Please enter Keyword");
		form.keyword.focus();
		return false;
	}
	
	form.submit();
	return true;
}


// function to validate the entered email
function isValidEmail(email){
	mailRE = new RegExp( );
	mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
	return (mailRE.test(email));
}

// function to clear the text from email text box on focus
function removeEmail(form){
	form.email.value="";
}

// function used when clicked on go for subsribing to newsletter
function validateSubscribeForm(form) {
	email=form.email.value;
	if((email==''||email==null)) {
		alert("Please enter E-Mail");
		form.email.focus();
		return false;
	}
	else if(!isValidEmail(form.email.value)) {
		alert( "Please enter valid E-mail address");
		form.email.focus();
		return false;
	}
	else {
		popup("subscribe.jsp?eid="+email,'subscribe');
		return false;
	}
}
 
// function for voting a poll
function validateVoteForm(form, pollId){
	var vote="";
	var choice=false;
	for (i = 0; i < form.vote.length; i++) {
		if (form.vote[i].checked) {
			vote = form.vote[i].value;
			choice = true;
		}
	}
	if(!choice){
		alert("Please select a choice");
		return false;
	}
	else{
		popup("pollQuestion.do?type=SetPollResults&vote=" + vote + "&pollID=" + pollId, 'ViewResults');
		return false;
	}
	
	return false;
}

function removeFieldValue(){
	
	 if(document.commentForm.commenterName.value=="Name"){
	 document.commentForm.commenterName.value='';
	
	return false;
	}
	
	if(document.commentForm.description.value=="Comments"){
	 document.commentForm.description.value='';
	
	return false;
	}
	
	if(document.commentForm.email.value=="Email"){
	 document.commentForm.email.value='';
	
	return false;
	}
	
	return false;
}




function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function




function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function imageTitleSearch(){
	var text = document.getElementById('image').title;
		if(text != ""){
		window.open("/articleSearch?keyword="+text+"&q=&choice=Content");
		}
	}