/*
	Common data
*/
var defaultBankCode			= '0200';
var defaultCurrencyCode		= 'SKK';
var newDefaultCurrencyCode	= 'EUR';


/*
	Common methods used by more then 1 modules
*/

//================================================
// Validation control
//================================================
function common_ValidationOff(element)
{
	if (element == null) return;	
	element.setAttribute("SkipValidation", "true");
}

function common_ValidationOn(element)
{
	if (element == null) return;
	element.removeAttribute("SkipValidation");
}

function common_ValidationOnOff(element, ison)
{
	if (element == null) return;
	if(ison)
		common_ValidationOn(element);
	else
		common_ValidationOff(element);
}

//================================================
// Show/Hide control
//================================================
function common_Display(element, isvisible)
{
	if (element == null) return;
	if(isvisible)
		element.style.display = "";
	else
		element.style.display = "none"
}

//================================================
// Make's field readonly
//================================================
function common_Readonly(element, state){
	if (element == null) return;
	element.readOnly = (state) ? true : false;
	if (state) {
		if (element.className != null) element.oldstyle = element.className;
		element.className = "readonly";				
	} else {
		if ( element.oldstyle != null) element.className = element.oldstyle;
	}
}

//================================================
// Set's value of some element
//================================================
function common_SetValue(element,value){
	if (element == null) return;
	switch(element.nodeName){
		case "INPUT":	
			if( !element.disabled ) element.value = value;
			break;
		case "SELECT":  
			if( !element.disabled ) element.selectedIndex = value;				
			break
		default:		
			break;
	}
}

//================================================
// Enable's/disable's field
//================================================
function common_EnableById(state,elementId)
{
	common_Enable(state, document.getElementById(elementId));
}

function common_Enable(state,element)
{	
	if (element == null) return;
	var label;
	label = "";
	if (element.type != "radio" && element.type != "checkbox") {
		element.disabled = (!state) ? true : false;			
		setStyleDisabled(state,element);
		return;	
	}

	if (element.parentNode.nodeName == "SPAN"){
		element.disabled = (!state) ? true : false;			
		element.parentNode.disabled = (!state) ? true : false;			
		element.readOnly = (!state) ? true : false;			
	} else {
		//create span and insert element into it
		span = document.createElement('span');
		element.parentNode.insertBefore(span,element);
		
		if (element.nextSibling.nodeName == "LABEL") {		
			label = element.nextSibling;							
		}
		span.appendChild(element);
		if (label != "") {			
			span.appendChild(label);				
		}

		span.disabled = (!state) ? true : false;
		element.disabled = (!state) ? true : false;
	}
	setStyleDisabled(state,element);
}

function setStyleDisabled(state,element){	
	if (element.type != "text") return;

	if (!state) {			
		if (element.className.indexOf("disabled") > -1) return;
		element.className += " disabled";				
	} else {
		element.className = element.className.replace(" disabled","")
	}
}

//--------------------------------------------
//	trims text
//--------------------------------------------
function common_TrimText(s) 
{
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? '' : m[1];
}

//--------------------------------------------
//	split's decimal
//--------------------------------------------
// ret is array containing 
// ret.before = string before decimal point
// ret.after = string after decimal point
// function returns false if it can't parse str
function common_SplitDecimal(str, ret)
{
	if(str==null || str.length==0) 
		return false;
	
	var before = "";
	var after = "";
	var pos = 0;
	var len = str.length;
	var ch = "";
	
	// before decimal
	while(pos<len)
	{
		ch = str.charAt(pos);
		
		if(ch==lang_ThousandSymbol)
			; // ignore
		else if(ch==lang_DecimalSymbol)
		{
			pos++;
			break;
		} 
		else if(lang_Digits.indexOf(ch)!=-1)
		{
			before += ch;
		}
		else
			return false;
		
		pos++;
	}
	
	// after decimal
	while(pos<len)
	{
		ch = str.charAt(pos);
		
		if(lang_Digits.indexOf(ch)==-1)
			return false;
		
		after+=ch;				
		pos++;
	}
	
	ret.before = before;
	ret.after = after;
}

function common_nbsp_to_sp(str)
{
	return str.replace(/\xA0/g, ' ');
}

//--------------------------------------------
//	Get's date representation
//	from day month year
//--------------------------------------------
function common_GetDateYMD(year, month, day) {
    var date = new Date();

    date.setTime(0);
    date.setUTCFullYear(year);
    date.setUTCMonth(month - 1);
    date.setUTCDate(day);

    return date;
}

function common_GetDate(fromStr)
{
	var YMD = lang_GetYMD(fromStr);
	return common_GetDateYMD(YMD.year, YMD.month, YMD.day);
}

var Common = 1;

