/* CHECK FUNCTIONS */

function check_data_length(form_name, input_name, alert_desc)
{
	if(document.forms[form_name].elements[input_name].value.length == 0)
	{
		alert(alert_desc);
		return false;
	}
	else return true;
}


function check_data_length_id(input_name, alert_desc)
{
	if(document.getElementById(input_name).value.length == 0)
	{
		alert(alert_desc);
		return false;
	}
	else return true;
}


/* WINDOW FUNCTIONS */
var win1;

function open_window(link_url, w, h, window_name, conf)
{
	l = (screen.availWidth - w) / 2;
	t = (screen.availHeight - h) / 2;
	win1 = window.open(link_url, window_name, 'width=' + w + ', height=' + h + ', left=' + l + ', top=' + t + conf).focus();
	return win1;
}

/* DISPLAY FUNCTIONS */
function show_element(element_id)
{
	if(navigator.appName=='Netscape')
		d='table-row';
	else
		d='block';
	document.getElementById(element_id).style.display = d;
}

function hide_element(element_id)
{
	document.getElementById(element_id).style.display = 'none';
}

function display_action(element_id)
{
	if(document.getElementById(element_id).style.display == 'none')
		show_element(element_id);
	else	hide_element(element_id);
}

function change_image(element_id, img_new)
{
	document.getElementById(element_id).src = img_new;
}

function check_display_status(element_id)
{
	if(document.getElementById(element_id).style.display == 'none') return 0;
	else return 1;
}

function get_pos(elemid)
{
	var elem = document.getElementById(elemid);
	var elemx = 0;
	var elemy = 0;

	while(elem)
	{
		elemx += elem.offsetLeft;
		elemy += elem.offsetTop;
		elem = elem.offsetParent;
	}
	if(navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftmargin != 'undefined')
	{
		elemx += document.body.leftMargin;
		elemy += document.body.topMargin;
	}
	return {elem_left:elemx, elem_top:elemy};
}

function set_global_lang(lang)
{
	document.forms['form_main'].elements['global_do'].value = 'set_global_lang';
	document.forms['form_main'].elements['global_lang'].value = lang;
	document.forms['form_main'].submit();
}


// COLOR FUNCTIONS
function rgb2cmy(r, g, b)
{
// 	c_val = (1 - (r / 255)) * 255;
// 	m_val = (1 - (g / 255)) * 255;
// 	y_val = (1 - (b / 255)) * 255;
	
	c_val = (1 - (r / 255)) * 100;
	m_val = (1 - (g / 255)) * 100;
	y_val = (1 - (b / 255)) * 100;

	c_val2 = Math.round(c_val * 10);
	m_val2 = Math.round(m_val * 10);
	y_val2 = Math.round(y_val * 10);

	return {c:(c_val2 / 10), m:(m_val2 / 10), y:(y_val2 / 10)};
}

function normalize255(val)
{
	return (val / 255);
}

function normalize100(val)
{
	return (val / 100);
}

function cmy2rgb(c1, m1, y1)
{
// 	c2 = normalize255(c1);
// 	m2 = normalize255(m1);
// 	y2 = normalize255(y1);
 
	c2 = normalize100(c1);
	m2 = normalize100(m1);
	y2 = normalize100(y1);

	r_val = (1 - c2) * 255;
	g_val = (1 - m2) * 255;
	b_val = (1 - y2) * 255;

	return {r:Math.round(r_val), g:Math.round(g_val), b:Math.round(b_val)};
}

function dec2hex_255(dec)
{
	conv_tbl = new Array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff');
	return conv_tbl[dec];
}

function rgb2hex(r, g, b)
{
	hex = '#' + dec2hex_255(r) + dec2hex_255(g) + dec2hex_255(b);
	return hex;
}


//  GO TO FUNCTIONS
function go_to(url)
{
	document.location.href = url;
}

function getPageSize()	// Core code from - quirksmode.org
{
	var xScroll, yScroll;
	var windowWidth, windowHeight, pageWidth, pageHeight;

	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
}	


