function refresh_events() {

}

function refresh_dcl() {
}

function refresh_project_tracker() {

}


function display_loading() {
	document.body.style.cursor = "wait";
	//set status div width = width of the window
	document.getElementById('status').style.width = (document.getElementById('content').offsetWidth+10)+'px';
	
	//set status div width = height of the content 
	document.getElementById('status').style.height = (document.getElementById('content').offsetHeight)+'px';
	
	var Yscroll = (document.all)?document.documentElement.scrollTop:window.pageYOffset;
	
	//move loading message depending on scroll  
	document.getElementById('status_message').style.marginTop = Yscroll+"px";
	
	//alert(test_test);
	
	//IE hack : hide select element
	var elem=document.getElementsByTagName('select');
	for(i=0;i<elem.length;i++)
		elem[i].style.visibility = "hidden";
	
	//display status content
	document.getElementById("status").style.display = "block";
}

function hide_loading() {
	var elem=document.getElementsByTagName('select');
	for(i=0;i<elem.length;i++)
		elem[i].style.visibility = "visible";
	document.getElementById("status").style.display = "none";
	document.body.style.cursor = "auto";
}

function prepareData() {
	//with the id_list, we retrieve all the data and serialize it
	var data = '';
	for(var i=0; i<id_list.length; i++) {
		if(isNaN(id_list[i])) {
			if(eval('document.getElementById(\''+id_list[i]+'\').value') != '')
				data += id_list[i]+'('+eval('document.getElementById(\''+id_list[i]+'\').value')+')**';
		} else {
			if(eval('document.getElementById(\'field_'+id_list[i]+'\').value') != '')
				data += id_list[i]+'('+eval('document.getElementById(\'field_'+id_list[i]+'\').value')+')**';
		}
	}
	data = data.substr(0, data.length-2);
	return data;
}

function prepareDetData() {
	//with the id_list, we retrieve all the data and serialize it
	var data = '';
	for(var i=0; i<id_list.length; i++) {
		if(isNaN(id_list[i])) {
			if(eval('document.getElementById(\''+id_list[i]+'\').value') != '')
				data += id_list[i]+'(!'+eval('document.getElementById(\''+id_list[i]+'\').value')+'!)**';
		} else {
			if(eval('document.getElementById(\'field_'+id_list[i]+'\').value') != '')
				data += id_list[i]+'(!'+eval('document.getElementById(\'field_'+id_list[i]+'\').value')+'!)**';
		}
	}
	data = data.substr(0, data.length-2);
	return data;
}


function count_lines(strtocount, cols) {
    var rows = 0;
    var start_line = 0;
    var end_line = 0;
    var c_line = "";
    while ( true ) {
    	//first get end of line position
        end_line = strtocount.indexOf("\n", end_line+1);
        rows ++;
        if ( end_line == -1 ) break;
        c_line = strtocount.substring(start_line, end_line);
        //alert(c_line);
        //alert(Math.round(c_line.length / (cols-1)));
        rows = rows + Math.round(c_line.length / (cols-1));
		start_line = end_line;
    }
    if(rows == 0)
    	rows = 1;
    return rows;
}

function do_action(param) {
	var sep_pos = param.indexOf(',', 0);
	var url = param.substring(0, sep_pos);
	var win = param.substr(sep_pos+1, param.length);
	if(win=='self') {
		document.location.href = url;
	} else {
		var c_date = new Date();
		window.open(url, "popup"+c_date.getTime(), "directories=no, location=no, menubar=no, resizable= yes, scrollbars=yes, status=yes, toolbar=no, width=900, height=500");
	}
}

function add_new_contact() {
	var grp_select = document.getElementById('grp_contact_id');
	if(grp_select.options[grp_select.selectedIndex].value == 0) {
		alert('Please select a group of contact first');
	} else {
		url = 'index.php?todo=contact_quick_add&sheet_id='+grp_select.options[grp_select.selectedIndex].value;
		param = url+',popup';
		do_action(param);
	}
}


//COOKIE FUNCTION

function createCookie(name,value,days){	if (days)	{		var date = new Date();		date.setTime(date.getTime()+(days*24*60*60*1000));		var expires = "; expires="+date.toGMTString();	}	else var expires = "";	document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){	var nameEQ = name + "=";	var ca = document.cookie.split(';');	for(var i=0;i < ca.length;i++)	{		var c = ca[i];		while (c.charAt(0)==' ') c = c.substring(1,c.length);		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);	}	return null;}function eraseCookie(name){	createCookie(name,"",-1);}