/////////////////////////////////////////////////////////////////////////////////////////////
//======================RenderVote() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	nRenderType	: determine the type of rendering (question, result) .
//				  -1	=>	default state to render the the question with it's options
//				  0		=>	show results (with 'go back to vote' shown)
//				  +ve	=> 	user voted ('go back to vote' not shown)	 		
//	bIsOnline	: determine if it is online state or system  .
//	nVote_id	: the vote id.
//================================================================================
//	return  value : HTML representation of the vote
//================================================================================
//	Description : this function is the entry point to draw the vote table 
//				  according to the states determined by 'nRenderType'	
/////////////////////////////////////////////////////////////////////////////////////////////

function RenderVote( nRenderType, bIsOnline , nVote_id ,voteSeq)
{
//debugger;
//alert("nVote_id =" + nVote_id);
	// dealing with vote as an object with needed properties
	var objVote							= new Object() ;
		objVote.cu_no					= 1		;
		objVote.active					= 1		;
		objVote.start_date				= "-1"	;
		objVote.close_date				= "-1"	;
		objVote.options_number			= "2"	;
		objVote.vote_id					= "-1"	;
		objVote.answer_id				= "-1"	;
		objVote.template_id				= "-1"	;
		objVote.nRenderType				= "-1"	;
		objVote.bIsOnline				= "1"	;	
		objVote.XML						= new ActiveXObject("Microsoft.XMLDOM");		
		objVote.XML.async				= false	;			
		objVote.XSL						= new ActiveXObject("Microsoft.XMLDOM");
		objVote.XSL.async				= false	;				
	
	// set the proeprties of the Vote object 
	setVoteObjectProperites( objVote, nRenderType , bIsOnline , nVote_id) ;
	//alert("After setProperties: objVote.nRenderType = " +objVote.nRenderType);
	if( checkCookieInfo(objVote)  && nRenderType != "-2")
	{
		objVote.nRenderType = "1" ;// check cookies	
		objVote.answer_Id	= "0" ;
	}
	
	//alert("after checkCookies: objVote.nRenderType = " +objVote.nRenderType);
	
	
//	if( objVote.bIsOnline !=  "0" ) // online case 
//	{
		// send an HTTPRequest to save the data on an ASP page
		
		var objHTTPRequest = new ActiveXObject("MSXML2.XMLHTTP") ;
		var strURL = "/topics/Vote.asp?cu_no=" + objVote.cu_no 
					+ "&bIsOnline="		+ objVote.bIsOnline 
					+ "&vote_Id="		+ objVote.vote_id 
					+ "&answer_id="		+ objVote.answer_id 
					+ "&template_id="	+ objVote.template_id 
					+ "&renderType="	+ objVote.nRenderType 
					+ "&current_date="	+ getCrntDate();
					  
		objHTTPRequest.open("GET",strURL,false) ; 
		//prompt("strURL", strURL);

		try
		{
			      
			// send the request
			objHTTPRequest.send() ;		
		}
		catch(e)
		{
			alert(e.description);
			return false ;
		}								
		// draw the vote table
//		prompt("objHTTPRequest.responseText", objHTTPRequest.responseText);

		var strvoteCell
		
		if (document.getElementById("voteSearchLevelNumber").value == 3 || document.getElementById("voteSearchLevelNumber").value == 31){
			strvoteCell = "votingCell" + nVote_id			
		}
		else
		{
			if (voteSeq != "" && voteSeq != undefined){
				
				strvoteCell = "votingCell" + voteSeq
			}
			else {
				strvoteCell = "votingCell" + nVote_id			
		
			}	
		}
		if(document.getElementById(strvoteCell)){
		    if (objVote.nRenderType == -2 || objVote.nRenderType > 0)
		    {
			    document.getElementById(strvoteCell).innerHTML = objHTTPRequest.responseText ;
			}
			else
			{
			    document.getElementById(strvoteCell).innerHTML = "" ;
			}
		}
		
		if (document.getElementById("VoteQuestions" + nVote_id))
		{
		   if (objVote.nRenderType == -2 || objVote.nRenderType > 0)
		   {
		        document.getElementById("VoteQuestions" + nVote_id).style.display="none";
		   }
		   else if (objVote.nRenderType == -1)
		   {
		        document.getElementById("VoteQuestions" + nVote_id).style.display="";
		   }
		}
		var IntLevelNo
				
		IntLevelNo = document.getElementById("voteSearchLevelNumber").value
		
		if (IntLevelNo == '8') {
			document.getElementById("tdvoteQuestion").style.display = "none" ;
		}
		
		// set the cookies
		if( objVote.answer_id > 0 )
		{			
			SetCookie("vote"+objVote.vote_id,objVote.vote_id,objVote.close_date);		
		}	
	
//	}

}

/////////////////////////////////////////////////////////////////////////////////////////////
//======================RenderVote() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//	nRenderType	: determine the type of rendering (question, result) .
//				  -1	=>	default state to render the the question with it's options
//				  0		=>	show results (with 'go back to vote' shown)
//				  +ve	=> 	user voted ('go back to vote' not shown)	 		
//	bIsOnline	: determine if it is online state or system  .
//	nVote_id	: the vote id.
//================================================================================
//	return  value : none
//================================================================================
//	Description : set some of the vote object properties
/////////////////////////////////////////////////////////////////////////////////////////////

function setVoteObjectProperites( objVote, nRenderType , bIsOnline , nVote_id ) 
{
	// set cu_no
	if( document.all.cu_no && document.all.cu_no.value != "" && document.all.target_template.value != undefined)
	{
		objVote.cu_no = document.all.cu_no.value ;
	}

	// set template_id 
	if( document.all.target_template && document.all.target_template.value != ""  && document.all.target_template.value != undefined)
	{
		objVote.template_id = document.all.target_template.value ;
	}
	
	
	// set vote_id
	/*if( document.all.target_vote_id )
	{
		// only for back compatibility
		objVote.vote_id = document.all.target_vote_id.value ;
	}*/
	/*else*/ if( nVote_id )
	{
		objVote.vote_id = nVote_id ;
	}
	
	
	// set the render type property of the vote object
	//if( nRenderType != "-1" ) 
		objVote.nRenderType				= nRenderType	;
	
	// set the answer_id (if user had select)
	if( nRenderType > "0" ) // case where user had selected an option
		objVote.answer_id				= nRenderType ;
		
	
	// set the online property	
	if( bIsOnline.toString() == "0") // system case
	{
		objVote.bIsOnline				= "0"	;	
	}	
}

/////////////////////////////////////////////////////////////////////////
// DOM related Functions
/////////////////////////////////////////////////////////////////////////	

/////////////////////////////////////////////////////////////////////////////////////////////
//======================setVoteXML() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//================================================================================
//	return  value : true / flase
//================================================================================
//	Description : set XML nodes of the xml DOM in the vote object
//				 accroding to objVote.nRenderType and online state
/////////////////////////////////////////////////////////////////////////////////////////////

function setVoteXML(objVote)
{		
	
	var xmlFileXpath			= ""	;
	
	
	if ( objVote.XML.parseError.errorCode != 0 )
	{
		return false ;
	}	
	
	
	if( objVote.bIsOnline !=  "0" ) // online case 
	{		
		if( objVote.nRenderType >= "0"  ) // if user made a selection
		{								  // (update  the vote)
										  // or show result case
 			// voteUpdate.xml uses ks_Upd_Vote SP
			xmlFileXpath = "/xml/topics/vote/voteUpdate.xml?cu_no="		+ objVote.cu_no  
																+ "&vote_Id="	+ objVote.vote_id 
																+ "&answer_Id="	+ objVote.answer_id 
																+ "&temp_id="	+ objVote.template_id	
																+ "&bIsOnline="	+ objVote.bIsOnline	;			
																
		}
		else // draw normal question and options 
		{	 //	(or results accordin to what is returned from cookies test)
			
			// uses Xpath and schema
			xmlFileXpath = "/xml/topics/vote/vote.xml?cu_no="			+ objVote.cu_no
													   + "&template_id="	+ objVote.template_id 
													   + "&active="			+ objVote.active	
													   + "&bIsOnline="		+ objVote.bIsOnline	;					
		}		
		
		try
		{		
			// load the xml DOM with file path 
			objVote.XML.load( xmlFileXpath ) ;
		}
		catch(e)
		{
			alert(e.description) ;
			return false ;
		}
		
		
	}
	else // system case 
	{
		// get DOM from frame["search"]
		var searchFrame = window.top.frames["search"] ;
		if(searchFrame)
			if(searchFrame.xmlDoc)
			{
				var rootNode	= searchFrame.xmlDoc ;
				var xPath		= ".//el_ks_vote_related[active=" + objVote.active + "]" ;
				// in system i only have one vote at a time 
				// having active = 1 			
				var voteNode	= rootNode.selectSingleNode(xPath) ;
				
				if(voteNode)
				{
					if(voteNode.selectSingleNode(".//vote_id"))
						objVote.vote_id	= voteNode.selectSingleNode(".//vote_id").text ;
					
					if(voteNode.selectSingleNode(".//template_id"))
						objVote.template_id	= voteNode.selectSingleNode(".//template_id").text ;					
					
					try
					{		
						// load the xml DOM with XML Node 
						objVote.XML.loadXML( voteNode.xml ) ;							
					}
					catch(e)
					{
						alert(e.description) ;
						return false ;
					}
					
				}
				
			}					
	}	
	
	
	// set some vote object properties
	// set start date
	if( objVote.XML.selectSingleNode(".//el_ks_vote_related//el_ks_vote_main//start_date") )
		objVote.start_date				= 	objVote.XML.selectSingleNode(".//el_ks_vote_related//el_ks_vote_main//start_date").text ;
	// set close date 
	if( objVote.XML.selectSingleNode(".//el_ks_vote_related//el_ks_vote_main//close_date") )
		objVote.close_date				= 	objVote.XML.selectSingleNode(".//el_ks_vote_related//el_ks_vote_main//close_date").text ;	
	
	// set number of options	
	//objVote.options_number = XML.selectNodes(".//el_ks_vote_related//el_ks_vote_results").length ;			
		
	return true ;
}

/////////////////////////////////////////////////////////////////////////////////////////////
//======================setVoteXSL() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//================================================================================
// return  value : true / flase
//================================================================================
//	Description : set XSL DOM in the vote object according to objVote.nRenderType
/////////////////////////////////////////////////////////////////////////////////////////////

function setVoteXSL(objVote)
{
	var xslFileXpath			= ""	;
	if ( objVote.XSL.parseError.errorCode != 0 )
	{
		return false ;
	}
	
	if( objVote.nRenderType >= "0"  ) // if user made a selection or show result	
	{
		xslFileXpath = "/xml/topics/vote/voteUpdate.xsl"	;	
		// in sytem case ( objVote.nRenderType = "-1"  ) 
		
		// set the cookies
		if(objVote.nRenderType > "0")
		{
			SetCookie("vote"+objVote.vote_id,objVote.vote_id,objVote.close_date);								
		}
	}
	else	
		xslFileXpath = "/xml/topics/vote/vote.xsl"	;
	
	
	try
	{		
		// load the xml DOM with file path 
		objVote.XSL.load( xslFileXpath ) ;		
	}
	catch(e)
	{
		alert(e.description) ;
		return false ;
	}	
	
	return true ;			
}

/////////////////////////////////////////////////////////////////////////
// Cookies related Functions
/////////////////////////////////////////////////////////////////////////	

/////////////////////////////////////////////////////////////////////////////////////////////
//======================checkCookieInfo() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//================================================================================
//	return  value : true / flase
//================================================================================
//	Description : check for cooikes states,in online case only, 
//				  if user had previously voted or vote expired
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////	
function  checkCookieInfo(objVote) 
{
	// check if cookies is disabled
	if (!(navigator.cookieEnabled))
	{
		alert ("cookies is not enabled") ;
		return -1 ;
	}			
	
	if( userHadVote(objVote) )
	{		
		//objVote.nRenderType = "0"  ; // show result case 		
		return true ;
	}
	
	return false ;	
}
/////////////////////////////////////////////////////////////////////////////////////////////
//======================userHadVote() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//================================================================================
//	return  value : true / flase
//================================================================================
//	Description : test if user had previously voted 
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////	

function userHadVote(objVote)
{
	var		sCookieName		="" ;
	var		sCookieValue	="" ;
	var		sCookieKey		="vote" ;
	
	sCookieValue			= objVote.vote_id ;// set the vote id ....
	sCookieKey				+= objVote.vote_id ;// this to check the value of the vote id ....				
	
					
	if(document.all.target_vote_id)
		document.all.target_vote_id.value	= objVote.vote_id ;		
		
	
	sCookieName		= GetCookie(sCookieKey) ;	
	
	
	// check if user had previously voted before
	if( sCookieName )
	{		
		
		if( sCookieName == sCookieValue  )
		{			
			return true; // there is key in cookie , mean that the client vote			
		}
	}
	
	return false ;
}
/////////////////////////////////////////////////////////////////////////////////////////////
//======================userHadVote() ======================================================
//================================================================================
//	input		: value .
//-----------------------------------------------------------------------------------
//	objVote		: vote object	
//================================================================================
//	return  value : true / flase
//================================================================================
//	Description : test if  vote expired
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////	

function VoteExpired(objVote)
{
	var		sCookieExp		="" ;
	var		sVoteStartDate	="" ;
	
	
	var		today = new Date();
	var		Expday;
	var		strday;
	
	// set the start and close date
	sCookieExp		=	objVote.close_date ;		
	sVoteStartDate	=	objVote.start_date ; 	
	
	sCookieExp		= parseDateObject(sCookieExp,1,"/") ;
	if( sCookieExp )
	{
		Expday = new Date(sCookieExp);
		Expday.setHours(today.getHours(),today.getMinutes()+1,today.getSeconds()  );
	}
	else
	{
		Expday = today ;			
	}
		
	sVoteStartDate	= parseDateObject(sVoteStartDate,1,"/");
 	if( sVoteStartDate )
	{
		strday = new Date(sVoteStartDate);		
		strday.setHours(today.getHours(),today.getMinutes()-1,today.getSeconds()  );
	}
	else
	{
		strday = today ;			
	}
	if( (today >= strday) && (today <= Expday))
	{
		return false ;	// vote still active	
	}	
	
	return true ;// vote expired 
}

//======================SetCookie() ===========================
// function check cookies  
// writen By	:Khader@20-02-2001
//=============================================================
// Create a cookie with the specified name and value.
// The cookie expires at the end of the expiration Date.
//=============================================================

function SetCookie(sName,sValue ,sExpiration )
{
	//  expDate = new Date('1/1/2009');	
		expDate = new Date() ;
		expDate.setYear(expDate.getYear()+ 1);
	
	expiration = ";expires=" + expDate.toUTCString() +";" ;
	
	var domain	= ";domain=" + "http://intikhabat" ; 
	var path	= ";path=" +  "http://intikhabat/site/" ; 
	
	try
	{		
		document.cookie = sName + "=" + escape(sValue) + expiration ;//+ domain + path ;		
	}
	catch(e)
	{
		alert(e.description) ;		
		return false ;
	}
	return true ;
}

//======================GetCookie() ===========================
// function check cookies  
// writen By	:Khader@20-02-2001
//=============================================================
// Retrieve the value of the cookie with the specified name.
//=============================================================
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");  	
  
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");      
	if (sName == aCrumb[0]) 
	{  
	   return unescape(aCrumb[1]);     
	}      
      
  }

  // a cookie with the requested name does not exist
  return null;
}

//======================Vote_onclick() ======================
// this function is the main function  which is used for 2 goal
// first : at first time the xsl is loaded it called 
// second : when click the button id=vote_id (vote) client click
//=============================================================
// writen By	: Khader@20-02-2001
// updated by	: Mohamemd AL-Tobji @27-03-2003
//=============================================================
// input Param : 
//	dataButton which take :
//				-1: mean to view the result or answer at first time .
//				otherwise >=0 : mean the client click the button vote.			
//=============================================================
function Vote_onclick(dataButton, voteID , SubvoteSeq) 
{
//debugger;
//alert(dataButton);
	if( dataButton < 0 ) 
	{					 
		alert("Please choose your answer ?");
		return ;
	}
	/*if( dataButton == undefined ) 
	{					 
		alert("Please choose your answer ?");
		return ;
	}*/
	
	// render the result 
	RenderVote( dataButton , "1", voteID, SubvoteSeq) ; // it is allowed in online case 
	
}	
function test()
{
 alert("fn test");
}

/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

// input date will be like yyyy/mm/dd
// output will be like mm/dd/yyyy
function  parseDateObject(sDateVal,dateFormay,sep)
{
		var tempVal = sDateVal.split(sep);
		if( tempVal.length == 3 ) // to ensure that the date is true 
		{
			var year     = tempVal[0] ; // e.g tempVal[0]=2001/02/12
			var month	 = tempVal[1] ; // e.g 2001/tempVal[1]=02/12
			var	day		 = tempVal[2] ; // e.g 2001/02/tempVal[2]=12
			if( dateFormay == 1)// convert to mm/dd/yyyy
			{
				return  month+sep+ day+sep +year ;
			}
			if( dateFormay == 2)// convert to yyyy/mm/dd
			{
				return  day+sep+ month +sep + year  ;
			}
			if( dateFormay == 3)// convert to yyyy/dd/mm
			{
				return  year+sep+ day +sep +month ;
			}
		}
		else
		{
			return null;// return null value .... 
		}	
}

var intAnswer_id	= -1 ;
var bFlag		= false;

function stopAllErrors() 
{
  return true;
}

window.onerror = stopAllErrors;

// khader@06-05-2001
function getCrntDate()
{
	var objDate = new Date();
	var strDay,strMonth,strDate,iMonth;
	iMonth= objDate.getMonth()+1 ;
		if(objDate.getDate()> 9)
			strDay= objDate.getDate();
		else
			strDay= "0" + objDate.getDate(); 
				
		if(iMonth > 9)
			strMonth= iMonth;
		else
			strMonth= "0" + iMonth ; 	
	strDate=   objDate.getYear() +"/"+ strMonth +"/"+strDay;
	return strDate;				
				
}		
/////////////////////////////////////////////////
// khader@06-05-2001
// this is for client search 
function submitSearch()
{
	ValidateForm();
}
function ValidateForm()
{  	
	if ( !((document.all.sourceDayFrom.value==0) && (document.all.sourceMonthFrom.value==0) ) && !((document.all.sourceDayFrom.value!=0) && (document.all.sourceMonthFrom.value!=0) && (document.all.sourceYearFrom.value!=0)) )
	{
		if(document.all.sourceDayFrom.value==0)
			//alert("الرجاء اختيار يوم بدء التصويت");
			//alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u064A%u0648%u0645%20%u0628%u062F%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
		   alert("Please select vote start day");
		else if(document.all.sourceMonthFrom.value==0)
	//			alert("الرجاء اختيار شهر بدء التصويت");
				//alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u0634%u0647%u0631%20%u0628%u062F%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
		        alert("Please select vote start month");
		else if(document.all.sourceYearFrom.value==0)
				//alert("الرجاء اختيار سنة بدء التصويت");
				//alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u0633%u0646%u0629%20%u0628%u062F%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
	            alert("Please select vote start year");
	}
	else 
	{
		if ( !((document.all.sourceDayTo.value==0) && (document.all.sourceMonthTo.value==0) && (document.all.sourceYearTo.value==0)) && !((document.all.sourceDayTo.value!=0) && (document.all.sourceMonthTo.value!=0) && (document.all.sourceYearTo.value!=0)) )
		{
			if(document.all.sourceDayTo.value==0)
				//alert("الرجاء اختيار يوم إنتهاء التصويت");
				 //alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u064A%u0648%u0645%20%u0625%u0646%u062A%u0647%u0627%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
			   alert("Please select vote end day");
			else if(document.all.sourceMonthTo.value==0)
				//alert("الرجاء اختيار شهر إنتهاء التصويت");
				 //alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u0634%u0647%u0631%20%u0625%u0646%u062A%u0647%u0627%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
			   alert("Please select vote end month");
			else if(document.all.sourceYearTo.value==0)
				//alert("الرجاء اختيار سنة إنتهاء التصويت");
				//alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0627%u062E%u062A%u064A%u0627%u0631%20%u0633%u0646%u0629%20%u0625%u0646%u062A%u0647%u0627%u0621%20%u0627%u0644%u062A%u0635%u0648%u064A%u062A"));
		   		alert("Please select vote end year");
		}
		else
		{
			/*
			if(document.all.question.value == "")
			{
				//alert("الرجاء إدخال كلمة واحدة على الأقل");
				//alert(unescape("%u0627%u0644%u0631%u062C%u0627%u0621%20%u0625%u062F%u062E%u0627%u0644%20%u0643%u0644%u0645%u0629%20%u0648%u0627%u062D%u062F%u0629%20%u0639%u0644%u0649%20%u0627%u0644%u0623%u0642%u0644"));
			    //alert("Please insert one word at least");	
			    alert("Please enter data to search for");  
			}	
			else			
			{
			*/
				var  startDate	 = ""	;
				var  endDate	 = ""	;
				var  searchValue = "";
				//var  xmlfile	 = "/xml/topics/voteSearch.xml?cu_no=1&id=1" ;
				var  xmlfile	 = "/topics/index.asp?cu_no=1&id=1" ;
				if( document.all.sourceDayFrom.value != 0 && document.all.sourceYearFrom.value != 0 && document.all.sourceMonthFrom.value != 0 )
				{
					xmlfile	+="&start_date=" + document.all.sourceMonthFrom.value +"/"+ document.all.sourceDayFrom.value + "/" + document.all.sourceYearFrom.value;
				} else{
					xmlfile	+="&start_date="
				}
				if( document.all.sourceDayTo.value != 0 && document.all.sourceYearTo.value != 0 && document.all.sourceMonthTo.value != 0 )
				{
					xmlfile	+= "&close_date=" + document.all.sourceMonthTo.value + "/" + document.all.sourceDayTo.value + "/" + document.all.sourceYearTo.value ;
				} else{
					xmlfile	+="&close_date="
				}
				var question = document.all.question.value.replace(/^ *| *$/g,"");
				if (question == "")
					xmlfile +="&question=*";
				else
					xmlfile +="&question=" + question;
					
				xmlfile += "&level=8"; 
			
				//var xmlDoc = null ;
				//	xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
				//	xmlDoc.async = false;	
				
				if(!CheckDates())
				{
					alert("Please select correct dates");
					return false;
				}
				else
				{
					window.location.href  = xmlfile ;	
				}
			//}		
		}		
	} 
}


function CheckDates()
{	
	var intFromYear = Math.ceil(sourceYearFrom.value);
	var intFromMonth = Math.ceil(sourceMonthFrom.value);
	var intFromDay = Math.ceil(sourceDayFrom.value);
	
	var intToYear = Math.ceil(sourceYearTo.value);
	var intToMonth = Math.ceil(sourceMonthTo.value);
	var intToDay = Math.ceil(sourceDayTo.value);
	
	
	if(intFromMonth == 2 && intFromDay>28)
	{
		return false;
	}
	
	if(intToMonth == 2 && intToDay >28)
	{
		return false;
	}
	
	
	if(intFromYear>0 && intFromMonth>0 && intFromDay>0 && intToYear>0 && intToMonth>0 && intToDay>0)
	
	{
		{
			if(intFromYear == 0 || intFromMonth == 0 || intFromDay == 0 || intToYear == 0 || intToMonth == 0 || intToDay == 0)
				return false;
				
			if(intFromYear > intToYear)
				return false;
			else
				if(intFromYear < intToYear)
					return true;
				else
				{
					if(intFromMonth > intToMonth)
						return false;
					else
						if(intFromMonth < intToMonth)
							return true;
						else
						{
							if(intFromDay > intToDay)
								return false;
							else
								if(intFromDay < intToDay)
									return true;
						}
				}
			
		}
	}
	
	return true;
}


function voteClick(vote_id,temp_id,CurrentvoteSeq,VotesCount)
{
	var strvoteCell2 = "votingCell" + CurrentvoteSeq
	
	var strvoteQuestion = "voteQuestion" + CurrentvoteSeq
	
	
	document.getElementById('currSeq').value = CurrentvoteSeq
	
	var voteCellIndex
	for(i=1;i<=VotesCount;i++){
		if (CurrentvoteSeq != i) {
			document.getElementById("voteQuestion" + i).className = "VoteTableTextBold" ;
			document.getElementById("votingCell" + i).innerHTML = "" ;
			
					
		}
	}
			if (document.getElementById(strvoteCell2).innerHTML == "")
			{
						
				document.getElementById(strvoteQuestion).className = "VoteTableTextBoldClicked"	; 
	
				if( document.all.target_template  )
				{
					if(  parseInt(document.all.target_template.value) != parseInt(temp_id) )
						document.all.target_template.value = temp_id 
				}
			
				if( document.all.target_vote_id )
				{
					document.all.target_vote_id.value = vote_id ;
				}
			
				if(document.all.vote_main_table && document.all.vote_main_table.className != '')
				{
					document.all.vote_main_table.className = '';
				}
	
				RenderVote( "-1", "1" , vote_id, CurrentvoteSeq) ;
				
			
			}		
			else
			{
				document.getElementById(strvoteQuestion).className = "VoteTableTextBold"	; 
				document.getElementById(strvoteCell2).innerHTML = "" ;
							
			}
				
			

}

function reportParseError(error)
{
  var s = "";
  for (var i=1; i<error.linepos; i++)
  {
    s += " ";
  }
  r = "<font face=Verdana size=2><font size=4>XML Error loading '" ; 
  r +=   error.url + "'</font>" ;
  r +=    "<P><B>" + error.reason ; 
  r +=    "</B></P></font>";
  if (error.line > 0)
  {
    r += "<font size=3><XMP>" ;
    r +="at line " + error.line + ", character " + error.linepos ;
    r +="\n" + error.srcText ;
    r +="\n" + s + "^" ;
    r +="</XMP></font>";
   }
  return r;
}
