// JavaScript Document
var board, visual;
function theNetwork () {
	
	var num = document.getElementById('mnum').value.substring(0, 3);
	if (num == "097")
		document.net.src = "libraries/images/zain.gif";
	else if (num == "096")
		document.net.src = "libraries/images/mtn.gif";		
	else if (num == "095")
		document.net.src = "libraries/images/celz.gif";
	else
		document.net.src = "libraries/images/blank.gif";
	
	//checkEvent();	
}

function isEmail( string ) {
	return (/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2,4}|museum|travel)$/i.test(string));
}


function checkRecharge () {
	var t = 0;
	for (var i = 1; i <= 5; i++) {
		t += document.getElementById('rn' + i).value.length;
	}
	
	if (t == 20)
		document.rs.src = "../libraries/images/ok.gif";
	else
		document.rs.src = "../libraries/images/blank.gif";
}

var rdWindow;

function PrintReceipt(mobile, amount) {
	document.getElementById("mnum").value = "";
	document.getElementById("mtamt").value = "0.00";
	if (rdWindow){
		if (!rdWindow.closed) rdWindow.close();
	}
		
	rdWindow = window.open("receipt.php?n="+ mobile + "&a=" + amount,"RenameDuplicate","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,height=400,width=250,left=800");
	rdWindow.focus();
}


function startUpload1(){
      startUpload();
	  document.getElementById('up').submit();      
}
function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
      }
      else {
         result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" onChange="startUpload1();"/><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';      
      return true;   
}

function assigntoboard(id, v) {
	
	board = id ;
	visual = v
	//alert(board)
	document.getElementById('board').value = v;
}

function checkEventP() {
	
	var RETURN = 13;
	var TAB = 9;
	var ESC = 27;	
	var bubble = 1;
	var NEWW = 78;
	var neww = 110;
	var R = 114 ;
	var r = 82;
	var m = 77;
	var M = 109;
	var BACKSPACE = 8;
	
	var e=window.event || e;
	var keyCd = e.keyCode || e.charCode;
		//alert("CharCode value: "+ keyCd)
		
		
	switch(keyCd)
	{
		case RETURN:
			//if (document.getElementById('mnum'))
				postChat();
				return false;
			break;
		//case ESC:
//				break;
//			case NEWW:
//			case neww:
//				UserStat();
//				break;
//			case R:
//			case r:
//				iniReports();
//				break;
//			case m:
//			case M:
//				mngCtrs();
//				break
	}	

}

function checkEvent2() {
	
	//return false;
	//location.href = "?Task=" + document.getElementById("d41d8cd98f00b204e9800998ecf8427e").innerHTML;
	
}
function checkPass() {
	
	if (document.getElementById("pass").value == document.getElementById("pass2").value) {
		document.getElementById("passnote").innerHTML = 'Passwords OK!';
		if (up == false) {
			alert('Please change username.');
			return false;
		}
		else {
		return true ;
		}
	}
	else {
		document.getElementById("passnote").innerHTML = 'Passwords do not match!';
		return false;
	}
	
}


function SetTimeFrame()
{
	var objTimestamp = new Date();
	var nItem	 = document.getElementById("timeframe").options[document.getElementById("timeframe").selectedIndex].value ;
	//var nCurDays	 = Math.floor(objTimestamp.valueOf()/864e5);
	var nCurDays	 = objTimestamp.valueOf()/864e5;
	//alert(nCurDays);
	
	var strDateFrom	 = "";
	var strDateUntil = "";
	var nMonth	 = 0;
	var nDay	 = 0;
	var nSrcDay	 = 0;
	var nSrcMonth	 = 0;
	var nSrcYear	 = 0;
	var nDestDay	 = 0;
	var nDestMonth	 = 0;
	var nDestYear	 = 0;
	switch (nItem)
	{
		case "60":	// Last month
			nCurDays -= objTimestamp.getDate();
			objTimestamp = new Date(nCurDays * 864e5);
			nDestYear = objTimestamp.getYear();
			nDestMonth = objTimestamp.getMonth();
			nDestMonth++;
			nDestDay = objTimestamp.getDate();
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = 1;
			break;
		case "30":	// Current month
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = 1;
			
			do
			{
				nCurDays++;
				objTimestamp = new Date(nCurDays * 864e5);
			} while (objTimestamp.getDate() != 1);
			nCurDays--;
			objTimestamp = new Date(nCurDays * 864e5);
			nDestYear = objTimestamp.getYear();
			nDestMonth = objTimestamp.getMonth();
			nDestMonth++;
			nDestDay = objTimestamp.getDate();
			break;
		case "14":	// Last 2 weeks

			nDay = objTimestamp.getDay();
			if (nDay == 0)
				nDay = 7;
			nCurDays -= nDay;
			objTimestamp = new Date(nCurDays * 864e5);
			nDestYear = objTimestamp.getYear();
			nDestMonth = objTimestamp.getMonth();
			nDestMonth++;
			nDestDay = objTimestamp.getDate();

			objTimestamp = new Date((nCurDays - 6) * 864e5);
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = objTimestamp.getDate();

			break;
		case "7":	// This week
			nDay = objTimestamp.getDay();
			if (nDay == 0)
				nDay = 6;
			else
				nDay--;
			nCurDays -= nDay;
			objTimestamp = new Date(nCurDays * 864e5);
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = objTimestamp.getDate();
			objTimestamp = new Date((nCurDays + 6) * 864e5);
			nDestYear = objTimestamp.getYear();
			nDestMonth = objTimestamp.getMonth();
			nDestMonth++;
			nDestDay = objTimestamp.getDate();
			break;
		case "1":	// Yesterday
			objTimestamp = new Date((nCurDays - 1) * 864e5);
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = objTimestamp.getDate();
			nDestYear = nSrcYear;
			nDestMonth= nSrcMonth;
			nDestDay  = nSrcDay;
			break;
		default:	// Today
			nSrcYear = objTimestamp.getYear();
			nSrcMonth = objTimestamp.getMonth();
			nSrcMonth++;
			nSrcDay = objTimestamp.getDate();
			nDestYear = nSrcYear;
			nDestMonth= nSrcMonth;
			nDestDay  = nSrcDay;
			break;
	}
	//// -----------
	
	if (nSrcMonth < 10)
		strDateFrom = "0" + nSrcMonth + "/";
	else
		strDateFrom = nSrcMonth + "/";
	if (nSrcDay < 10)
		strDateFrom += "0" + nSrcDay + "/";
	else
		strDateFrom += nSrcDay + "/";
		
	strDateFrom += nSrcYear;	

	//// ------------
	
	if (nDestMonth < 10)
		strDateUntil = "0" + nDestMonth + "/";
	else
		strDateUntil = nDestMonth + "/";
	if (nDestDay < 10)
		strDateUntil += "0" + nDestDay + "/";
	else
		strDateUntil += nDestDay + "/";
		
	strDateUntil += nDestYear;

	document.getElementById('dynamic_pannel_start_date').value	= strDateFrom;
	document.getElementById('dynamic_pannel_end_date').value	= strDateUntil;
	iniReports (nItem);
}


// Drop-in content box- By Dynamic Drive
// For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
// This credit MUST stay intact for use

var ns4=document.layers?1:0
var ie4=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0
var calunits=document.layers? "" : "px"

var bouncelimit=40 //(must be divisible by 8)
var direction="up"

function initbox(){
if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-250+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",50)
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<80+scroll_top)
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)

if (document.getElementById("nopop")) {
	if (document.getElementById("nopop").checked == true) {
		if (confirm('Set this option if you are the only\nperson that accessess this computer\n\nContinue?'))
					setPop(2) ;
	}
}
crossobj.visibility="hidden"
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}



function doPopup() {
	initbox();
}

function submittheform(id) {
document.getElementById(id).submit();
}
 
 
function DeleteAction() {

		if(confirm('Are you sure you want to delete this entry?'))
		{
			return true;
		}
		else
		{
			return false;
		}

	}
function UpdateAction() {

	if(confirm('Are you sure you want to make these changes?'))
	{
		return true;
	}
	else
	{
		return false;
	}

}
	
function fks() {
	document.getElementById("user").focus();	
}
	
var ns4 = document.layers;

var ns6 = document.getElementById && !document.all;

var ie4 = document.all;

offsetX = 0;

offsetY = 20;

var toolTipSTYLE="";
var historyShowSTYLE = "";
var updateSTYLE = "";
var titleSTYLE = "";

function iniTool()

{

  if(ns4||ns6||ie4)

  {

    if(ns4) toolTipSTYLE = document.toolTipLayer;

    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;

    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else

    {

      toolTipSTYLE.visibility = "visible";

      toolTipSTYLE.display = "none";

    }

  //  document.onmousemove = moveToMouseLoc;

  }

}

function initupD()

{

  if(ns4||ns6||ie4)

  {

    if(ns4) updateSTYLE = document.updateLayer;

    else if(ns6) updateSTYLE = document.getElementById("updateLayer").style;

    else if(ie4) updateSTYLE = document.all.updateLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else

    {

      updateSTYLE.visibility = "visible";

      updateSTYLE.display = "none";

    }

    //document.onmousedown = moveToMouseLoc;

  }

}
var site = window.location ;
var timeout = false;

function addCrop(e) {
	
	fnUpdate(e);
	
}


function fnUpdate(o_name,d,e,f,nc)

{
 
  var rs;
  if(fnUpdate.arguments.length < 1 || o_name == '') // hide

  {

    if(ns4) updateSTYLE.visibility = "hidden";

    else updateSTYLE.display = "none";

  }

  else // show

  {

    if (o_name && d) {
		
		rs = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="libraries/images/loading.gif" alt="Exit">&nbsp;</td><td><table border="0" cellspacing="0" cellpadding="2"  style="border:1px solid #000033" bgcolor="#C5E8F5"><tr><td colspan=2 height=21 width=90% class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033">&nbsp;<strong>Update User</strong></td><td align=right class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033; padding:2px"><a onClick="fnUpdate();" style="cursor:pointer"><img src="libraries/images/exit.gif" alt="Exit"></a></td></tr><tr style="height:3px" ><td  colspan="2" ></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Name:</strong></td><td   style="padding:2px"><input name="username" type=text class="blueish inp_ta" id="username" value="'+ d +'"/></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Login:</strong></td><td   style="padding:2px"><input name="user" type=text class="blueish inp_ta" id="user" value="'+ e +'"/></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Password:</strong></td><td   style="padding:2px"><input name="pass" type=password class="blueish inp_ta" id="pass" value="'+ f +'"/></td></tr>';
		
		rs += '<tr ><td style="padding:2px" colspan=2 id="add_result"></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"></td><td><input type="button" name="submitBtn" class="sbtn" value="Update" onclick="updateUser('+ o_name + ');" /></td></tr>';
		
		rs += '</table></td></tr></table>';
	}
	
	
	if (o_name && !d) {
		
		rs = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="libraries/images/loading.gif" alt="Exit">&nbsp;</td><td><table border="0" cellspacing="0" cellpadding="2"  style="border:1px solid #000033" bgcolor="#C5E8F5"><tr><td colspan=2 height=21 width=90% class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033">&nbsp;<strong>Add New User</strong></td><td align=right class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033; padding:2px"><a onClick="fnUpdate();" style="cursor:pointer"><img src="libraries/images/exit.gif" alt="Exit"></a></td></tr><tr style="height:3px" ><td  colspan="2" ></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Name:</strong></td><td   style="padding:2px"><input name="username" type=text class="blueish inp_ta" id="username" /></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Login:</strong></td><td   style="padding:2px"><input name="user" type=text class="blueish inp_ta" id="user" /></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Password:</strong></td><td   style="padding:2px"><input name="pass" type=password class="blueish inp_ta" id="pass" /></td></tr>';
		
		rs += '<tr ><td style="padding:2px" colspan=2 id="add_result"></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"></td><td><input type="button" name="submitBtn" class="sbtn" value="Add" onclick="addUser('+ o_name + ');" /></td></tr>';
		
		rs += '</table></td></tr></table>';
	}
	
	if (o_name == '80xe45') {
		
		rs = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="libraries/images/loading.gif" alt="Exit">&nbsp;</td><td><table border="0" cellspacing="0" cellpadding="2"  style="border:1px solid #000033" bgcolor="#C5E8F5"><tr><td colspan=2 height=21 width=90% class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033">&nbsp;<strong>Add New Centre</strong></td><td align=right class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033; padding:2px"><a onClick="fnUpdate();" style="cursor:pointer"><img src="libraries/images/exit.gif" alt="Exit"></a></td></tr><tr style="height:3px" ><td  colspan="2" ></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Name:</strong></td><td   style="padding:2px"><input name="cname" type=text class="blueish inp_ta" id="cname" /></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Address:</strong></td><td   style="padding:2px"><input name="cadd" type=text class="blueish inp_ta" id="cadd" /></td></tr>';
		
		//rs += '<tr ><td align="right" style="padding:2px"><strong>Password:</strong></td><td   style="padding:2px"><input name="pass" type=password class="blueish inp_ta" id="pass" /></td></tr>';
		
		rs += '<tr ><td style="padding:2px" colspan=2 id="add_result"></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"></td><td><input type="button" name="submitBtn" class="sbtn" value="Add" onclick="addCtr();" /></td></tr>';
		
		rs += '</table></td></tr></table>';
	}
	
	if (o_name == 'schat') {
		
		rs = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/indicator.gif" alt="Exit">&nbsp;</td><td><table border="0" cellspacing="0" cellpadding="2"  style="border:1px solid #000033" bgcolor="#C5E8F5"><tr><td colspan=2 height=21 width=90% class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033">&nbsp;<strong>Chat with C.R.I.$.I.$</strong></td><td align=right class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033; padding:2px"><a onClick="fnUpdate();" style="cursor:pointer"><img src="libraries/images/exit.gif" alt="Exit"></a></td></tr><tr style="height:3px" ><td  colspan="2" ></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Name:</strong></td><td   style="padding:2px"><input name="cname" type=text class="blueish inp_ta" id="cname" /></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"><strong>Address:</strong></td><td   style="padding:2px"><input name="cadd" type=text class="blueish inp_ta" id="cadd" /></td></tr>';
		
		//rs += '<tr ><td align="right" style="padding:2px"><strong>Password:</strong></td><td   style="padding:2px"><input name="pass" type=password class="blueish inp_ta" id="pass" /></td></tr>';
		
		rs += '<tr ><td style="padding:2px" colspan=2 id="add_result"></td></tr>';
		
		rs += '<tr ><td align="right" style="padding:2px"></td><td><input type="button" name="submitBtn" class="sbtn" value="Add" onclick="addCtr();" /></td></tr>';
		
		rs += '</table></td></tr></table>';
	}
  

    if(ns4)

    {

      updateSTYLE.document.write(rs);

      updateSTYLE.document.close();

      updateSTYLE.visibility = "visible";

    }

    if(ns6)

    {

      document.getElementById("updateLayer").innerHTML = rs;

      updateSTYLE.display='block'

    }

    if(ie4)

    {
		
		 document.all("updateLayer").innerHTML = rs;
		 updateSTYLE.display='block';
			moveToMouseLoc(e);
    }
	

  }

}



function editCrop(c,i) {
	//showCropsMenu();
	var s = '<table width="100%" border="0" cellspacing="0" cellpadding="2" style="border:1px solid #797979;" background="libraries/images/n_secbg.jpg" ><tr ><td align=left style="padding:2px;" ><input type="text" name="edcp" id="edcp'+i+'" value="'+c+'" class=inp_stt> </td><td align=left><a onClick="updateCrop('+i+')" style="cursor:pointer"><img src="libraries/images/ok2.gif" alt="Update"></a></td><td align=left><a onClick="delCrop('+i+')" style="cursor:pointer"><img src="libraries/images/del_small.gif" alt="Delete"></a></td><td align=left><a onClick="hideCropMenu(\''+i+'\',\''+c+'\');" style="cursor:pointer"><img src=\"libraries/images/exit.gif\" alt="Cancel"></a></td></tr></table>';
	document.getElementById("mcp"+i).innerHTML = s;
	document.getElementById("edcp"+i).focus();	
}

function addFarmer(e) {
	showCropsSelect();	
	setTimeout(function(){addFarmer2(e)},200);
	
}
function addFarmer2(e) {
	var c = CropSelect();
	showLivestockSelect();
	setTimeout(function(){addFarmerN(e,c)},300);
}
var busy = '<br><div align=center><img src="libraries/images/loading.gif"><br>... please wait</div>';
function addFarmerN(e,c) {
	//showCropsMenu();	
	var cropOptions = c;
	document.getElementById("adds").innerHTML = busy;
	var livestockOptions = CropSelect();
	try {
		var vlg = document.getElementById("vlgs").options[document.getElementById("vlgs").selectedIndex].value ;
	}
	catch (Error) {
		alert('You must select a Village!');
		return false;
		
	}
	
	//var cropOptions = CropSelect();
	var pv = document.getElementById("provinces").options[document.getElementById("provinces").selectedIndex].value ;
	var ds = document.getElementById("districts").options[document.getElementById("districts").selectedIndex].value ;
	var blk = document.getElementById("blocks").options[document.getElementById("blocks").selectedIndex].value ;
	var cmp = document.getElementById("camps").options[document.getElementById("camps").selectedIndex].value ;
	var vlg = document.getElementById("vlgs").options[document.getElementById("vlgs").selectedIndex].value ;
	
	var s = '<br><table border="0" cellspacing="0" cellpadding="0" width="100%"><form action="index.php" method="post" name="addFmrl" id="addFmrz"><tr><td><table border="0" cellspacing="0" cellpadding="2"  style="border:1px solid #000033" bgcolor="#FFFFFF" width="100%"><tr><td height=30 align=left width=50% class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033">&nbsp;<strong>Add New Farmer</strong></td><td align=right class="b_s" background="libraries/images/n_secbg.jpg" style="border-bottom:1px solid #000033; padding:2px"><a onClick="extAdds();" style="cursor:pointer"><img src="libraries/images/exit.gif" alt="Exit"></a></td></tr>';
	// ENTRIES TABLE
	s += '<tr><td style="padding:20px" colspan=2><table border="0" cellspacing="0" cellpadding="0" width="80%" style="border:1px solid #000033" align=center><tr ><td colspan=2 height=25 style="padding:2px; border-bottom:1px solid #000033" background="libraries/images/n_secbg.jpg" align=left><strong>Details</strong></td></tr><tr ><td align="right" style="padding:2px"><strong>Surname:</strong></td><td   style="padding:2px"  align=left><input name="sname" type=text class="blueish inp_ta" id="sname" /></td></tr><tr ><td align="right" style="padding:2px"><strong>First Name(s):</strong></td><td   style="padding:2px"  align=left><input name="fname" type=text class="blueish inp_ta" id="fname" /></td></tr><tr ><td align="right" style="padding:2px"><strong>Date of Birth:</strong></td><td   style="padding:2px"  align=left><input name="dob" type=text class="blueish inp_ta" id="dob" /> (Format : YYYY-MM-DD)</td></tr><tr ><td align="right" style="padding:2px"><strong>Gender:</strong></td><td   style="padding:2px"  align=left><input name="sex" type=text class="blueish inp_ta" id="sex" /></td></tr><tr ><td align="right" style="padding:2px"><strong>National ID:</strong></td><td   style="padding:2px"  align=left><input name="nid" type=text class="blueish inp_ta" id="nid" /></td></tr><tr ><td align="right" style="padding:2px"><strong>Household Size:</strong></td><td   style="padding:2px"  align=left><input name="hsez" type=text class="blueish inp_ta" id="hsez" /></td></tr><tr ><td align="right" style="padding:2px"><strong>Farm Size(Ha):</strong></td><td   style="padding:2px"  align=left><input name="fsz" type=text class="blueish inp_ta" id="fsz" /></td></tr><tr ><td align="right" style="padding:2px"><strong>Major Enterprise:</strong></td><td   style="padding:2px"  align=left><input name="met" type=text class="blueish inp_ta" id="met" /></td></tr>';
	// CATEGORY OPTIONS
	s += '<tr ><td align="right" style="padding:2px"><strong>Category:</strong></td><td   style="padding:2px"  align=left><input name="fcat" type=radio value="1"';	
	if (e == 1 || addFarmerN.arguments.length == 0)
	s += ' checked';
	s += '/>Small-scale&nbsp;<input name="fcat" type=radio value="2"';
	if (e == 2)
	s += ' checked';
	s += '/>Medium-scale&nbsp;<input name="fcat" type=radio value="3"';
	if (e == 3)
	s += ' checked';
	s += '/>Large-scale</td></tr>';		
	
	//OPERATIONAL BUTTONS
	s += '<tr><td></td><td style="padding:2px;" align=left><table width="100" cellpadding="2" cellspacing="3"><tr><td align="center" valign="middle" background="libraries/images/n_secbg.jpg" style="padding-top:6px; padding-bottom:6px; border:1px solid #999999; padding-left:3px; padding-right:3px" width=50%><a style="cursor:pointer" onClick="addFmrDet();"><img src="libraries/images/ok2.gif" alt="Add Record" /></a></td> <td align="center" valign="middle" background="libraries/images/n_secbg.jpg" style="padding-top:6px; padding-bottom:6px; border:1px solid #999999; padding-left:3px; padding-right:3px"><a style="cursor:pointer" onClick="extAdds();"><img src="libraries/images/b_drop.png" alt="Cancel/Exit" /></a></td></tr></table></td></tr></table></td></tr>';
	/// CROP AND FRUIT PRODUCTION
	s += '<tr><td style="padding:20px" colspan=2><table border="0" cellspacing="1" cellpadding="0" width="80%" style="border:1px solid #000033" align=center><tr ><td colspan=4 height=25 style="padding:2px; border-bottom:1px solid #000033" background="libraries/images/n_secbg.jpg" align=left><strong>1. Crop & Fruit Production</strong></td></tr>';
	s += '<tr><td background="libraries/images/n_secbg.jpg">&nbsp;</td><td style="padding:2px"  align=center background="libraries/images/n_secbg.jpg"><strong>Crop</strong></td><td background="libraries/images/n_secbg.jpg"  style="padding:2px"  align=center><strong>Hectares</strong></td><td   style="padding:2px" background="libraries/images/n_secbg.jpg" align=center><strong>Average Yield</strong></td></tr>';
	for ( var i = 0; i < 16; i++ ) { 
	s += '<tr><td align=right>'+(i+1)+'.</td><td valign="bottom" style="padding-top:5px" align=left><select name="cp[]" class="blueish" id="cp'+i+'" onChange="addFmrCF(\'cp'+i+'\',1,'+i+',1);">'+cropOptions+'</select></td><td  valign="middle" style="padding:2px"  align=left><input name="cha[]" type=text class="blueish inp_ta" id="cha'+i+'" onFocusOut="addFmrCF(\'cha'+i+'\',1,'+i+',2);"/></td><td   style="padding:2px"  align=left><input name="cay[]" type=text class="blueish inp_ta" id="cay'+i+'" onFocusOut="addFmrCF(\'cay'+i+'\',1,'+i+',3);"/></td></tr>';
	}
	
	s += '</table></td></tr>';
	
	/// LIVESTOCK PRODUCTION
	s += '<tr><td style="padding:20px" colspan=2><table border="0" cellspacing="1" cellpadding="0" width="80%" style="border:1px solid #000033" align=center><tr ><td colspan=4 height=25 style="padding:2px; border-bottom:1px solid #000033" background="libraries/images/n_secbg.jpg" align=left><strong>2. Livestock Production</strong></td></tr>';
	s += '<tr><td background="libraries/images/n_secbg.jpg">&nbsp;</td><td   style="padding:2px"  align=center background="libraries/images/n_secbg.jpg"><strong>Livestock</strong></td><td background="libraries/images/n_secbg.jpg"  style="padding:2px"  align=center><strong>Numbers</strong></td><td   style="padding:2px" background="libraries/images/n_secbg.jpg" align=center><strong>Livestock Products</strong></td></tr>';
	for ( var i = 0; i < 16; i++ ) { 
	s += '<tr><td align=right>'+(i+1)+'.</td><td style="padding:2px"  align=left><select name="lv[]" class="blueish" id="lv'+i+'" onChange="addFmrCF(\'lv'+i+'\',2,'+i+',1);">'+livestockOptions+'</select></td><td   style="padding:2px"  align=left><input name="lvn[]" type=text class="blueish inp_ta" id="lvn'+i+'" onFocusOut="addFmrCF(\'lvn'+i+'\',2,'+i+',2);"/></td><td   style="padding:2px"  align=left><input name="lvp[]" type=text class="blueish inp_ta" id="lvp'+i+'" onFocusOut="addFmrCF(\'lvp'+i+'\',2,'+i+',3);"/></td></tr>';
	}
	
	s += '</table></td></tr>';
	
	/// FISH PRODUCTION
	s += '<tr><td style="padding:20px" colspan=2><table border="0" cellspacing="1" cellpadding="0" width="80%" style="border:1px solid #000033" align=center><tr ><td colspan=4 height=25 style="padding:2px; border-bottom:1px solid #000033" background="libraries/images/n_secbg.jpg" align=left><strong>3. Fish Production</strong></td></tr>';
	s += '<tr><td background="libraries/images/n_secbg.jpg">&nbsp;</td><td   style="padding:2px"  align=center background="libraries/images/n_secbg.jpg"><strong>Number</strong></td><td background="libraries/images/n_secbg.jpg"  style="padding:2px"  align=center><strong>Size Sq.M</strong></td><td   style="padding:2px" background="libraries/images/n_secbg.jpg" align=center><strong>Type of Fish</strong></td></tr>';
	// PONDS EXCAVATED 
	s += '<tr><td>Ponds Excavated</td> <td   style="padding:2px"  align=left><input name="fpen" type=text class="blueish inp_ta" id="fpen" size=15 onFocusOut="addFmrCF(\'fpen\',3);"/></td><td   style="padding:2px"  align=left><input name="fpsqm" type=text class="blueish inp_ta" id="fpsqm" size=15 onFocusOut="addFmrCF(\'fpsqm\',3);"/></td><td   style="padding:2px"  align=left><input name="fpft" type=text class="blueish inp_ta" id="fpft"  onFocusOut="addFmrCF(\'fpft\',3);"/></td></tr>';
	// PONDS STOCKED
	s += '<tr><td>Ponds Stocked</td> <td   style="padding:2px"  align=left><input name="fpsn" type=text class="blueish inp_ta" id="fpsn" size=15 onFocusOut="addFmrCF(\'fpsn\',3);"/></td><td   style="padding:2px"  align=left><input name="fpssqm" type=text class="blueish inp_ta" id="fpssqm" size=15 onFocusOut="addFmrCF(\'fpssqm\',3);"/></td><td   style="padding:2px"  align=left><input name="fpsft" type=text class="blueish inp_ta" id="fpsft" onFocusOut="addFmrCF(\'fpsft\',3);"/></td></tr>';
	
	//}
	
	s += '</table></td></tr>';
	
	/// EQUIPMENT USAGE
	s += '<tr><td style="padding:20px" colspan=2><table border="0" cellspacing="1" cellpadding="0" width="80%" style="border:1px solid #000033" align=center><tr ><td colspan=4 height=25 style="padding:2px; border-bottom:1px solid #000033" background="libraries/images/n_secbg.jpg" align=left><strong>4. Farm Equipment Used</strong></td></tr>';
	s += '<tr><td   style="padding:2px"  align=center background="libraries/images/n_secbg.jpg"><strong>Crop Production</strong></td><td background="libraries/images/n_secbg.jpg"  style="padding:2px"  align=center><strong>Dairy &amp; Beef</strong></td><td  style="padding:2px" background="libraries/images/n_secbg.jpg" align=center><strong>Poultry</strong></td><td  style="padding:2px" background="libraries/images/n_secbg.jpg" align=center><strong>Aquaculture</strong></td></tr>';
	for ( var i = 0; i < 16; i++ ) { 
	s += '<tr><td   style="padding:2px"  align=right>'+(i+1)+'.<input name="ecp[]" type=text class="blueish inp_ta" id="ecp'+i+'" size=15 onFocusOut="addFmrCF(\'ecp'+i+'\',4,'+i+',1);"/></td><td   style="padding:2px"  align=right>'+(i+1)+'.<input name="edb[]" type=text class="blueish inp_ta" id="edb'+i+'" size=15 onFocusOut="addFmrCF(\'edb'+i+'\',4,'+i+',2);"/></td><td   style="padding:2px"  align=right>'+(i+1)+'.<input name="ep[]" type=text class="blueish inp_ta" id="ep'+i+'" size=15 onFocusOut="addFmrCF(\'ep'+i+'\',4,'+i+',3);"/></td><td   style="padding:2px"  align=right>'+(i+1)+'.<input name="eaq[]" type=text class="blueish inp_ta" id="eaq'+i+'" size=15 onFocusOut="addFmrCF(\'eaq'+i+'\',4,'+i+',4);"/></td></tr>';
	}
	
	s += '</table></td></tr>';
	s += '<tr><td colspan=2  style="padding:2px"  align=center><input name="insertFM" type=button class="blueish inp_ta" value="DONE"  onClick="finAdd();"/></td></tr>';
	s += '</table><input name="pvi" type=hidden value="'+pv+'"/><input name="dsi" type=hidden value="'+ds+'"/><input name="bki" type=hidden value="'+blk+'"/><input name="cmpi" type=hidden value="'+cmp+'"/> <input name="vlgi" type=hidden value="'+vlg+'"/> <input name="lastid" type=hidden value="" id="lastid"/></td></tr></form></table>';
	
	
	
	setTimeout(function (){document.getElementById("adds").innerHTML = s},2000);
	//document.getElementById("edcp"+i).focus();	
}


function cfP() {
	
	if (confirm('Print the Record?')) {
		return true;
	} else {
		return false;
	}
	
}
function extAdds () {
	document.getElementById("adds").innerHTML = '';
	
}

function editLs(c,i) {
	//showCropsMenu();
	var s = '<table width="100%" border="0" cellspacing="0" cellpadding="2" style="border:1px solid #797979;" background="libraries/images/n_secbg.jpg" ><tr ><td align=left style="padding:2px;" ><input type="text" name="edls" id="edls'+i+'" value="'+c+'" class=inp_stt> </td><td align=left><a onClick="updateLs('+i+')" style="cursor:pointer"><img src="libraries/images/ok2.gif" alt="Update"></a></td><td align=left><a onClick="delLs('+i+')" style="cursor:pointer"><img src="libraries/images/del_small.gif" alt="Delete"></a></td><td align=left><a onClick="hideLsMenu(\''+i+'\',\''+c+'\');" style="cursor:pointer"><img src=\"libraries/images/exit.gif\" alt="Cancel"></a></td></tr></table>';
	document.getElementById("mls"+i).innerHTML = s;
	document.getElementById("edls"+i).focus();	
}

function hideCropMenu (e,s) {
	
	setTimeout(function(){if (document.getElementById("mcp"+e))document.getElementById("mcp"+e).innerHTML = '<div id="cp'+e+'" onClick="editCrop(\''+s+'\', \''+e+'\')\" >'+s+'</div>'}, 500);	
	
}

function hideLsMenu (e,s) {
	
	setTimeout(function(){if (document.getElementById("mls"+e))document.getElementById("mls"+e).innerHTML = '<div id="ls'+e+'" onClick="editLs(\''+s+'\', \''+e+'\')\" >'+s+'</div>'}, 500);	
	
}
function inittitle()

{

  if(ns4||ns6||ie4)

  {

    if(ns4) titleSTYLE = document.titleLayer;

    else if(ns6) titleSTYLE = document.getElementById("titleLayer").style;

    else if(ie4) titleSTYLE = document.all.titleLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else

    {

      titleSTYLE.visibility = "visible";

      titleSTYLE.display = "none";

    }

    //document.onmousedown = moveToMouseLoc;

  }

}

function updatetitle() 
{
	
	var ns = document.getElementById("q_t").value.split('\n');
	
	var title_c  = document.getElementById("q_t").value;
	
	for (g=0; g<ns.length;g++)
	{
		title_c  = title_c.replace('\n', '<br>') ;
	}
	title_c = title_c.toUpperCase();
	document.getElementById("q_title").innerHTML =  title_c ;
}

var site = window.location ;
var timeout = false;
function fntitle(stuff,tm) {
	
	var ns = document.getElementById("q_title").innerHTML.split('<BR>');
	
	var content  = document.getElementById("q_title").innerHTML;
	
	for (g=0; g<ns.length;g++)
	{
		content  = content.replace('<BR>', '\n') ;
	}
	
	if(fntitle.arguments.length < 1) // hide
  	{
		if(ns4) 
		{
			titleSTYLE.visibility = "hidden";
			titleSTYLE.document.write('');
		}
		
		else 
		{
			titleSTYLE.display = "none";			
			
			if(ns6)	
			{	
			  document.getElementById("titleLayer").innerHTML = '';		
			}
		
			if(ie4)	
			{			
				 document.all("titleLayer").innerHTML = '';
			}
		}
	}
  
	else // show	
	{		
		var rs = '<table border="0" cellspacing="0" cellpadding="0"  style="border: 2px solid #FFFFFF outset; padding:2px" bgcolor="#484848"><td>' +     ' <table width="100%" border="0" cellpadding="1" cellspacing="0"><tr bgcolor="#416992"><td colspan=2><table width="100%" border="0" cellpadding="0" cellspacing="0" ><td width=90% class="wyt_bld">Questionnare Title</td><td align=right><a onClick="fntitle();"><img src="libraries/images/close.png"></a></td></table></td></tr><tr style="height:3px" ><td  colspan="2" ></td></tr><tr ><td colspan="2"><textarea name="q_t" type=text class="blueish sml" onkeyup="updatetitle();" id="q_t" rows=5 onClick="if(this.value==\'Click here to type your questionnaire title\')this.value=\'\';" />'+ content +'</textarea></td></tr><tr style="height:5px" ><td  colspan="2" ></td></tr><tr ><td colspan=2 align=right bgcolor="#484848"><input onClick="fntitle();"  type="button" name="rename" value="Finished" class="inp_s"></td></tr></table></table>';

		if(ns4)
	
		{
	
		  titleSTYLE.document.write(rs);
	
		  titleSTYLE.document.close();
	
		  titleSTYLE.visibility = "visible";
	
		}
	
		if(ns6)
	
		{
	
		  document.getElementById("titleLayer").innerHTML = rs;
	
		  titleSTYLE.display='block'
	
		}
	
		if(ie4)
	
		{
			
			 document.all("titleLayer").innerHTML = rs;
			 titleSTYLE.display='block';
			 
			  if (!tm)
			  {
				 moveToMouseLoc();
			  }
			  
			 
		}
		
		document.getElementById("q_t").focus();
		document.getElementById("q_t").select();
	}
}

function toolTip(msg, fg, bg, tm)

{
	//var startTime = (new Date()).getTime();
	//var clear = startTime + 1000;
	
  if(toolTip.arguments.length < 1) // hide

  {

    if(ns4) toolTipSTYLE.visibility = "hidden";

    else toolTipSTYLE.display = "none";

  }

  else // show

  {

    if(!fg) fg = "#777777";

    if(!bg) bg = "#FFFFFF";

    var content = '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +     ' <table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + '"> <td align="justify"><font face="sans-serif" color="' + fg +'" size="2">&nbsp\;' + msg +'&nbsp\;</font></td></table></td></table>';

    if(ns4)

    {

      toolTipSTYLE.document.write(content);

      toolTipSTYLE.document.close();

      toolTipSTYLE.visibility = "visible";

    }

    if(ns6)

    {

      document.getElementById("toolTipLayer").innerHTML = content;

      toolTipSTYLE.display='block'

    }

    if(ie4)

    {
		
		 document.all("toolTipLayer").innerHTML = content;
		  toolTipSTYLE.display='block';
		 
    }

  }

}

function Point(x,y) { this.x = x; this.y = y; }
var mouseLocation = new Point(-500,-500);

function moveToMouseLoc()

{

  
  var mx;
  var my = 90;
  if(ns4||ns6)

  {

    mouseLocation.x = e.pageX;

    mouseLocation.y = e.pageY;

  }

  else

  {

    mouseLocation.x = ie4 ? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX

    mouseLocation.y = ie4 ? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY;

  }
  
	mx = 20;
	

  updateSTYLE.left = mouseLocation.x + offsetX + mx;

  updateSTYLE.top = mouseLocation.y + offsetY - my;

  return true;

}

function inithistoryShow()

{

  if(ns4||ns6||ie4)

  {

    if(ns4) historyShowSTYLE = document.historyLayer;

    else if(ns6) historyShowSTYLE = document.getElementById("historyLayer").style;

    else if(ie4) historyShowSTYLE = document.all.historyLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else

    {

      historyShowSTYLE.visibility = "visible";

      historyShowSTYLE.display = "none";

    }

   //document.onmousemove = moveToMouseLoc;

  }

}

function createlist(stuff) {

//return  stuff +"\n";

return "<a style='cursor:arrow;color:#000000' onmouseover='this.style.background=\"#1C2D3E\";this.style.color=\"#FFFFFF\"' onmouseout='this.style.background=\"\";this.style.color=\"#000000\"' onClick=" + "\"addtolist('" + stuff + "');\" style='width:100%;border-bottom:1px solid #8DACCB;color:#484848'>" + stuff.charAt(0).toUpperCase() + stuff.substring(1, stuff.length) +"</a><br>";
//return "<option value="+ content +">"+ content + "</option>\n";

}


 
var newWindow;

function loadup (file) {
	
if (file != '')
{
	if (confirm('Sorry, this feature is not curently installed here\nThe feature will allow you to pack(share) project data\nand structure to other computers\n\nWould you like to add this option?'))
	{
		window.alert('Please contact support for ordering this option.');	
	}
//location = "exportself.php?n="+ file +"";
}
else
window.alert(p_err);
//----------if (newWindow){
//--------------''if (!newWindow.closed) newWindow.close();
//-----//}
//-----newWindow = window.open("lup.php?n="+ file ,"LoadData","toolbar=no,location=no,directories=no,status=no,menubar=no,height=200,width=300");
//-------------newWindow.focus( );
}

var newviewWindow;

function viewfile (file,t,w,o) {
if (newviewWindow){
if (!newviewWindow.closed) newviewWindow.close();
}
newviewWindow = window.open("view.php?v="+ file + "&t=" + t + "&w="+ w + "&tmp="+ o,"ViewFiles","toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,height=500,width=650");
newviewWindow.focus( );
}

var rdWindow;

function rename_Dup (file) {
if (rdWindow){
if (!rdWindow.closed) rdWindow.close();
}
rdWindow = window.open("rename.php?n="+ file,"RenameDuplicate","toolbar=no,location=no,directories=no,status=no,menubar=no,height=200,width=300");
rdWindow.focus( );
}

var p_err  = 'Project has Errors\n\nIt was either aborted on creation or has developed serious erros.\nDelete it or contact support if this problem persists.';	

function dp(file) {
if (file != '')
	if(confirm('Are you sure you want to:\n\n DELETE PROJECT: `' + file + '` ?')) 
		location = window.location +"?dp="+ file +"";
		
	else
		return false;
else
window.alert(p_err);
}  

function eTo(file) {  		
if (file != '')
location = "eproject.php?n="+ file +"";
else
window.alert(p_err);
}  


function addtolist (content,sc) {

	//var list = document.code.hs;
	//var listText = list.options[list.selectedIndex].text;
	
	//if (sc) 
	//{
	//	content = listText;
	//	document.getElementById("t1").value;
	//}
	
	var stuff = document.getElementById("t1").value;
	
	if (stuff.indexOf(content) == -1) 
	{
		if (stuff.length < 3)
		{
			document.getElementById("t1").value = content;
		}
		else
		{
			if (stuff.indexOf(' ') != -1) 
			{
				var d = stuff.split(' ');
				
				if (d.length > 1)
				{
					var lg = d.length-1;
					if (typeof(d[lg]) != 'undefined')
					{
						if (d[lg].length < 3)
						{
							document.getElementById("t1").value = stuff.substring(0,stuff.length-2)+' ' + content ;
						}
						else
						{
							document.getElementById("t1").value = stuff +' ' + content;
						}
					}
				}
			}
		}
	} 
	else 
	{	
		if (stuff == content)
		document.getElementById("t1").value = stuff.replace(content, '')
		else
		document.getElementById("t1").value = stuff.replace(' '+ content, '') ;
	}
	
	// historyShow(2);
	document.getElementById("t1").focus();
	
}


function addtolistB (content,sc) {

	var stuff = document.getElementById("t1").value;
	
	if (stuff.indexOf(content) == -1) 
	{
		if (stuff.length < 2)
		{
			document.getElementById("t1").value = content;
		}
		else
		{
			document.getElementById("t1").value = stuff+ ' ' +content;
		}		
	} 
	else 
	{	
		if (stuff == content)
		document.getElementById("t1").value = stuff.replace(content, '')
		else
		document.getElementById("t1").value = stuff.replace(' '+ content, '') ;
	}
	
	// historyShow(2);
	//document.getElementById("t1").focus();
	
}

function acc (content) {

	var accp = document.getElementById("qcd").value;
	
	if(content == 0) {
		document.getElementById("qcd").value = 50 ;
	}
	else if(content == 'l') {
		document.getElementById("qcd").value = 80 ;
	}
	else if(content == 'h') {
		document.getElementById("qcd").value = 70 ;
	}
	else if(content == 'm'){
		if (accp == 0)
			alert('Minimum Limit is 0%!');
		else
			document.getElementById("qcd").value = +accp-5 ;
	}
	else if(content == 'p'){
		if (document.getElementById("sim2") && document.getElementById("sim2").checked == true && accp == 95)
			alert('100% Disimilarity is Zero!');
		else if (accp == 100)
			alert('Maximum Limit is 100%!');
		else
			document.getElementById("qcd").value = +accp+5 ;
	}
	else {
		document.getElementById("qcd").value = content ;
	}
	textCounter(document.getElementById("qcd"),'progressbar1',100);
}


function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	
	var fieldWidth =  150;
	var charcnt = field.value.length;  
	var char = field.value; 
	var unique_id;
    var checkbox;

    // trim the extra text
	if (char > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = char;
	var pcnt = parseInt(100 - (( maxlimit - char) * 100)/maxlimit) ;
	//var text = '/ <?php //echo $totalRows_ana_qs ; ?> Entered';
	document.getElementById(counter).style.width =  parseInt((fieldWidth*pcnt)/100)+"px";
	document.getElementById(counter).innerHTML=""+percentage+"%";
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),pcnt,"background-color");
	//}
	
	
	 }
}
function setcolor(obj,pcnt,prop){
	obj.style[prop] = "rgb(80%,"+(100-pcnt)+"%,"+(100-pcnt)+"%)";
}

function emp(file) {  		
if (file != '')
	if(confirm('Are you sure you want to:\n\n EMPTY DATA IN PROJECT: `' + file + '` ?')) 
		location = window.location +"?d="+ file +"";
	else
		return false;
else
window.alert(p_err);
}

var w_text = "WARNING: This change will affect the questionnare code sequence!\n\nWe recommend you make this change before the final questionnare\n is set and field data is collected\n\n(Note: Check the `Turn Off Warnings` checkbox to remove\n this warning in future.)\n----------------------------------------------------------------------\n\n";

function move_q (from, to) {
var warning = ""; 
var kw = "1";

	if (document.getElementById('warn').checked == false ) {
	warning = w_text;
	kw = "";
	}
	

if (from != '' && to != '')
	if(confirm(warning +'Are you sure you want to:\n\nMOVE QUESTION `' + from + '` TO `' + to + '` ?'))  
		location = "eproject.php?frm="+from+"&to="+to+"&w=" + kw +"";
	else
	return false;
else
window.alert('There is an error in question numbers!');

}

function typ_q (id,format) {
var warning = ""; 
var text ;

	if (document.getElementById('warn').checked == false ) {
	warning = w_text;
	}
	
	if (format == 1 ) {
	text = "Single Choice Format ?";
	}
	else if (format == 2 ) {
	text = "Text Format ?";
	}
	else if (format == 3 ) {
	text = "Ranked Format ?";
	}
	else if (format == 4 ) {
	text = "Multiple Choice Format ?";
	}
	else if (format == 5 ) {
	text = "List Choice Format ?";
	}
	else {
	text = "Undefined Format ?";	
	}
	

if (id != '')
	if(confirm(warning +'Are you sure you want to:\n\nCHANGE QUESTION `'+ id +'` TO `' + text + '`'))  
		return true;
	else
	return false;
else
window.alert('There is an error in question numbers!');

}

function delq (file,num) {
var warning = ""; 
var text ;

	if (document.getElementById('warn').checked == false ) {
	warning = w_text;
	}
	
	
	if (file != '')
	{
		if(confirm(warning +'Are you sure you want to:\n\nDELETE QUESTION `'+ num +'` FROM `' + file + '`?')) 
		{
			location = "eproject.php?dq="+num;
		}
		else
		{
			return false;
		}
	}
	else
	{
		window.alert('There is an error in question numbers!');
	}

}

	
function ch_gp (q,cg,t) {
var warning = ""; 
var ngs = document.getElementById('chg_gps' + q);
var ng = ngs.options[ngs.selectedIndex].value.split("|");
var g_text = "";

	if (document.getElementById('warn').checked == false ) 
	{
		warning = w_text;
	}
	
	if (typeof(ng[1]) != 'undefined')
	{
		g_text = ' (' + ng[1] +')';	
	}
	
	if (cg != '' && q != '')
	{
		if(confirm(warning +'Are you sure you want to:\n\nMOVE QUESTION `'+ q +'` FROM GROUP `' + cg.toUpperCase() + '` TO GROUP `' + ng[0].toUpperCase() +''+ g_text.toUpperCase() + '` ?')) 
		{
			location = "eproject.php?m_g=" + cg + "&tg=" + ng[0] + "&m_q=" + q + "&m_qt=" + t;
		}
		else
		{
			return false;
		}
	}
	else
	{
		window.alert('There is an error in question numbers!');
		return false;
	}

}


function M_gp () {
var warning = ""; 
var s_gp = document.getElementById("m_tg");
var m_t = s_gp.options[s_gp.selectedIndex].value.split("|");

	location = window.location +"?ng="+ m_t[0];	

}

var marked_row = new Array;

function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }
	document.code.an.checked = true;
	autonumber();
	document.code.qcd.focus();
    return true;
}

function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }
	document.code.an.checked = false;
	autonumber()
	document.code.qcd.focus();
    return true;
}

function keepdata() {
	if (document.getElementById('kan'))
							
		if (document.getElementById('keep').checked == true ) 

			document.getElementById('kan').value = 1;

			else 

			document.getElementById('kan').value = '';

}

var arrGp = new Array(0);
var arrGpValue = new Array(0);
var arrAbValue = new Array(0);
var ta = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z');


