//--------------------------------------------------------------------
function cat (scat) {
	document.frm_maintree.hid_selectedCat.value=scat;
	document.frm_maintree.submit();
}
function changeHeight () {
if((document.getElementById('left').offsetHeight*1+150) < pageHeight()) 
	document.getElementById('left').style.height = (pageHeight()*1-150)+'px';	
}
//--------------------------------------------------------------------
function checkNewUser() {
	if(trim(document.frm_user_reg.newUserName.value)=='') { 
		alert('Neįvestas vardas!'); 
		document.frm_user_reg.newUserName.focus();
		return 0; 
	}
	
	if(trim(document.frm_user_reg.newUserEmail.value)=='' || document.frm_user_reg.newUserEmail.value.indexOf('@')==-1) { 
		alert('Neteisingai įvestas el. paštas!'); 
		document.frm_user_reg.newUserEmail.focus();
		return 0; 
	}
	
	if(trim(document.frm_user_reg.newUserPass.value)=='' || trim(document.frm_user_reg.newUserRepeatPass.value)=='') { 
		alert('Neįvestas slaptažodis!'); 
		document.frm_user_reg.newUserRepeatPass.value='';
		document.frm_user_reg.newUserPass.value='';
		document.frm_user_reg.newUserPass.focus();		
		return 0; 
	}
		
	if( document.frm_user_reg.newUserRepeatPass.value!=document.frm_user_reg.newUserPass.value) {
		alert('Slaptažodžiai nesutampa. Pakartokite įvedimą!'); 
		document.frm_user_reg.newUserRepeatPass.value='';
		document.frm_user_reg.newUserPass.value='';
		document.frm_user_reg.newUserPass.focus();
		return 0; 
	}
	
	if(document.frm_user_reg.chk_rules.checked==false) { alert('Norėdami prisiregistruoti turite susipažinti ir sutikti su taisyklemis!'); return 0; }
	
	return 1;

}
//--------------------------------------------------------------------
function checkNewArticle(uID) {
if(!(uID > 0)) {
	if(trim(document.frm_upload_article.newAUserName.value)=='') { 
		alert('Neįvestas vardas!'); 
		document.frm_upload_article.newAUserName.focus();
		return 0; 
	}

	if(trim(document.frm_upload_article.newAUserEmail.value)=='' || document.frm_upload_article.newAUserEmail.value.indexOf('@')==-1) { 
		alert('Neteisingai įvestas el. paštas!'); 
		document.frm_upload_article.newAUserEmail.focus();
		return 0; 
	}
}

	if(trim(document.frm_upload_article.newATitle.value)=='') { 
		alert('Neįvestas pavadinimas!'); 
		document.frm_upload_article.newATitle.focus();
		return 0; 
	}

	if(trim(document.frm_upload_article.newACategory.value)=='') { 
		alert('Nepasirinkta kategorija!'); 
		document.frm_upload_article.newACategory.focus();
		return 0; 
	}

	if(trim(document.frm_upload_article.newAType.value)=='') { 
		alert('Nepasirinktas tipas!'); 
		document.frm_upload_article.newAType.focus();
		return 0; 
	}

	if(trim(document.frm_upload_article.newADesc.value)=='') { 
		alert('Neįvestas apibūdinimas!'); 
		document.frm_upload_article.newADesc.focus();
		return 0; 
	}

	if(trim(document.frm_upload_article.newAFile.value)=='') { 
		alert('Nepasirinktas failas!'); 
		document.frm_upload_article.newAFile.focus();
		return 0; 
	}

	if(document.frm_upload_article.chk_rules.checked==false) { alert('Norėdami atsiųsti darbą turite susipažinti ir sutikti su taisyklemis!'); return 0; }
	
	return 1;


}

//--------------------------------------------------------------------
function trim(str) {
return str.replace(/^\s+|\s+$/g, '') ;	
}
//--------------------------------------------------------------------
function ratingOnMouse(action,img_name) {
	var star;
	var nr = img_name.match(/\d/);
//	alert(document.getElementById('hid_israted').value);
	if(document.getElementById('hid_israted').value=='0') {
			document.getElementById('rating_star1').style.cursor = 'pointer'; 
			document.getElementById('rating_star2').style.cursor = 'pointer';		
			document.getElementById('rating_star3').style.cursor = 'pointer';		
			document.getElementById('rating_star4').style.cursor = 'pointer';		
			document.getElementById('rating_star5').style.cursor = 'pointer';					
		if(action=='over') {
			for(i=1;i<=5;i++) {
				star = eval('document.getElementById(\'rating_star'+i+'\')');
				if(i<=nr) star.src='images/star_10.gif';
				else star.src='images/star_00.gif';
			}
		}
		else if(action=='out') {
			showRating(document.getElementById('hid_rating').value);
		}
	}
}
//--------------------------------------------------------------------
function showRating(rating) {
var i;
for(i=0;i<5;i++) {
	star = eval('document.getElementById(\'rating_star'+(i*1+1)+'\')');
	if(rating > i && rating < i+1) {	
		star.src='images/star_05.gif'; // half star
	}
	else if(i < rating) {	
		star.src='images/star_10.gif'; //yellow star
	}
	else {	
		star.src='images/star_00.gif'; //empty star
	}	
}
}
//--------------------------------------------------------------------
function GetXmlHttpObject() {
var xmlHttp=null;
try {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e) {
 //Internet Explorer
 try  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
//--------------------------------------------------------------------
var xmlHttp;
function submitRating(val) { 
param = val;
if(document.getElementById('hid_israted').value=='0') {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	 alert ("Browser does not support HTTP Request");
	 return;
	 }
	var url="ajax.php?obj=rating&val1="+document.getElementById('hid_aID').value+"&val2="+val+"&vid="+document.getElementById('vID').value;
	xmlHttp.onreadystatechange=stateChangedRating;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
}
//---------------------------------------------------------------------
function stateChangedRating() { 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
//alert(xmlHttp.responseText);
document.getElementById('hid_rating').value = xmlHttp.responseText;
	document.getElementById('hid_israted').value = 1;
	showRating(xmlHttp.responseText);

	document.getElementById('rating_star1').style.cursor = ''; 
	document.getElementById('rating_star2').style.cursor = '';		
	document.getElementById('rating_star3').style.cursor = '';		
	document.getElementById('rating_star4').style.cursor = '';		
	document.getElementById('rating_star5').style.cursor = '';				
	
	document.getElementById("span_rating_value").innerHTML = 'Ačiū!';
	setTimeout("document.getElementById('span_rating_value').innerHTML = '&nbsp;"+xmlHttp.responseText+"'",1500);
 } 
}
//----------------------------------------------------------------------
function pageHeight(){
return window.innerHeight != null ? window.innerHeight :
document.documentElement
&& document.documentElement.clientHeight ?
document.documentElement.clientHeight : document.body != null?
document.body.clientHeight : null;
}
//---------------------------------------------------------------------
function maxlength(Object, MaxLen)
{
  if(Object.value.length >= MaxLen) Object.value = Object.value.substring(0,MaxLen);
}
//---------------------------------------------------------------------
function keypressed(event) {
var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
return Key;
}
//---------------------------------------------------------------------
function loadDocViewer(Ob){

	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onkeyup = function() { if(event.keyCode==27) DocViewerClose(); }
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '99';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	y=getPosY(Ob);
	if( dBi("docviewerDiv") )
	{
			dBi('docviewerDiv').style.display='';
			dBi('docviewerDiv').style.top=arrayPageScroll[1]+100+"px";

			if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			}
			}

			dBi('docviewerDiv').style.left=winW/2-(360/2)+"px";
	}
	objOverlay.focus();
	BG = '1';
}
//----------------------------------------------------------------------
function DocViewerClose(){
var BG;
dBi('overlay').style.display='none';
dBi('docviewerDiv').style.display='none';
BG = '0';
}
//----------------------------------------------------------------------
function writeDocViewer(){
	document.write('<object id="docviewerflash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="450" id="docviewer" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="ab.swf" /><param name="quality" value="high" />');
	document.write('<param name="scale" value="noscale" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="ab.swf" quality="high" scale="noscale" wmode="transparent" bgcolor="#ffffff" width="300" height="450" name="docviewer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
//----------------------------------------------------------------------
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
//----------------------------------------------------------------------
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
//------------------------------------------------------------------------------
function getPosY(theObj){
  y = 0;
  while(theObj){
    y += theObj.offsetTop;
    theObj = theObj.offsetParent;
  }
 return y;
}
//------------------------------------------------------------------------------
function dBi(id)
{
	return document.getElementById(id);
}
//------------ converts to sentence case ----------------------------------------------------------------
function sCase(obj){
  val=obj.value;
  result=new Array();
  result2='';
  count=0;
  endSentence=new Array();
  for (var i=1;i<val.length;i++){
  if(val.charAt(i)=='.'||val.charAt(i)=='!'||val.charAt(i)=='?'){
    endSentence[count]=val.charAt(i);
    count++
  }
}

var val2=val.split(/[.|?|!]/);

if(val2[val2.length-1]=='')val2.length=val2.length-1;

for (var j=0;j<val2.length;j++){
  val3=val2[j];

if(val3.substring(0,1)!=' ')val2[j]=' '+val2[j];

var temp=val2[j].split(' ');
var incr=0;

if(temp[0]==''){
  incr=1;
}

temp2=temp[incr].substring(0,1);
temp3=temp[incr].substring(1,temp[incr].length);
temp2=temp2.toUpperCase();
temp3=temp3.toLowerCase();
temp[incr]=temp2+temp3;

for (var i=incr+1;i<temp.length;i++){
  temp2=temp[i].substring(0,1);
  temp2=temp2.toLowerCase();
  temp3=temp[i].substring(1,temp[i].length);
  temp3=temp3.toLowerCase();
  temp[i]=temp2+temp3;
}

if(endSentence[j]==undefined)endSentence[j]='';
  result2+=temp.join(' ')+endSentence[j];
}

if(result2.substring(0,1)==' ')result2=result2.substring(1,result2.length);
  obj.value=result2;
}












