// JavaScript Document
function funcConfDelete(url,txt){
	var agree=confirm(txt);
	if (agree){
		window.location.href=""+url+"";
		return true;
	}else{
		return false;
	}
}

function SelectEditcate(path,catid){
	//alert(catid);
	location.href=path+"&tab=editcat&catid="+catid;
}


function SelectDelcate(path,catid){
	//alert(catid);
	location.href=path+"&tab=delcat&catid="+catid;
}

function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}

function removeRowFromTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

/*add row table*/
// Last updated 2006-02-21
function addRowToTable()
{
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);
  
  // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'name[' + iteration+']';
  el.id = 'name[' + iteration+']';
  el.size = 30;
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);
  
  var cellRight2 = row.insertCell(2);
  var el2 = document.createElement('input');
  el2.type = 'text';
  el2.name = 'value[' + iteration+']';
  el2.id = 'value[' + iteration+']';
  el2.size = 20;
  el2.onkeypress = keyPressTest;
  cellRight2.appendChild(el2);
  
  // select cell
}

/*add row table*/
// Last updated 2010-01-13
function addRowToTableImage()
{
  var tbl = document.getElementById('tblProduct');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // left cell
  var cellLeft = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellLeft.appendChild(textNode);
  
  // right cell
 // right cell
  var cellRight = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'file';
  el.name = 'image' + iteration;
  el.id = 'image' + iteration;
  el.size = 30;
  el.onkeypress = keyPressTest;
  cellRight.appendChild(el);
  
}
function removeRowFromTableImage()
{
  var tbl = document.getElementById('tblProduct');
  var lastRow = tbl.rows.length;
  if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

function valid_site(form) {
   f = form;
   

   for(var i=0;i<f.elements.length;i++){
       if (f.elements[i].type!="text"){
           continue;
       }
       t = f.elements[i].value;

       if((t == null || t.length == 0) && (f.elements[i].name != "asin") && (f.elements[i].name != "model") && (f.elements[i].name != "pur_limit") && (f.elements[i].name != "salep") && (f.elements[i].name != "saleend")){
           var et = f.elements[i].getAttribute("errortext");
           alert(et);
           f.elements[i].focus();
           return false;
       }
   }
   
   var catcheck = f.category_wanted.value;
   if (catcheck == 0){
      var et = f.category_wanted.getAttribute("errortext");
           alert(et);
           f.category_wanted.focus();
           return false;
   }
return true;
}