function validate()
{

	//var myString = "51,52,53,54,";
	var myString = 	getCookie('CompvQuestionID')
	//alert(myString)
	if( myString ) {
	
		var lastPos = myString.length-1;
		if (myString.charAt(lastPos) == ",")
		{
			var strLen = myString.length;
			myString = myString.slice(0,strLen-1);
		}

		var mySplitResult = myString.split(",");
		for(i = 0; i < mySplitResult.length; i++)
		{
		var val = "Answer" + mySplitResult[i]
		var obj=document.getElementById(val)

		if(obj)
			if(obj.length)
			{
				for(var i=0; i<obj.length;i++)
				{
					if(obj[i].value.length==0)
					{
						obj[i].focus();
						alert("Please enter an answer for the competition.");
						return false;
					}
					else
					{
						if(obj[i].value.length>=500)
						{
							obj[i].focus();
							alert("The answer is too long(max 500)");
							return false
						}
					}
				}
			}
			else
			{
				if(obj.value.length==0)
				{
					
					obj.focus();
					alert("Please enter an answer for the competition.");
					return false;
				}
				
			}
		}

		for(i = 0; i < mySplitResult.length; i++)
		{
			var valR = "Answer" + mySplitResult[i]
			var objR=document.getElementById(valR)
			if(objR && objR.type=="radio" )
			{
				//alert(valR)
				//alert("insdie radio length : " + valR.length)
				//alert( "InnerHTML text : " + document.getElementById(valR).value)
				//alert( "Name: " + document.getElementById(valR).name)
				//alert("Gropu Length : " + radioLength)
				//alert("New Gropu Length : " + radioGrp.length)
				radioLength = document.competition[valR].length
				var radioGrp = document['competition'][valR];
					myOption = -1;
					for(k = 0; k < radioLength; k++) 
					{
						if(radioGrp[k].checked)
						{
							myOption = k;
						}
					}
					if (myOption == -1) 
					{
						alert("Please select an answer for the competition.");
						return false;
					}
			}
		}

	} //end myString
	var sTermsMsg="";
	if(document.competition.terms && !document.competition.terms.checked) {
		sTermsMsg+="You must read the Terms & Conditions before submitting (check box must be checked)\n";
	}
	if (document.competition.privacy && !document.competition.privacy.checked)
	{
		sTermsMsg+="You must read the Privacy Policy before submitting (check box must be checked)\n";
	}
	if(sTermsMsg.length>0) {
		alert(sTermsMsg);
		return false;
	}
	encodeAnswer();
	return true;
}

function TruncateTextArea(obj)
{
	obj.value = obj.value.substring( 0,parseInt(obj.maxlength) );
}

function IsTextAreaTooLong(obj)
{
	return (obj.value.length > parseInt(obj.maxlength));
}



function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
}

function encodeAnswer()
{
	var objForm = document.competition.Answer;
	if(objForm)
	{
		if(objForm.length)
		{
			for(var i=0; i<objForm.length; i++)
				if(objForm[i].value.length>0)
					objForm[i].value = objForm[i].value.replace(/,/g, String.fromCharCode(130));
		}
		else
			if(objForm.value.length>0)
				objForm.value = objForm.value.replace(/,/g, String.fromCharCode(130));
	}	

}
