function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=770,height=500,left = 132,top = 134');");
}


function deleteOldCookies()
	{
		//alert("Start:" + startVar);
		if (startVar == 1)
		{
			//alert("Just started cookies:" + document.cookie);
			var currentcookie = document.cookie;
			var arrayofpart = currentcookie.split(";");
			//alert(arrayofpart.length);
			for (i=0; i < arrayofpart.length;i++)
			{
				if ((arrayofpart[i].match ( '(^|;) ?' + "CFID" + '=([^;]*)(;|$)' )) || (arrayofpart[i].match ( '(^|;) ?' + "CFTOKEN" + '=([^;]*)(;|$)' )) || (arrayofpart[i].match ( '(^|;) ?' + "style" + '=([^;]*)(;|$)' )))
				{
					//alert("dont delete");
				}
				else
				{
					var partIddel = arrayofpart[i].split("=");
					delete_cookie(partIddel[0]);
				}
			}
			
		}	
		
		//alert("Clean:" + document.cookie + "Start:" + startVar);
	}

function checkCookie(prtList,qsprtID)
{
	var arrayofpart = prtList.split("&");
	//alert(arrayofpart.length);
	for (i=0; i < arrayofpart.length;i++)
	{
		var partId = arrayofpart[i].split("_");
		if (partId[0] == qsprtID)
		{
			return ( unescape (partId[1]));
		}
	}	
	return null;	
		//alert("Clean:" + document.cookie + "Start:" + startVar);
}
	
function delete_cookie ( cookie_name )
	{
	  var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );
	  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	}
	

function gopage(ipagenum) {
	document.frm1.UserAnswered.value = 1;
	document.frm1.PageNum.value = ipagenum;
	document.frm1.submit();
}

function updateCSS(f)
{
	document.getElementsByTagName('link')[0].setAttribute('href', f);
}


function setCookie(qpartId, ansResultVal)
{
	var current = getCookie("answerList");
	var updated;
	if (current == null)
	{
		updated = escape (qpartId) + "_" + escape (ansResultVal) + "&";
	}
	else
	{
		updated = current + escape (qpartId) + "_" + escape (ansResultVal) + "&";
	}
	document.cookie = "answerList =" + updated;
	//document.cookie = qpartId + "=" + escape (ansResultVal);
	//alert("Cookie Set:" + document.cookie);
}

function getCookie(qpartId)
{
	if (document.cookie.length > 0)
	{
		var results = document.cookie.match ( '(^|;) ?' + qpartId + '=([^;]*)(;|$)' );
		if ( results )
    		return ( unescape ( results[2] ) );
  		else
    		return null;
	}
	return null;
}

function fncShowHideBox(dvid,from)
{  
	objDiv = document.getElementById(dvid);
	if (objDiv != null) 
	{	
		if (from == 1)
		{
			objDiv.style.display = 'block';
		}
		if (from == 0)
		{
			objDiv.style.display = 'none';
		}
	}
}

function fncShowHideBox1(dvid1,from)
{  
	objDiv = document.getElementById(dvid1);
	if (objDiv != null) 
	{	
		if (from == 1)
		{
			objDiv.style.display = 'block';
		}
		if (from == 0)
		{
			objDiv.style.display = 'none';
		}
	}
}

function answerchange(j,t,b) 
{

	rb = t.length;
	var selval;
	for(i=0;i<rb;i++)
	{
		if(t[i].checked == true)
		{
			selval = t[i].value;
			break;
		}
	}
	document.frm1.iAnswer.value =selval; 
	if(document.frm1.browse.value==1)
	{
	//alert("Already Answered !");
	//window.history.go(+2);
	document.frm1.browseflag.value =1; 
	}
	document.frm1.browse.value =1; 
//	alert(b);
	if (eval("document.frm1.ansres_"+selval+".value") == "Yes") {
		document.frm1.iAnswerresult.value = 1; 
	}
	else {
		document.frm1.iAnswerresult.value = 0; 
	}
	var dvid = 'answerOne_'+selval;
	var dvid1 = 'answerOneimg_'+selval;

	myString = new String(document.frm1.divid.value);
	splitString = myString.split(",");
	for(i=0;i<splitString.length;i++)
	{	
		fncShowHideBox('answerOne_'+splitString[i],0);
		fncShowHideBox1('answerOneimg_'+splitString[i],0);
		
	}
	
	var partList = getCookie("answerList");
	var isPartans;
	if (partList == null)
	{
		isPartans = null;
	}
	else
	{
		isPartans = checkCookie(partList, document.frm1.QpartidAns.value);
	}
	if (isPartans == null){
		setCookie(document.frm1.QpartidAns.value,document.frm1.iAnswerresult.value);
		fncShowHideBox(dvid,1);
		fncShowHideBox1(dvid1,1);
		funcncShow1(t);
	} 
	else
	{
		document.frm1.iAnswerresult.value = isPartans;
		alert("You have already answered this question and we have registered your first response. You will now be directed to the next question part.");
		gopage(pageVar);
	}	
	
}

function funcncShow1(t1)
{
	rb1 = t1.length;
	for(i=0;i<rb1;i++)
	{
		t1[i].disabled=true;
	}
}

function answerchangeimg(j,t) 
{
	rb = t.length;
	var selval;
	var objDiv1;
	for(i=0;i<rb;i++)
	{
		if(t[i].checked == true)
		{
			selval = t[i].value;
			break;
		}
	}

	var dvid1 = 'answerOneimg_'+selval;
   

	myString = new String(document.frm1.divid.value);
	splitString = myString.split(",");
	for(i=0;i<splitString.length;i++)
	{	
		fncShowHideBox1('answerOneimg_'+splitString[i],0);
	}
//	fncShowHideBox1(dvid1,1);
}

function answerchangemultiimg(j,t)
{
	rb = t.length;
	//alert(rb);
	nocount = 0;
	yescount = 0;
	for(i=0;i<rb;i++)
	{	
		if(t[i].checked == true)
		{
			if(t[i].value == 'Yes')
			{
				yescount = yescount + 1;
			}
			else
			{
				nocount = nocount + 1;
			}		
		}
	}
		fncShowHideBox('answerOneimg1',0);	
		fncShowHideBox('answerOneimg2',0);	
}
function answerchange1(j,t)
{
	rb = t.length;
	//alert(rb);
	nocount = 0;
	yescount = 0;
	var imulchk = 0;
	var selvl;
	selvl = '';
	var imulchk;
	for(i=0;i<rb;i++)
	{	
		if(t[i].checked == true)
		{
		    imulchk=1;
			if (selvl == '') {
				selvl = t[i].value;
			}
			else {
				selvl = selvl + ',' + t[i].value;
			}
			//alert(t[i].value);
			if(t[i].value == 'Yes')
			{
				yescount = yescount + 1;
			}
			else
			{
				nocount = nocount + 1;
			}		
		}
	}
//	alert("out"+imulchk);
			if(imulchk == 0)
			{
	//	alert("outa"+imulchk);
				fncShowHideBox('answerOne2',0);
				fncShowHideBox('answerOneimg2',0);
				fncShowHideBox('answerOne1',0);
				fncShowHideBox('answerOneimg1',0);	
			alert("Please Select Atleast One Answer!");
			return false;
			}

		else
		{
	//	alert("outb"+imulchk);
		document.frm1.iAnswer.value = selvl; 
				if(document.frm1.browse.value==1)
				{
				//alert("Already Answered !");
				document.frm1.browseflag.value =1; 
				}
				document.frm1.browse.value =1; 
		dbYesCorrectCount = document.frm1.hdnDBYesCorrectCount.value; 
		if (yescount > 0 && yescount == dbYesCorrectCount && nocount == 0)
		{
				  // alert(yescount);
			document.frm1.iAnswerresult.value = 1; 		
			var partList = getCookie("answerList");
			var isPartans;
			if (partList == null)
			{
				isPartans = null;
			}
			else
			{
				isPartans = checkCookie(partList,document.frm1.QpartidAns.value);
			}
			if (isPartans == null){
				setCookie(document.frm1.QpartidAns.value,document.frm1.iAnswerresult.value);
				fncShowHideBox('answerOne1',1);
				fncShowHideBox('answerOne2',0);
				fncShowHideBox('answerOneimg1',1);
				fncShowHideBox('answerOneimg2',0);
				funcncShow1(t);
			} 
			else
			{
				document.frm1.iAnswerresult.value = isPartans;
				fncShowHideBox('answerOne1',0);
				fncShowHideBox('answerOne2',0);
				fncShowHideBox('answerOneimg1',0);
				fncShowHideBox('answerOneimg2',0);
				funcncShow1(t);
				alert("You have already answered this question and we have registered your first response. You will now be directed to the next question part.");
				gopage(pageVar);
			} 		
		}
		else
		{
			document.frm1.iAnswerresult.value = 0; 	
			var partList = getCookie("answerList");	
			var isPartans;
			if (partList == null)
			{
				isPartans = null;
			}
			else
			{
				isPartans = checkCookie(partList,document.frm1.QpartidAns.value);
			}
			if (isPartans == null){
				setCookie(document.frm1.QpartidAns.value,document.frm1.iAnswerresult.value);
				fncShowHideBox('answerOne1',0);
				fncShowHideBox('answerOne2',1);	
				fncShowHideBox('answerOneimg1',0);	
				fncShowHideBox('answerOneimg2',1);	
				funcncShow1(t);
			}
			else
			{
				document.frm1.iAnswerresult.value = isPartans;
				fncShowHideBox('answerOne1',0);
				fncShowHideBox('answerOne2',0);
				fncShowHideBox('answerOneimg1',0);
				fncShowHideBox('answerOneimg2',0);
				funcncShow1(t);
				alert("You have already answered this question and we have registered your first response. You will now be directed to the next question part.");
				gopage(pageVar);
			} 		
						
		}
	}
}
function openview(filepath,imgiiid) {
		url_string='imagepreview.cfm?filepath='+filepath+'&imgid='+imgiiid+'';
		win_width=800;
		win_height=650;	
		var win_left = 100;
		var win_up = 10;
		window_parameters = 'width=' + win_width + ',height=' + win_height + ',left=' + win_left + ',top=' + win_up + ',scrollbars=1,resizable=1';
		Win = window.open(url_string, "mywin", window_parameters);
		Win.window.focus();
		return false;
}