function getObj(id){
	return document.getElementById(id);
}

function getSelectValue(selid){
	return document.getElementById(selid).options[document.getElementById(selid).selectedIndex].value;
}

function getInputValue(input){
	return document.getElementById(input).value;
}

function getCheckboxValue(id){
	return document.getElementById(id).checked;
}

function getRadioValue(id){
	return document.getElementById(id).checked;
}

function getInner(id){
	return document.getElementById(id).innerHTML;
}

function getOuter(id){
	return document.getElementById(id).outerHTML;
}

function getRadioGroupValue(name){

var a=document.getElementsByName(name);

if(a==undefined || a==null)return false;

for(i=0;i<a.length;i++){
 if(a[i].checked) return a[i].value;
}
	return false;
}

function setFocus(id,showError){
	
	var obj=getObj(id);
	if(obj){
		obj.focus();
		if(showError) obj.className='error '+obj.className;
	}
	else return false;
}

function setValue(id,val){
	document.getElementById(id).value=val;
}

function isemail(e){return /^[0-9a-z]+([\.\-_][0-9a-z]+)*@[0-9a-z]+([\.\-][0-9a-z]+)*\.(([a-z]{2,4})|(travel)|(museum))$/i.test(e)} 


/*  same cyfry */
function isNumbers(e) {return /^[\d]+$/i.test(e)}


/* Telefon - przynajmniej 7 cyfr i -*/
function isTel(e) {return /^[\d\s()-]{7,}$/i.test(e)}

/* sprawdzenie daty z kalendarzyka */
function isCalDate(e) {return /^[\d]{4}\-[\d]{2}\-[\d]{2}$/i.test(e)}

function isToLong(str,maxl){
	return str.length>maxl;
}

function fix_zero(l){
	//alert(l.substring(0,1));
	if(l.substring(0,1)=="0") l=l.substring(1,l.length);
	return parseInt(l);
}

function trim(str,x){ 
 if (x=='left' || x=='both') 
   str= str.replace(/^\s*/,'');
 if (x=='right' || x=='both') 
   str= str.replace(/\s*$/,'');

 return str; 
}

var verificator_nip=[6,5,7,2,3,4,5,6,7];
var verificator_regon=[8,9,2,3,4,5,6,7];
var verificator_pesel=[1,3,7,9,1,3,7,9,1,3];

function verify_nip(a)
{
a=a.replace(/[^0-9]/g,'')
if (a.length!=10) return false;
var i,n;
for (i=n=0;i<9;i++) n+=a.charAt(i)*verificator_nip[i];
n%=11;
return ( n == a.charAt(9));

}

function verify_regon(a){
 if (a.search(/[^0-9]/)>=0 || a.length!=9) return false;
 var i,n;
 for (i=n=0;i<8;i++) n+=a.charAt(i)*verificator_regon[i];
 n%=11;
 return ( n == a.charAt(8));
}

function verify_pesel(a){
 if (a.search(/[^0-9]/)>=0 || a.length!=11) return false;
 var i,n;
 for (i=n=0;i<10;i++) n+=a.charAt(i)*verificator_pesel[i];
 n%=10;
 return  ( (10-n)%10 == a.charAt(10));
} 

function isPostCodePl(code){
	code=code.replace(/-/,'');
	code=parseInt(code);
	code=code.toString();
	//alert(code);
	if(code.length!=5) return false;
	return true;
}

//pokazuje w alercie jakie wymagane pola nalezy jeszcze wypelnic
function showErrorFields(to_valid,errFields,lang){
	
	var msg=new Array(
	'Wypełnij następujące pola:',
	'You must fill required fields:'
	)
	var actlang=(lang=='pl')?0:1;
	var msg_alert=msg[actlang];
	
	
	for ( i=0; i<errFields.length; i++)
	{
		msg_alert+="\n- "+to_valid[errFields[i]][3];
	}
	
	alert(msg_alert);
}

//sprawdza na blur czy jest wypelniony,zaznaczony - tylko dla pol required
function blurCheck(obj,type,mode){
	
	var error=false;
	
	if(type=='i') actValue=trim(getInputValue(obj.id),'both');
	else if(type=='s')actValue=trim(getSelectValue(obj.id),'both');
	else if(type=='c')actValue=getCheckboxValue(obj.id);
	else if(type=='r')actValue=getRadioValue(obj.id);
	
	if(mode=='email' && !isemail(actValue))error=true;
	else if(actValue=='' || (type=='s' && actValue==0))error=true;
	
	

	if(error)obj.className='error';
	else obj.className='';
}

function setBorderColor(obj,color){
	obj.style.borderColor=color;
	return;
}

function setClass(obj,cname,add){
	
	if(add)obj.className+=' '+cname;
	else obj.className=cname;
	return;
}

function setBG(obj,color){
	obj.style.backgroundColor=color;
}

