function not_disabled(id)
{
	document.getElementById(id).readOnly = false;
	document.getElementById(id).style.border = "1px solid #000000";
}
function set_disabled(id)
{
	document.getElementById(id).readOnly = true;
	document.getElementById(id).style.border = "0";
}
vaiting=3;
function save_changes(id,id2)
{
	if (document.getElementById(id2+'_'+id).value != document.getElementById('old_'+id2+'_'+id).value)
	{
		answer = confirm("Do you want save changes ?");
		if (answer) 
		{
			xajax_update_number(id2,document.getElementById(id2+'_'+id).value,id);
			vaiting=0;
		}
		else
		{
			document.getElementById(id2+'_'+id).value=document.getElementById('old_'+id2+'_'+id).value
			vaiting=0;
		}
	}
}
function center_window(id)
{
		win_height = parseInt(document.body.clientHeight);
		win_width = parseInt(document.body.clientWidth);
		block_height = parseInt(document.getElementById(id).offsetHeight);
		block_width = parseInt(document.getElementById(id).offsetWidth);
		document.getElementById(id).style.top = ( win_height - block_height ) / 2 + "px";
		document.getElementById(id).style.left = ( win_width - block_width ) / 2 + "px";
}
function open_window(_link,_name,_width,_height)
{
	win_height = parseInt(document.body.clientHeight);
	win_width = parseInt(document.body.clientWidth);
	_left = win_width / 2 - _width / 2;
	_top = win_height / 2 - _height / 2;
	window.open(_link,_name,'width='+_width+',height='+_height+',left='+_left+',top='+_top+',screenX=200,screenY=200,scrollbars=yes');
	return false;
}

function extension(id,x,y)
{
		if (document.getElementById(id).style.display=='none')
		{
			document.getElementById(id).style.top=x + "px";
			document.getElementById(id).style.left=y + "px";
			document.getElementById(id).style.display='';
		}
		else
		{
			document.getElementById(id).style.top=-1000 + "px";
			document.getElementById(id).style.left=-1000 + "px";
			document.getElementById(id).style.display='none';
		}
}
function hide_seek(id)
{
		if (document.getElementById(id).style.display=='none')
		{
			document.getElementById(id).style.display='block';
			document.getElementById(id).style.top='';
			document.getElementById(id).style.left='';
			document.getElementById(id).style.positinion='';
		}
		else
		{
			document.getElementById(id).style.positinion='absolute';
			document.getElementById(id).style.top=-1000 + "px";
			document.getElementById(id).style.left=-1000 + "px";
			document.getElementById(id).style.display='none';
		}
}
function hide_seek2(id)
{
		if (document.getElementById(id).style.visibility=='hidden')
		{
			document.getElementById(id).style.positinion='';
			document.getElementById(id).style.visibility='';
			document.getElementById(id).style.top='';
			document.getElementById(id).style.left='';
		}
		else
		{
			document.getElementById(id).style.positinion='absolute';
			document.getElementById(id).style.visibility='hidden';
			document.getElementById(id).style.top=-1000 + "px";
			document.getElementById(id).style.left=-1000 + "px";
		}
}
function focus_input(form,id00,id01)
{
	if (document.forms[form].elements[id00].value == '')
	{
		document.forms[form].elements[id00].focus();
	}
	else if (id01)
	{
		document.forms[form].elements[id01].focus();
	}
}
function confirmLink(msg)
{
var agree=confirm(msg);
if (agree)
	return true ;
else
	return false ;
}

function textarea_size(id,from,to)
{
	if (document.getElementById(id).style.height==from)
	{
		document.getElementById(id).style.height=to;
	}
	else
	{
		document.getElementById(id).style.height=from;
	}
}

items =new Array(100);
function more_fields(id,type)
{
 	;selected='';tmp_write='';write='';name_write='';
 	last_pos = document.getElementById('last_pos').value;
 	//alert(id);
 	if (selectObject=document.getElementById(id))
 	{
 		item_className=document.getElementById(id).className;
		sk=parseInt(last_pos)+1;
		sk2=1;
		write = write + '<input type="text" class="'+item_className+'" value="'+document.getElementById(id).value+'" name="'+document.getElementById(id).name+'" id="'+id+'" />';
		if (document.getElementById(id+'_req').checked) check='checked="checked"'; else check='';
		tmp_write = tmp_write + '<input type="checkbox" value="'+document.getElementById(id+'_req').value+'" name="'+document.getElementById(id+'_req').name+'" id="'+id+'_req" '+check+' /><br />';
		name_write = name_write + id + '_' + sk2 + '<br />';
		sk2++;
		for ( j=0; j < 20; j++ )
		{
			if (document.getElementById(id+'_'+sk2))
			{
				if (type=='text')
			 	{
					write = write + '<input type="text" class="'+item_className+'" value="'+document.getElementById(id+'_'+sk2).value+'" name="'+document.getElementById(id+'_'+sk2).name+'" id="'+id+'_'+sk2+'" />';
					if (document.getElementById(id+'_'+sk2+'_req').checked) check='checked="checked"'; else check='';
					tmp_write = tmp_write + '<input type="checkbox" value="'+document.getElementById(id+'_'+sk2+'_req').value+'" name="'+document.getElementById(id+'_'+sk2+'_req').name+'" id="'+id+'_'+sk2+'_req" '+check+' /><br />';
					if (document.getElementById(id+'_'+sk2).name.indexOf("new_update")!=-1)
						name_write = name_write + id + '_' + sk2 + '<input name="data[new_update][values]['+sk+'][name]" value="'+id+"_"+sk2+'" type="hidden"><input name="data[new_update][values]['+sk+'][type]" value="checkbox_plus" type="hidden"><br />';
					else
						name_write = name_write + id + '_' + sk2 + '<br />';
					sk++;
					sk2++;
			 	}
			}
			else
			{
				j=20;
			}
		}

		if (type=='text')
		{
			write = write + '<input type="text" class="'+item_className+'" value="" name="data[new_update][values]['+sk+'][value]" id="'+id+'_'+sk2+'" />';
			tmp_write = tmp_write + '<input type="checkbox" value="on" name="data[new_update][values]['+sk+'][requere]" id="'+id+'_'+sk2+'_req" />';
			name_write = name_write + id + '_' + sk2 +'<input name="data[new_update][values]['+sk+'][name]" value="'+id+'_'+sk2+'" type="hidden"><input name="data[new_update][values]['+sk+'][type]" value="checkbox_plus" type="hidden"><br />';
			//alert(write);
			document.getElementById(id+'_place').innerHTML = write;
			document.getElementById(id+'_requere').innerHTML = tmp_write;
			document.getElementById(id+'_name').innerHTML = name_write;
		}
	}
 }

var translate_error = "Klaida";
var translate_neuzpildyti_laukai = "neuzpildyti privalomi laukai";
var aFields=new Array();
var aErrMsgs=new Array();
var oAllInputs;
var list_fields=false;
function fecCheckRequiredFields (oForm2,_return){
	var daysInMonth = DaysArray(12)
	var month_names=new Array(12)
	month_names[0]="January"
	month_names[1]="February"
	month_names[2]="March"
	month_names[3]="April"
	month_names[4]="May"
	month_names[5]="June"
	month_names[6]="July"
	month_names[7]="August"
	month_names[8]="September"
	month_names[9]="October"
	month_names[10]="November"
	month_names[11]="December"
	var aErrors=new Array();
	var aMissmatch=new Array();
	var aList=new Array();
	var bList=new Array();
	var cList=new Array();
	var dList=new Array();
	var eList=new Array();
	var fList=new Array();
	var errorList=new Array();
	var sAdditionalExplanation=new String();
	oAllInputs=oForm2.getElementsByTagName('INPUT');
	var ii = 0;
	for(ii=0; ii<aFields.length; ii++)
	{
		if (aFields[ii][2]!='' && (typeof(oForm2[aFields[ii][0]])=='object' || aFields[ii][1]=='checkbox'))
		{
			if (typeof(aFields[ii][4])=='undefined' || (typeof(aFields[ii][4])!='undefined'))
			{
				switch(aFields[ii][1])
				{
					case "text":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						}

						break;
					case "number":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						}
						else {
							if (!IsNumber(oForm2[aFields[ii][0]].value)) {
								aErrors[aErrors.length]=new Array();
								aErrors[aErrors.length-1]=aFields[ii];
								cList[cList.length]=aFields[ii][3];
							}
						}

						break;
					case "textarea":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						}
						break;
					case "password":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						} else {
							if (fecCheckRequiredPassword (aFields[ii],oForm2)==false) {
								aMissmatch[aMissmatch.length]=new Array();
								aMissmatch[aMissmatch.length-1]=aFields[ii];
								bList[bList.length]=aFields[ii][3];
							}
						}
						break;
					case "select":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						}
						break;
					case "radio":
						if ((fecCheckRequiredRadiobutton (aFields[ii],oForm2)==false) && aFields[ii][2]=='on'){
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						};
						break;
					case "checkbox":
						if((fecCheckRequiredCheckbox (aFields[ii],oForm2)==false) && aFields[ii][2]=='on'){
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						};
						break;
					case "url":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						}
						break;
					case "calendar":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						} else if (oForm2[aFields[ii][0]].value!='' && oForm2[aFields[ii][0]].value!=' ')
						{
							if (oForm2[aFields[ii][0]].value.match(/\d{4}[\/-]\d{2}[\/-]\d{2}/)==null)
							{
								aMissmatch[aMissmatch.length]=new Array();
								aMissmatch[aMissmatch.length-1]=aFields[ii];
								eList[eList.length]=aFields[ii][3];
							}
							else
							{
								tmp_theField_value = month_names[oForm2[aFields[ii][0]].value.substr(5,2)-1]+' '+oForm2[aFields[ii][0]].value.substr(8,2)+', '+oForm2[aFields[ii][0]].value.substr(0,4);
								var dPart = tmp_theField_value.replace("-"," ");
								var nDate = new Date(dPart);
								if (oForm2[aFields[ii][0]].value.substr(8,1)=="0") tmp_day=oForm2[aFields[ii][0]].value.substr(9,1);
								else tmp_day=oForm2[aFields[ii][0]].value.substr(8,2);
								if (oForm2[aFields[ii][0]].value.substr(5,1)=="0") tmp_month=oForm2[aFields[ii][0]].value.substr(6,1);
								else tmp_month=oForm2[aFields[ii][0]].value.substr(5,2);
								tmp_year=oForm2[aFields[ii][0]].value.substr(0,4);
								var day = parseInt(tmp_day);
								var month = parseInt(tmp_month);
//								alert(day + ':' + month + ':' + tmp_year);
//								return false;
								if (tmp_day.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(tmp_year)) || day > daysInMonth[month] || isNaN(nDate))
								{
									aMissmatch[aMissmatch.length]=new Array();
									aMissmatch[aMissmatch.length-1]=aFields[ii];
									eList[eList.length]=aFields[ii][3];
								}
							}
						}
						break;
					case "email":

						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						} else if(oForm2[aFields[ii][0]].value!='' && oForm2[aFields[ii][0]].value!=' ')  {
							if (oForm2[aFields[ii][0]].value.match(/^[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+@[a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])+\.[a-zA-Z]{2,4}/)==null) {
							//if (oForm[aFields[i][0]].value.match(/^[\w\.\-]+\@{1}[\w\.\-]+\.{1,}\w{2,10}/)==null) {
								aMissmatch[aMissmatch.length]=new Array();
								aMissmatch[aMissmatch.length-1]=aFields[ii];
								aList[aList.length]=aFields[ii][3];
							}
						}

						break;
					case "phone":
						if ((oForm2[aFields[ii][0]].value=='' || oForm2[aFields[ii][0]].value==' ') && aFields[ii][2]=='on') {
							aErrors[aErrors.length]=new Array();
							aErrors[aErrors.length-1]=aFields[ii];
							dList[dList.length]=aFields[ii][3];
						} else if(oForm2[aFields[ii][0]].value!='' && oForm2[aFields[ii][0]].value!=' ')  {
							if (oForm2[aFields[ii][0]].value.match(/^[0-9]+-+[0-9]+-+[0-9]+[0-9]$/)==null) {
							//if (oForm[aFields[i][0]].value.match(/^[\w\.\-]+\@{1}[\w\.\-]+\.{1,}\w{2,10}/)==null) {
								aMissmatch[aMissmatch.length]=new Array();
								aMissmatch[aMissmatch.length-1]=aFields[ii];
								fList[fList.length]=aFields[ii][3];
							}
						}

						break;
					case "file":
						break;
				}
			}
		}
	}

	if (aMissmatch.length>0)
	{
		if (aList.length>0)
		{
			errorList[errorList.length]=translate_error+' ("'+aList.join(', ')+'") ! '+aErrMsgs[1];
		}
		if (bList.length>0)
		{
			errorList[errorList.length]=translate_error+' ("'+bList.join(', ')+'") ! '+aErrMsgs[2];
		}
		if (eList.length>0)
		{
			errorList[errorList.length]=translate_error+' ("'+eList.join(', ')+'") ! '+aErrMsgs[5];
		}
		if (fList.length>0)
		{
			errorList[errorList.length]=translate_error+' ("'+fList.join(', ')+'") ! '+aErrMsgs[6];
		}
	}
	if (aErrors.length>0)
	{
		if (cList.length>0)
		{
			errorList[errorList.length]=translate_error+' ("'+cList.join(', ')+'") ! '+aErrMsgs[4];
		}
		if (dList.length>0)
		{
			if (list_fields)
			{
				errorList[errorList.length]=translate_error+' ! '+aErrMsgs[0]+'\n '+translate_neuzpildyti_laukai+': \n'+dList.join(',\n');
			}
			else
			{
				errorList[errorList.length]=translate_error+' ! '+aErrMsgs[0];
			}

		}
	}
	if (errorList.length>0)
	{
		 alert(errorList.join('\n'));
		 if (_return=='false') return false;
	}
	else
	{
		if (_return=='false') return true;
		else oForm2.submit();
	}
}

function fecRegisterFormElement (sName,sType,sCheck,sLabel,sFormname)
{
	var notfound = true;
	var iq=aFields.length;
	for (i=0;i < iq;i++)
	{
		if (aFields[i][0]==sName && aFields[i][1]==sType  && aFields[i][2]==sCheck  && aFields[i][4]==sFormname)
		{
			notfound = false;
		}
	}
	if (sName!='' && sType!='' && sLabel!='' && notfound == true)
	{
		aFields[iq]=new Array();
		aFields[iq][0]=sName;
		aFields[iq][1]=sType;
		aFields[iq][2]=sCheck;
		aFields[iq][3]=sLabel;
		aFields[iq][4]=sFormname;
	}
}
function fecUnRegisterFormElement (sName,sType) {
	if (sName!='' && sType!='') {
		var iq=aFields.length;
		for(i=0;i<iq;i++)
		{
			if (aFields[i][0]==sName && aFields[i][1]==sType)
			{
				aFields[i][0]='';
				aFields[i][1]='';
				aFields[i][2]='';
				aFields[i][3]='';
				aFields[i][4]='';
			}
		}
	}
}
function fecRegisterErrorMessages (sErrMsgEmptyFields, sBadForm, sPasswordsDoNotMatch, snoLatin, snoNumber, snoDate, sbadPhone){
	aErrMsgs[0]=sErrMsgEmptyFields;
	aErrMsgs[1]=sBadForm;
	aErrMsgs[2]=sPasswordsDoNotMatch;
	aErrMsgs[3]=snoLatin;
	aErrMsgs[4]=snoNumber;
	aErrMsgs[5]=snoDate;
	aErrMsgs[6]=sbadPhone;
}
function fecCheckRequiredCheckbox (aCB,oForm){
	var bHasAtLeastOneChecked=new Boolean(false);
	for(iii in oAllInputs) {
		if (oAllInputs[iii].type=='checkbox') {
			if (oAllInputs[iii].name.substr(0,aCB[0].length)==aCB[0] && oAllInputs[iii].checked==true)	bHasAtLeastOneChecked=true;
		}
	}
	return bHasAtLeastOneChecked;
}
function fecCheckRequiredRadiobutton (aRadio,oForm){
	var bHasAtLeastOneChecked=new Boolean(false);
	//alert(oForm[aRadio[0]][0].checked);
	for(iia=0; iia<oForm[aRadio[0]].length; iia++) {
		if (oForm[aRadio[0]][iia].value!=undefined && oForm[aRadio[0]][iia].checked==true) {
			bHasAtLeastOneChecked=true;
		} else {

		}
		//alert(oForm[aRadio[0]][ii].checked);
	}
	return bHasAtLeastOneChecked;
}
function fecCheckRequiredPassword (oPw,oForm){
	for(iii=0; iii<aFields.length; iii++) {
		if (aFields[iii][1]=='password' && oForm[aFields[iii][0]].value!=oForm[oPw[0]].value) return false;
	}
	return true;
}
function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function add_field (data_array)
{

}