function $(obj){return document.getElementById(obj);}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function initSize(){
	pageHeight=$('wrap1').offsetHeight;
	windowHeight=document.body.offsetHeight-70;
	if(pageHeight<windowHeight)$('wrap1').style.height=windowHeight+'px';
}

function defineKey(e) {
	var keynum;
	
	if(window.event){ // IE
		keynum = e.keyCode;
	}
	else if(e.which){ // Netscape/Firefox/Opera
		keynum = e.which;
	}
	
	if (keynum == 13){
		//ask();
		return false;
	}
	else{
		return String.fromCharCode(keynum);
	}
}

function checkMail(address) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(address) == false) {
		return false;
	}
	return true;
}

function getBigImg(obj){
	imgAdr=obj.getElementsByTagName("img")[0].src;
	myRef = window.open(imgAdr,"mywin","left=20,top=20,toolbar=0,resizable=0");
}

function sendToFriend(c,f,id){
	fMailVal=$('fMail').value;
	fNameVal=$('fName').value;
	sNameVal=$('sName').value;
	_error=0;
	if(!checkMail(fMailVal)){
		showError('fMail');
		_error=1;
	}
	if(fNameVal==''){
		showError('fName');
		_error=1;
	}
	if(sNameVal==''){
		showError('sName');
		_error=1;
	}
	if(_error==1)return false;
	formHTML=$('sendForm').innerHTML;
	$('sendForm').innerHTML=$('loadCode').innerHTML;
	JsHttpRequest.query(
		f+'/ajax.php?x=a'+Math.random(), 
		{
			'uid': c,
			'act': 'sendToFriend',
			'id': id,
			'fMail': fMailVal,
			'fName': fNameVal,
			'sName': sNameVal
		},
 
		function(result, errors) {
		    if(errors)alert(errors);
			else{
				showMessage(result);
				$('sendForm').innerHTML=formHTML;
			}
		}
	);
}

function showError(id){
	$(id).style.backgroundColor="#ffd8d8";
	$(id).onfocus=function(){
		this.style.backgroundColor="#ffffff";
	}
}

function showMessage(text){
	if(!$('alertDiv'))document.body.innerHTML+='<div id="alertDiv"></div>';
	if(!$('alertMes'))document.body.innerHTML+='<div id="alertMes"></div>';
	$('alertMes').innerHTML=text;
	$('alertMes').innerHTML+='<div style="text-align:center;margin-top:10px;"><input type="button" class="button" value="Закрыть" onclick="hideMessage()" /></div>';
	$('alertDiv').style.display='block';
	$('alertDiv').onclick=hideMessage;
	$('alertMes').style.display='inline';
}

function hideMessage(){
	$('alertDiv').style.display='none';
	$('alertMes').style.display='none';
}

function showMail(t){
	m='@infobreak.ru';
	switch(t){
		case 'main':m='info'+m;break;
	}
	return '<a href="mailto:'+m+'">'+m+'</a>';
}

function doSearch(){
	inp=document.getElementById('search');
	if(inp.value.length<2){
		inp.focus();
		return false;
	}

	location.href=folder+"/"+"s/"+inp.value+"/";
	return false;
}
