// Global Verify -- use : id="required bla bla bla"
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.id.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.id.substring(8,30);
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
return true;
}

// Delete Confirmation 
function confirmDelete()
{
var agree=confirm("Are you sure you wish to Delete?");
if (agree)
	return true ;
else
	return false ;
}

// Open PopUp Window Center Using : Onclick="openCenterWin("../../index.html",300,300)"
function openCenterWin(url,theWidth,theHeight){

var theTop=(screen.height/2)-(theHeight/2)
var theLeft=(screen.width/2)-(theWidth/2)
var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",scrollbars=yes";
theWin=window.open(url,'',features)
}

function addcat() {
    var category = window.prompt('Enter new category', '');
    if (category != null && category != '') {
		if (arguments.length > 0) {
			window.location.href = 'script.php?action=add&jenis=2&name=' + encodeURIComponent(category);
		} else {
			window.location.href = 'script.php?action=add&jenis=1&name=' + encodeURIComponent(category);
		}
        return true;
    } else {
        return false;
    }
}
function editcat(elem, jenis, action) {
    var opt = document.getElementById(elem);
	indkat = jenis == 1 ? 'Category' : 'Industry';
    if (opt.options[opt.selectedIndex].value != 0) {
        if (action == 'edit') {
            var category = window.prompt('Edit '+indkat, opt.options[opt.selectedIndex].text);
            if (category != null && category != '' && category != opt.options[opt.selectedIndex].text) {
                window.location.href = 'script.php?action=edit&jenis='+jenis+'&id=' + opt.options[opt.selectedIndex].value + '&name=' + encodeURIComponent(category);
                return true;
            } else {
                return false;
            }
        } else if (action == 'del') {
            if (window.confirm('Are your sure want to delete ' + opt.options[opt.selectedIndex].text + '?\nAll '+indkat+' in this category will be deleted')) {
                window.location.href = 'script.php?action=del&jenis='+jenis+'&id=' + opt.options[opt.selectedIndex].value + '&name=' + encodeURIComponent(opt.options[opt.selectedIndex].text);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}
