function hideLogin() {
    document.getElementById('login').style.visibility='hidden';
}

function getObjectClass(obj) {  
     if (obj && obj.constructor && obj.constructor.toString) {  
         var arr = obj.constructor.toString().match(  
             /function\s*(\w+)/);  
   
         if (arr && arr.length == 2) {  
             return arr[1];  
         }  
     }  
   
     return undefined;  
}  

function prepareRSS(chk) {
    var c = getCheckedValue(chk);
    showRSS(c);
    return false;
}

function showLightbox(arr) {
    tb_show(arr['title'], arr['href'] + '&TB_iframe=true&height=' + arr['height'] + '&width=' + arr['width']);
}

function webdavShowHow() {
    showLightbox({href: 'page.php?pt=webdav', 'title': 'Manage Files', 'width': 615, 'height': 480});
}

function importContacts(which) {
    showLightbox({href: '/getcontacts/importscript.php?datr_redir=' + escape(which), 'title': 'Import Contacts', 'width': 615, 'height': 580});
}

function showRSS(c) {
    return window.open('page.php?pt=_rss&c=' + c);
}

function playMedia() {
    showLightbox({href: 'page.php?pt=_player', 'title': 'Play Media', 'width': 715, 'height': 380});
}

function uploadFilesToFolder(folder) {
    showLightbox({href: 'page.php?pt=_newfile&folder=' + escape(folder), 'title': 'Upload', 'width': 400, 'height': 400});
}

function uploadFilesToGroup(group) {
    showLightbox({href: 'page.php?pt=_newfile&group=' + escape(group), 'title': 'Upload', 'width': 400, 'height': 250});
}

function send2phone(id) {
    showLightbox({href: 'page.php?pt=phonefile&file=' + escape(id), 'title': 'Send to phone', 'width': 500, 'height': 250});
}

function linkFile(id) {
    showLightbox({href: 'page.php?pt=getlink&file=' + escape(id), 'title': 'Link File', 'width': 500, 'height': 100});
}

function showProps(id) {
    showLightbox({href: 'page.php?pt=fileprops&id=' + escape(id), 'title': 'Properties', 'width': 400, 'height': 250});
}

function shareFile(chk) {
    var c = getCheckedValue(chk);
    shareFileGo(c);
    return false;
}

function sendForSignature(c) {
    showLightbox({href: 'page.php?pt=_signfile&c=' + c, 'title': 'Send for digital signature', 'width': 400, 'height': 250});
}

function shareFileGo(c) {
    showLightbox({href: 'page.php?pt=_sendfile&c=' + c, 'title': 'Share File', 'width': 800, 'height': 445});
}

function updateAllChecks(ch, how) {
    if (ch) {
        if (ch.length) {
            for (var i = 0; i < ch.length; i++) {
                ch[i].checked = how && !ch[i].disabled;
            }
        } else {
            ch.checked = how && !ch.disabled;
        }
    }
}

function toggleVisibility(id, NNtype, IEtype, WC3type) {
    if (document.getElementById) {
        eval("document.getElementById(id).style.visibility = \"" + WC3type + "\"");
    } else {
        if (document.layers) {
            document.layers[id].visibility = NNtype;
        } else {
            if (document.all) {
                eval("document.all." + id + ".style.visibility = \"" + IEtype + "\"");
            }
        }
    }
}

function errorOut(msg, fld) {
    alert(msg);
    fld.focus();
    return false;
}

function getCheckedValue(radioObj) {
    var ret_val = '';
    if (radioObj) {
        var radioLength = radioObj.length;
	if(radioLength == undefined) {
            if(radioObj.checked) ret_val = radioObj.value;
        } else {
            for(var i = 0; i < radioLength; i++) {
                if (radioObj[i].checked) ret_val = ret_val + ',' + radioObj[i].value;
            }
            if (ret_val != '') ret_val = ret_val.substring(1);
        }
    }
    return ret_val;
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

function updateRankImg(over,num,tot) {
    if (over) {
        selectTill(num);
    } else {
        selectTill(tot);
    }
}

function selectTill(what) {
    for (var i = 1; i <= what; i++) {
        document.getElementById('rank_' + i).src = 'images/star_sm.gif';
    }
    for (var i = what + 1; i <= 5; i++) {
        document.getElementById('rank_' + i).src = 'images/star_sm_bg.gif';
    }
}

function rateIt(what) {
    document.forms['formrate'].rating.value = what;
    document.forms['formrate'].submit();
}

function generateLink(frm) {
    var val = getCheckedValue(frm['chk[]']);
    var arr = val.split(",");
    val = arr[0].substring(1);
    if (val == '') {
        alert('No file selected.');
        return false;
    }
    document.getElementById('link_area').value = '<a href="http://www.datr.ws/page.php?pt=showfile&file=' + val + '">Download</a>';
}




function launchChat() {
    window.open('http://www.tagr.mobi/b/web/edchat.jsp?t=' + new Date(), 'chatwin', 'toolbar=0,status=0,menubar=0,resizable=1,width=300,height=400');
    return false;
}

