// JavaScript Document


function allcheck(obj,main){
    for(var i=0; i < obj.elements.length ; i++){
        if(main.checked==true){
            obj[i].checked=true;
        }else{
            obj[i].checked=false;
        }
    }
}



function number_format (number, decimals, dec_point, thousands_sep) {
    var exponent = "";
    var numberstr = number.toString ();
    var eindex = numberstr.indexOf ("e");
    if (eindex > -1) {
        exponent = numberstr.substring (eindex);
        number = parseFloat (numberstr.substring (0, eindex));
    }
    if (decimals != null) {
        var temp = Math.pow (10, decimals);
        number = Math.round (number * temp) / temp;
    }
    var sign = number < 0 ? "-" : "";
    var integer = (number > 0 ?
        Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
    var fractional = number.toString ().substring (integer.length + sign.length);
    dec_point = dec_point != null ? dec_point : ".";
    fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
    if (decimals != null && decimals > 0) {
        for (i = fractional.length - 1, z = decimals; i < z; ++i) {
            fractional += "0";
        }
    }
    thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
    if (thousands_sep != null && thousands_sep != "") {
        for (i = integer.length - 3; i > 0; i -= 3){
            integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
        }
    }
    return sign + integer + fractional + exponent;
}

function maxsize(url,id){
    newwin=window.open(url,'fullsize'+id, 'width='+screen.width+', top=0, left=0, height='+screen.height+', fullscreen=yes, location=0');
    if (window.focus){
        newwin.focus();
    }
    return false;
}




function delc(obj){
    var status=false;
    for(var i=0 ; i < obj.elements.length ; i++ ){
        if(obj[i].name=='del[]'){
            if(obj[i].checked==true){
                status=true;
            }
        }
    }
    if(status==false){
        alert('Warning!!!\n\nPlease select at least one item to delete!!!                                 ');
        return false;
    }else{
        if(confirm('Warning!!!\n\n Confirm Press OK, Cancel Press Cancel.            ')){
            return true;
        }else{
            return false;
        }
    }
}


function delc_str(obj, var_str){
    var status=false;
    for(var i=0 ; i < obj.elements.length ; i++ ){
        if(obj[i].name=='del[]'){
            if(obj[i].checked==true){
                status=true;
            }
        }
    }
    if(status==false){
        alert('Warning!!!\n\nPlease select at least one item to delete!!!                                 ');
        return false;
    }else{
        if(confirm('Warning!!!\n\n '+var_str)){
            return true;
        }else{
            return false;
        }
    }
}




function newwin(URLStr,width, height, usescrollbar,resize)
{
    var popUpWin=0;
    var left = (screen.width/2) - width/2;
    var top = (screen.height/2) - height/2;
    if(popUpWin)
    {
        if(!popUpWin.closed) popUpWin.close();
    }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=0,location=0,directories=0,status=0,menub ar=0,scrollbars='+usescrollbar+',resizable='+resize+',copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function isEmail(email){ 
	
	
    var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
    if (!emailRE.test(email)){
        return false;
    }else{
        return true;
    }

}
function isUrl(s) {
    var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    return regexp.test(s);
}

function insertAtCursor(myField, myValue) {
    //IE support
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+myValue+myField.value.substring(endPos, myField.value.length);
    } else {
        myField.value += myValue;
    }
}


