﻿//bw check
function bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom&&document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1||window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1&&!this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1||this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1||this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6
	}
	else if(this.moz)
		this.ns6=1
	else if(this.ie){
		this.ie4=!this.dom&&document.all
		this.ie5=(this.agent.indexOf("msie 5")>-1)
		this.ie55=(this.ie5&&this.agent.indexOf("msie 5.5")>-1)
		this.ie6=this.dom&&!this.ie4&&!this.ie5&&! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.op5||this.op6||this.op7)
	this.usedom= this.ns6||this.op7
	this.reuse=this.ie||this.op7||this.usedom
	this.px=this.dom&&!this.op5?"px":""
	return this
}

var bw=new bwcheck()

//form validator
function checkForm(obj,mess){
	var v=true,
		chB=false,
		chBch=false,
		rB=false,
		rBch=false,
		i=0,
		j=obj.elements.length;
	if(!mess)
		mess="";
	for(i=0;i<j;i++){
		oName=obj.elements[i].name;
		if(oName.indexOf("wm_")!=-1)
			oObligatory=1;
		else
			oObligatory=0;
		oType=obj.elements[i].type;
		if(oType=='radio'){
			if(oObligatory==1)
				rB=true;
			if(oObligatory==1&&obj.elements[i].checked)
				rBch=true;
		}
		if(oType=='checkbox'){
			if(oObligatory==1)
				chB=true;
			if(oObligatory==1&&obj.elements[i].checked)
				chBch=true;
		}
		if(oType=='text'||oType=='textarea'||oType=='password')
			if(oObligatory==1&&obj.elements[i].value=="")
				v=false;
		if(oType=='select-one'||oType=='select-multiple')
			if(oObligatory==1&&obj.elements[i].selectedIndex==0)
				v=false;
	}
	if((chB&&!chBch)||(rB&&!rBch))
		v=false;
	if(!v)
		alert(mess);
	return v;
}

function isEmail(obj) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	if(email.test(obj.value)==false){
		alert("Nesprávny E-Mail!");
		obj.value="";
		return false;
	}
	else
		return true;
}

//img switcher
function switchImg(obj,par){
	if(document.getElementById(obj))
		obj=document.getElementById(obj);
	
	
	imgName=obj.src;
	imgName=imgName.split("/");
	imgName=imgName[(imgName.length)-1];
	
	imgPath=obj.src.split(imgName);
	imgPath=imgPath[0];
	
	imgName=imgName.split(".");
	imgSuffix=imgName[1];
	imgName=imgName[0];
	
	if(par==1)
		imgName=imgName+"_over."+imgSuffix;
	else{
		imgName=imgName.split("_");
		imgName=imgName[0]+"."+imgSuffix;
	}
	obj.src=imgPath+imgName;
}


//cancel event
function cancelEvent(){
	window.event.returnValue=false;
	window.event.cancelBubble=true;
}

//popup opener
function openPopup(w,h,ref,par){
	if(par==1)
		ref="_popup.wm"+ref;
	window.open(ref,"popupWin","width="+w+",height="+h+",top="+((screen.availHeight/2)-(h/2))+",left="+((screen.availWidth/2)-(w/2))+",toolbar=no,scrollbars=yes,resizable=no,menubar=no,status=no,directories=no,location=no");
}

//center window
function centerWindow(){
	var xCoordinate=(screen.availWidth-document.body.offsetWidth)/2,
		yCoordinate=(screen.availHeight-document.body.offsetHeight-100)/2;
	window.moveTo(xCoordinate,yCoordinate)
}

//resize window
function resizeWindow(w,h){
	window.resizeTo(w,h)
}

//pos finder
function findPosition(obj){
    x=0; y=0; w=0; h=0; var el,temp;
    el=document.getElementById(obj);
    if(el.offsetParent){
      temp=el;
      while(temp.offsetParent){
        temp=temp.offsetParent; 
        x+=temp.offsetLeft;
        y+=temp.offsetTop;
      }
    }
    x+=el.offsetLeft;
    y+=el.offsetTop;
	return [x,y];
 }
  
  
//target="_blank"
function extLinks(){ 
	if(!document.getElementsByTagName)
		return; 
	var anchors=document.getElementsByTagName("a"); 
	for(var i=0;i<anchors.length;i++)				
		if(anchors[i].getAttribute("href")&&anchors[i].getAttribute("rel")) 
			anchors[i].target=anchors[i].getAttribute("rel");
}

function bookmark(title,url){
	if(document.all)
		window.external.AddFavorite(url,title);
	else if(window.sidebar)
		window.sidebar.addPanel(title,url,"")
}