/*
styledJS v0.7
Coded by Rustam Khodjaev.
This code is the part of copyrighted content and not for public use.
If you want to use anything from here, please contact an author.
*/

var firstRun=true,popUpWin=false,rTimer,tTimer,cTimer
var Mozilla=navigator.appName=="Netscape"
var IE=navigator.appName.indexOf("Microsoft")!=-1
var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1&&navigator.appVersion.indexOf("Mozilla")==-1

document.onkeydown = checkKeycode
window.onload=function() {
	if(get("agnt")) {
		get("agnt").checked=false
		get("agnt").onclick=function() {get("check_btn").disabled=!this.checked}
	}
	if(get("shoutbox")) {
		Request("tools/shout.php","w=show","shoutboxt")
		getByTag("shoutbox","button",0).onclick=function() {
			if(getByTag("shoutbox","input",0).value!=''&&getByTag("shoutbox","textarea",0).value!='')
			Request("tools/shout.php","w=shout&name="+getByTag("shoutbox","input",0).value+"&text="+getByTag("shoutbox","textarea",0).value,"",function() {
				getByTag("shoutbox","textarea",0).value=''
				getByTag("shoutbox","textarea",0).focus()
				Request("tools/shout.php","w=show","shoutboxt")
			})
		}
		setInterval(function() {
			Request("tools/shout.php","w=show","shoutboxt")
		},40000)
	}
	preparePhotoEff()
	if(IE6) iePNGFix()
}
function insertHTML(elem,html) {
	if(Mozilla) {
		var adjHTML,range=elem.ownerDocument.createRange()
		range.selectNodeContents(elem)
		range.collapse(false)
		adjHTML=range.createContextualFragment(html)
		elem.appendChild(adjHTML)
    } else {
		elem.innerHTML=html
    }
}
function get(elem) {
	if(document.getElementById(elem))
	return document.getElementById(elem)
}

function getByTag(elemid,name,index) {
	elem=typeof elemid=="object"?elemid:get(elemid)
	collection=elem.getElementsByTagName(name)
	return (index==undefined)?collection:collection[index]
} 

function checkFieldNum(e) {
	date=new Date()
	e=e||window.event
	var charCode=e.which?e.which:e.keyCode
	switch(this.id) {
		case "dy":restriction=date.getFullYear()-15;break
		case "dm":restriction=13;break
		case "dd":restriction=32;break
		default:restriction=0
	}
	if(charCode!=8||charCode!=7) restr=restriction==0?true:this.value+String.fromCharCode(charCode)<restriction
	return (charCode>=48&&charCode<=57&&restr||charCode==8||charCode==9)
}

function redirect(to,timeout) {
	to=to==''?'index.php':to
	if(!timeout||timeout==0||timeout==undefined) location.href=to
	else timedAction(function(){redirect(to)},timeout*1000)
}

function timedAction(callback,timeout) {
	if(!timeout||timeout==0||timeout==undefined) {
		callback()
		if(tTimer) clearInterval(tTimer)
	} else {
		tTimer=setInterval(function(){timedAction(callback)},timeout*1000)
	}
}

function decodeUrl(coded,extended,hideQm) {
	var url=''
	if(extended) {
		var index=0
		var str=new Array()
		temp=coded.toString().split('')
		for(i=0;i<temp.length;i++) {
			if(!str[index]) str[index]=""
			str[index]+=temp[i]
			if(str[index].toString().length>=3) index++
		}
		var cArray=str
	} else cArray=coded.split("%")
	for(i=0;i<cArray.length;i++) {
		if(extended) {
			url+=String.fromCharCode(parseInt(cArray[i].replace('%',''))+13)
		} else {
			innerArray=cArray[i].split(",")
			for(a=0;a<innerArray.length;a++) url+=String.fromCharCode(parseInt(innerArray[a])+13)
			if(i!=(cArray.length-1)) url+='&'
		}
	}
	return (extended?'':(hideQm?'':'?'))+url
}

function randNum() {return Math.round(Math.random()*100000)}

function addImgField(limit) {
	limit=limit==''?3:limit
	pt=get("s_imgs_fld")
	fields=getByTag(pt,"input").length+1
	if(fields<limit) {
		newElm=document.createElement('input')
		newElm.type="file"
		newElm.name="s_images[]"
		newElm.className="inputsearch"
		pt.appendChild(newElm)
	}
	//if(fields==limit-1) getByTag(pt.parentNode,"span",0).style.display='none'
}

function setContent(text,elem) {
	elem=typeof elem=='object'?elem:get(elem)
	elem.style.display='block'
	elem.innerHTML=text
}

function getPosition(obj) {
	var oleft=otop=0
	if(obj.offsetParent) {
		oleft=obj.offsetLeft
		otop =obj.offsetTop
		while(obj=obj.offsetParent) {
			oleft+=obj.offsetLeft
			otop +=obj.offsetTop
		}
	}
	return [oleft,otop]
}

function newWindow(URLStr, left, top, width, height) {
	if(popUpWin && !popUpWin.closed) popUpWin.close()
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'')
}

function checkKeycode(e) {
	e = e||window.event
	var kc=e.keyCode
	if(e.ctrlKey&&kc==83) return false
}

function locate(elem,elemto,act,acl) {
	var coords=getPosition(elemto)
	elem.style.left=(coords[0]+(acl==undefined?0:acl))+'px'
	elem.style.top=(coords[1]+(act==undefined?0:act))+'px'
}