/*
JavaScript functions for poll module
- uses: ajax.js
*/

function Poll()
{
}

Poll.isVoteConfirm = function( id )
{
	if (document.URL.indexOf("#vote_")>0) {
		var voteId = document.URL.substr(document.URL.lastIndexOf("_")+1);
		if (voteId == id) {
			return true;
		}
	}
	return false;
}

Poll.voteShowHide = function( id, confirm )
{
  try{
	var hideId = "vote-"+id;
	var showId = "voted-"+id;
	var confId = "cnfrm-"+id;
	var hideElm = document.getElementById( hideId);
	var showElm = document.getElementById( showId);
	var confElm = document.getElementById( confId);

	if ( hideElm != null) {
		hideElm.style.display = "none";
		if (!confirm && confElm!=null) {
			confElm.style.display = "none";
		}
	}
	if (confirm && confElm!=null) {
		confElm.style.display = "block";
	} else
	if ( showElm != null) {
		showElm.style.display = "block";
	}
	var hideId = "vote-"+id+"-art";
	var showId = "voted-"+id+"-art";

	var hideElm = document.getElementById( hideId);
	var showElm = document.getElementById( showId);

	if ( hideElm != null && showElm != null) {
		hideElm.style.display = "none";
		showElm.style.display = "block";
	}

  }catch (erm){
	//alert("peiling.ShowHide()"+erm);
  }
}

Poll.voteInitialHide = function( id, divId )
{
  try
  {
	//hide poll Q&A and show Results
	var mentometer = getCookie("mentometer");
	if ( mentometer != null )
	{
	  var mentometer_array = mentometer.split("M");
	  for ( i = 0; i < mentometer_array.length; i++ )
	  {
		if ( mentometer_array[i] != 'null' )
		{
		  if ( mentometer_array[i].match(id) )
		  {
			  Poll.voteShowHide( divId, Poll.isVoteConfirm(id) );
		  }
		}
	  }
	}
  }
  catch ( erm )
  {
	//alert("displayPoll" + erm);
  }
}

Poll.voteSubmit = function( divId, formEl, type )
{
	var redirectUrl = formEl.elements['redirectTo'].value;
	if( !redirectUrl )
		redirectUrl = window.location.href;
	formEl.elements['redirectTo'].value = 
		redirectUrl + 
		"?service=Ajax&ajax=module&s=" + Math.random() + 
		(type ? "&polltype=" + type : "");
	runFormRequest( divId, formEl );
	return false;
}


