
  var _nOff = 20;
  var interval;
  var wndFocused = true;
  var oldMessages = new Array();
  var oldMessages2 = new Array();
  var curProfile = false;
  var curAlbum = 1;
  var curImage = '';

onload = function()
{
	setTimeout(adjustBody,500);
//	navigateButtons();
};


function navigateButtons()
{
	var back = document.createElement('a');
	back.innerHTML = "Back";
	back.href='javascript:history.go(-1);';
	//back.onclick = function(){history.go(-1);};
	
	var fwd = document.createElement('a');
	fwd.innerHTML = "Forward";
	fwd.href='javascript:history.go(1)';
	//fwd.onclick = function(){history.go(1);};

	var navholder = document.createElement('table');
	navholder.className = 'nav';
	navholder.width = "100%";
	var tr = navholder.insertRow(0);
	var tdback = tr.insertCell(0);
	tdback.appendChild(back);
	var tdfwd = tr.insertCell(1);
	tdfwd.align = 'right';
	tdfwd.appendChild(fwd);

	
//	document.body.insertBefore(navholder,document.body.firstChild);
}

var isIE = navigator.userAgent.indexOf('MSIE')!=-1;
var isChrome = navigator.userAgent.indexOf('Chrome')!=-1;
var isFirefox = navigator.userAgent.indexOf('Firefox')!=-1;
var isSafari = (!isChrome && navigator.userAgent.indexOf('Safari')!=-1);
var isOpera = navigator.userAgent.indexOf('Opera')!=-1;

adjustBody = function(){
	var sh = document.body.scrollHeight;
	var oh = document.body.offsetHeight;
	var h = 0;
	if(isNaN(sh) && isNaN(oh))
	{
		top.document.title = "Unsupported browser";
		setTimeout(adjustBody,200);
		return;
	}else if(isNaN(sh) || isFirefox)
	{
		h = oh;
	}else if(isNaN(oh) || isIE)
	{
		h = sh;
		
		//sometimes.. 

	}else
	{
		h = (sh>oh)?sh:oh;
	}
	
	{
		top.document.title = "Awortinkos";
		top.document.getElementById('mfrm').height = (h+50)+"px";
	}
	setTimeout(adjustBody,1200);
};

function loadNews(id)
{
	document.getElementById('newsDiv').innerHTML = newsAry[id];
}

function loadProfile(uid)
{
	hilite('lp');
	var pd = [];
	pd['UserId'] = uid;
	pd['func'] = 'loadProfile';
	var rpc = new ajax('functions.ajax.php','tabContentDiv',pd);
	rpc.post('HTML_ELEMENT',false);
}

function loadAlbum(uid,album)
{
	hilite('la'+album);
	curAlbum = album;
	var pd = [];
	pd['uid'] = uid;
	pd['album'] = album;
	var rpc = new ajax('albumHolder.php','tabContentDiv',pd);
	rpc.post('HTML_ELEMENT',false);
}



function validateAndRegister(frm)
{
  if(frm.UserName.value=='')
  {
    alert("Username must be filled!");
    return false;
  }
  
  if(frm.Password.value=='')
  {
    alert("Please enter atleast a 6 character password!");
    return false;
  }
  
  if(frm.Password.value!=frm.conf_Password.value)
  {
    alert("Password and Confirm Password don't match!");
    return false;
  }
  
  if(frm.Email.value.replace(/[a-z_0-9\-\@\.]+/g,'')!='' || frm.Email.value=='')
  {
    alert("Please enter your valid email address");
    return false;
  }
  
  var postData = new Array();
  postData['UserName'] = frm.UserName.value;
  postData['Password'] = frm.Password.value;
  postData['Email'] = frm.Email.value;
  postData['Sex'] = ($('male').checked)?'m':'f';
  postData['act'] = frm.act.value;
  postData['func'] = 'register_step1';
  
  var callCMD = new ajax('functions.ajax.php','',postData);
  callCMD.post('FUNCCALL',true);
}


function validateAndProceed(frm)
{
  var postData = new Array();
  postData['FirstName'] = frm.FirstName.value;
  postData['LastName'] = frm.LastName.value;
  postData['Place'] = frm.Place.value;
  postData['Nationality'] = frm.Nationality.value;
  postData['DateOfBirth'] = frm.year.options[frm.year.options.selectedIndex].value+'-'+frm.month.options[frm.month.options.selectedIndex].value+'-'+frm.day.options[frm.day.options.selectedIndex].value;
  postData['Single'] = $('Singyes').checked?'y':'n';
  postData['SchoolName'] = frm.SchoolName.value;
  postData['func'] = 'register_step3';
  
  var callCMD = new ajax('functions.ajax.php','',postData);
  callCMD.post('FUNCCALL',true);
}


function checkUploadStatus()
{
 if(window.frames['uploader'].document.body.innerHTML=='' || window.frames['uploader'].document.body.innerHTML =='undefined'){
 setTimeout('checkUploadStatus()',200);
 }else
 {
   hideDelayer(1);
   eval(window.frames['uploader'].document.body.innerHTML);
 }
}


function validateAndFinish(frm)
{
  var postData = new Array();
  postData['FavPlaceToGo'] = frm.FavPlaceToGo.value;
  postData['FavMusicBand'] = frm.FavMusicBand.value;
  postData['AboutYou'] = frm.AboutYou.value;
  postData['func'] = 'register_finish';

  var callCMD = new ajax('functions.ajax.php','',postData);
  callCMD.post('FUNCCALL',true);
}



function validateFileUpload(frm,section)
{
  var fileEleAry = new Array();
  var ele = frm.getElementsByTagName('input');
  var validFileTypes = 'jpg|png|gif';
  var noFile  = true;
  
  for(var i=0;i<ele.length;i++)
  {
    if(ele[i].getAttribute('type')=='file')
    {
      var fileType = ele[i].value.substring(ele[i].value.lastIndexOf('.')+1).toLowerCase();
      if(validFileTypes.indexOf(fileType)==-1)
      {
       alert('Only jpg, png and gif pictures are allowed!');
       return false;
      }
      
      if(ele[i].value!='') noFile = false;
    }
    if(ele[i].getAttribute('type')=='text')
    {
      if(ele[i].value=='')
      {
        alert("Please fill the "+ele[i].name.replace(/_/g,' ')+" field!");
        ele[i].focus();
        return false;
      }
    }
  }
  

  if(noFile)
  {
    alert("Please select atleast one file to upload!");
    return false;
  }
  
  
  
  switch(section)
  {
    case 'imageUploader':
         frm.action = section+'.php';
         frm.target = 'uploader';
         showDelayer(1);
         setTimeout('checkUploadStatus()',200);
         frm.submit();
    break;
    case 'album_iupload':
         frm.action = section+'.php';
         frm.target = 'uploader';
         showDelayer(1);
         setTimeout('checkUploadStatus()',200);
         frm.submit();
    break;
  }

}


function viewProfile(pid)
{
	location.href="profile.php?UserId="+pid;
}

function hilite(id)
{
	$('lp').className='tabhead';
	$('la1').className='tabhead';
	$('la2').className='tabhead';
	$('la3').className='tabhead';
	$(id).className='tabheadactive';
}

/**** quiz ****/

function nextQuestion()
{
	var rload=new ajax('ajax_quiz.php','quiz_canvas',[]);
	rload.get('HTML_ELEMENT',true);
}

function deletePhoto(url)
{
  if(confirm("Are you sure?")){
  var postData = new Array();
  postData['url'] = url;
  postData['album'] = curAlbum;
  postData['func'] = 'deleteAlbumPhoto';
  
  var loadCMD = new ajax('functions.ajax.php','',postData);
  loadCMD.post('FUNCCALL',true);
  }
}


var maxtime = 10;

function startTimer()
{
	$('tmr').innerHTML = maxtime--;

	if(maxtime>=0)
		setTimeout(startTimer,1000);
}


function postAnswers(frm)
{
	if(frm==null || frm==undefined) return;
	window.location.href='#questions';

	var i = frm.getElementsByTagName('input');
	
	var qAry = [];
	
	for(j=0;j<i.length;j++)
	{
		if(i[j].type=='radio')
		{
			if(i[j].name.indexOf('question')!=-1) // && i[j].checked
			{
				if(qAry.toString().indexOf(i[j].name)==-1)
				qAry.push(i[j].name);
			}
		}
		
	}
	
	var postData = [];
	while(pd=qAry.pop())
	{
		for(k=0;k<=4;k++)
		{
			try{
			if(frm.elements[pd][k].checked)
			{
				postData[pd] = frm.elements[pd][k].value;
				break;
			}
			else
				postData[pd] = '';
			}catch(e){
				postData[pd] = '';
			}
		}
	}
	postData['func'] = 'quizans';
	
	var quizcmd = new ajax('functions.ajax.php','quiz_canvas',postData);
	quizcmd.post('HTML_ELEMENT',postData);
}


function showDelayer(_time)
{
/*
  $('plswait').style.width = document.body.offsetWidth-_nOff;
  $('plswait').style.height = document.body.scrollHeight;
  $('plswait').style.top = 0;
  $('plswait').style.left = 0;
  if(navigator.appName.indexOf('Microsoft')!=-1){
  $('plswait').style.filter = "alpha(opacity=75)";
  }else{
  $('plswait').style.opacity = 0;
  }

  animateDelayer(0,_time,'show');
  */
}

function checkUploadStatus()
{
 if(window.frames['uploader'].document.body.innerHTML=='' || window.frames['uploader'].document.body.innerHTML =='undefined'){
 setTimeout('checkUploadStatus()',200);
 }else
 {
   hideDelayer(1);
   eval(window.frames['uploader'].document.body.innerHTML);
 }
}


function hideDelayer(_time)
{
/*
  $('plswait').style.width = document.body.offsetWidth-_nOff;
  $('plswait').style.height = document.body.scrollHeight;
  $('plswait').style.top = 0;
  $('plswait').style.left = 0;
  if(navigator.appName.indexOf('Microsoft')!=-1){
  $('plswait').style.filter = "alpha(opacity=65)";
  }else{
  $('plswait').style.opacity = '.65';
  }

  animateDelayer(65,_time,'hide');
  */
}

function loadPage(section, showProgress)
{
  window.location.href = section+'.php';
}

function loadPagehome(section, showProgress)
{
  window.location.href = section;
}

function animateDelayer(opacity,_time,dType)
{
  if(navigator.appName.indexOf('Microsoft')!=-1){
  $('plswait').style.filter = "alpha(opacity="+opacity+")";
  }else{
  $('plswait').style.opacity = opacity/100;
  }
  if(dType=='show')
  {
   if(opacity<65)
   {
     $('plswait').style.visibility = 'visible';
     opacity += 5;
     clearTimeout(interval);

     interval = setTimeout('animateDelayer('+opacity+','+_time+',"'+dType+'")',_time);
   }
  }else if(dType=='hide')
  {
   if(opacity>0)
   {
     opacity -= 5;
     clearTimeout(interval);
     interval = setTimeout('animateDelayer('+opacity+','+_time+',"'+dType+'")',_time);
   }else{
     $('plswait').style.visibility = 'hidden';
     $('plswait').style.height = '0px';
   }
  }

}




function showFadedElement(ele1)
{
//  alert(ele);
  ele = $(ele1).firstChild;
  var opacity = arguments[1];
  if(opacity=='undefined' || opacity==null || opacity==undefined)
  {
    opacity = 0;
  }
  //alert(opacity);
  opacity+=5;


  if(ele!=null && ele.nodeType!=3){
  if(navigator.appName.indexOf('Microsoft')!=-1){
  ele.style.filter = "alpha(opacity="+opacity+")";
  }else{
  ele.style.opacity = opacity/100;
  }
  ele.style.visibility = 'visible';
  
  if(opacity<100)
  {
    setTimeout("showFadedElement('"+ele1+"',"+opacity+")",20);
  }
  }else{

    $(ele1).style.visibility = 'visible';
  }
}




function loadSection(section, id, showProgress)
{
  var postData = new Array();
  var loadCMD = new ajax(section+'.php',id,postData);
  loadCMD.post('HTML_ELEMENT', showProgress);
}

function loadSection_NA(section, id, showProgress)
{
  var postData = new Array();
  var loadCMD = new ajax(section+'.php',id,postData);
  loadCMD.post('HTML_ELEMENT_NO_ANIME', showProgress);
}


function loadPage_WP(section, showProgress, postData)
{
  //loadSection(section, 'mainBody', showProgress, postData, 'HTML_ELEMENT');
  createForm(section,postData,'POST');
}

function loadSection_WP(section, id, showProgress, postData, loadType)
{
  var loadCMD = new ajax(section+'.php',id,postData);
  loadCMD.post(loadType, showProgress);
}

function loadPage_WA(section, action, postData)
{
  if(postData==undefined) postData = new Array();
  
  var loadCMD = new ajax(section+'.php', 'mainBody', postData);
  loadCMD.post('HTML_ELEMENT',true,action);
  
  
}

function loadCustomPage(id)
{
  var postData = new Array();
  postData['id'] = id;

  //var loadCMD = new ajax('custompage.php','mainBody',postData);
  //loadCMD.post('HTML_ELEMENT', true);
  
  createForm('custompage',postData,'POST');
}



function loadAlbumSec()
{
  if(arguments.length<1)
  {
    setTimeout("loadAlbumSec(1)",1500);
  }else{
  var url = window.location.href.split('#')[0];
  window.location.href = url + '#albumUploadContainer';
  }
}

function pageBrowse(section, page, postData)
{
  postData['start'] = page;
  loadPage_WP(section, true, postData);
}

function checkLogin()
{
  loadSection('memberBox','memberBox',false);
}

function tryLogin(frm)
{
  if(frm.username.value=='' || frm.password.value=='')
  {
    alert("Please enter username and password");
    return false;
  }
  var postData = new Array();
  postData['username'] = frm.username.value;
  postData['password'] = frm.password.value;
  postData['func'] = 'login';
  
  var callCMD = new ajax('functions.ajax.php','',postData);
  callCMD.post('FUNCCALL', true);
}

function logout()
{
  var postData = new Array();
  var loadCMD = new ajax('logout.php','',postData);
  loadCMD.post('FUNCCALL', true);
}

function callServer(func, _rid, callType)
{
  var postData = new Array();
  postData['func'] = func;
  
  switch(func)
  {
    case 'profileMenu':
        postData['UserId'] = curProfile;
    break;
  }
  
  var callCMD = new ajax('functions.ajax.php',_rid,postData);
  callCMD.post(callType, false);
}

function doPingServer()
{
  if($('profileMenu')){
  callServer('profileMenu','profileMenu','HTML_ELEMENT_NO_ANIME');
  }
  callServer('pingServer','','ALERT');
  callServer('checkMyStat','','FUNC_CALL');
}

function forgotPassword()
{
  var email = prompt("Please enter your email address");
  if(email)
  {
    var postData = new Array();
    postData['email'] = email;
    postData['func'] = 'forgotPass';
    var callCMD = new ajax('functions.ajax.php','',postData);
    callCMD.post('ALERT');
  }
}

function changePass()
{
	alert("People can see your password when you type! So make sure noone is near you.");
	var pass = prompt("Please enter your old password",'');
	if(pass)
	{
		var postData = new Array();
		postData['oldpass'] = pass;
		postData['func'] = 'chkOldPass';
		var callCMD = new ajax('functions.ajax.php','',postData);
		callCMD.post('FUNCCALL');
	}
}

function changeSkin(id)
{
	//loadPagehome('changeskin',true);
		window.location.href = "changeskin.php?userid="+id;
}

function newPass()
{
	var pass = prompt("Please enter your new password",'');
	var cpass = prompt("Please retype your new password to confirm it",'');
	
	if(pass==cpass && pass!='')
	{
		var postData = new Array();
		postData['Password'] = pass;
		postData['func'] = 'changePass';
		var callCMD = new ajax('functions.ajax.php','',postData);
		callCMD.post('FUNCCALL');
	}else
	{
		alert("Password Mismatch / Invalid password!");
	}
}


function reply(userid)
{
  startChat(userid);
}

function startChat(userid)
{
  //var topOffset = document.documentElement.scrollTop || document.body.scrollTop;
//return alert("Not Enabled Yet");
	var replyto = ''
	if(arguments.length==2)
	{
		replyto = "&reply="+arguments[1];
	}

	window.location.href = 'pm.php?uid='+userid+replyto;

  /*var totalChatBoxes=0;
  var chatBoxes = document.getElementsByTagName('div');
  for(cbs=0;cbs<chatBoxes.length;cbs++)
  {
    if(chatBoxes[cbs].getAttribute('id')!='undefined' && chatBoxes[cbs].getAttribute('id')!=null && chatBoxes[cbs].getAttribute('id')!='')
    {
      if(chatBoxes[cbs].getAttribute('id').indexOf('chatBox')!=-1)
      totalChatBoxes++;
    }
  }
  
  var cbTop = ((totalChatBoxes/2)*275);// || topOffset;
  
  
  var pos = new Array();
  pos.push(screen.width-270);
  pos.push(cbTop);
  var chatWindow = createWindow('chatBox'+userid,createEle('span','chatBox'+userid+'_title'),250,250,'floatPanel',pos,true);
  
  var textarea = document.createElement('div');
  textarea.style.height = '220px';
  textarea.style.fontFamily = 'Arial';
  textarea.style.fontSize = '12px';
  textarea.style.width = '243px';
  textarea.style.border = '1px solid #999999';
  textarea.style.color = '#222222';
  textarea.style.background = '#FFFFFF';
  textarea.style.overflowY = 'auto';
  textarea.style.textAlign = 'left';
  textarea.style.padding = '3px';
  textarea.id = 'history_'+userid;
  textarea.className = 'historyBox';
  
  chatWindow.appendChild(textarea);
  
  var nudge = document.createElement('a');
  nudge.href = 'javascript: nudgeUser('+userid+');';
  nudge.innerHTML = "<img src='./images/nudge.png' border='0' />";
  
  chatWindow.appendChild(nudge);
  
  var input = document.createElement('input');
  input.type = 'text';
  input.style.width = 170;
  input.className = 'messageSend';
  input.id = 'msgSend_'+userid;
  input.onkeyup = trySend;
  
  chatWindow.appendChild(input);
  
  
  var send = document.createElement('input');
  send.type = 'button';
  send.value = 'Send';
  send.style.fontSize = '10px';
  send.onclick = function()
  {
    sendMessage(input);
  }
  
  chatWindow.appendChild(send);
  
  var postData = new Array();
  postData['func'] = 'getChatWindowTitle';
  postData['to_id'] = userid;

  var sendMsgCMD = new ajax('functions.ajax.php','chatBox'+userid+'_title',postData);
  sendMsgCMD.post('HTML_ELEMENT_NO_ANIME',false);
  
  updateChatBox(userid,'chatBox'+userid);
  */
}


function trySend(e)
{
  if(!e) e = window.event;

  switch(e.keyCode)
  {
    case 13:
       var target = e.target || e.srcElement;
       sendMessage(target);
    break;
  }
}

function updateChatBox(userid,cbox)
{
  var postData = new Array();
  postData['func'] = 'updateChatBox';
  postData['to_id'] = userid;

  var sendMsgCMD = new ajax('functions.ajax.php','history_'+postData['to_id'],postData);
  sendMsgCMD.post('HTML_ELEMENT_NO_ANIME',false);
  
  if($('history_'+postData['to_id']))
  {
  if(!wndFocused && $('history_'+postData['to_id']).innerHTML!=oldMessages[postData['to_id']])
  {
     window.focus();
     document.title= $('chatBox'+userid+'_title').innerHTML.replace(/(<small>.*<\/small>[\s]*)/,'')+' says..';
  }
  
  if($('history_'+postData['to_id']).innerHTML!=oldMessages2[postData['to_id']])
  {
    $('history_'+postData['to_id']).scrollTop=100000;
    oldMessages2[postData['to_id']] = $('history_'+postData['to_id']).innerHTML;
    $('msgSend_'+postData['to_id']).focus();
  }
  

    setTimeout('updateChatBox('+userid+',"'+cbox+'")',1000);
  }
}

function sendMessage(obj)
{
  var postData = new Array();
  postData['func'] = 'saveChat';
  postData['to_id'] = obj.id.replace('msgSend_','');
  postData['message'] = obj.value;
  
  var sendMsgCMD = new ajax('functions.ajax.php','history_'+postData['to_id'],postData);
  sendMsgCMD.post('HTML_ELEMENT_NO_ANIME',false); //,"scrollHistory('history_"+postData['to_id']+"')");
  
  obj.value = '';
}

function scrollHistory(id)
{
  $(id).scrollTop = 99999;
}

function createEle(type,id)
{
  var ele = document.createElement(type);
  ele.id = id;
  
  return ele;
}

function nudgeUser(userid)
{
  var postData = new Array();
  postData['func'] = 'saveChat';
  postData['to_id'] = userid;
  postData['message'] = ':Nudge:';

  var sendMsgCMD = new ajax('functions.ajax.php','history_'+postData['to_id'],postData);
  sendMsgCMD.post('HTML_ELEMENT_NO_ANIME',false); //,"scrollHistory('history_"+postData['to_id']+"')");

}

function addFriend(userid)
{
  var postData = new Array();
  postData['func'] = 'addFriend';
  postData['frndid'] = userid;
  
  var sendRqstCMD = new ajax('functions.ajax.php','',postData);
  sendRqstCMD.post('FUNCCALL',false);
}

function removeFriend(userid)
{
  var postData = new Array();
  postData['func'] = 'removeFriend';
  postData['frndid'] = userid;

  var sendRqstCMD = new ajax('functions.ajax.php','',postData);
  sendRqstCMD.post('FUNCCALL',false);
}

function newFriendInvites(numOfInvites)
{
  var alrt = confirm("You have "+numOfInvites+" pending friend requests. Would you like to view them?");
  if(alrt)
  {
    loadPage('invites',true);
  }
}

function acceptFriend(userid)
{
   //addFriend(userid);
   var postData = new Array();
  postData['func'] = 'addFriend';
  postData['frndid'] = userid;
  
  var sendRqstCMD = new ajax('functions.ajax.php','',postData);
  sendRqstCMD.post('FUNCCALL',true,'loadPage("invites",true)');
}

function denyFriend(userid)
{
   removeFriend(userid);
}





function postFrm(frm, page)
{
  var ele = frm.elements;
  
   
  var postData = new Array();
  
  for(i=0; i<ele.length; i++)
  {
  	if(arguments.length>2)
  	{
			if(ele[i].value=='')
			{
				alert(ele[i].name.toUpperCase()+' cannot be blank!');
				return;
			}
		}
  
    if(ele[i].name!='' || ele[i].id!='')
    {
      postData[ele[i].name] = ele[i].value;
      ele[i].value = '';
    }
  }
  
  postData['func'] = page;
  
  var postCMD = new ajax('functions.ajax.php','',postData);
  postCMD.post('FUNCCALL',false);
}

function clearForm(frmName)
{
	var frm = document.forms[frmName];
	
	var ele = frm.elements;
	
	for(i=0;i<ele.length;i++)
	{
		if(ele[i].type=='text' || ele[i].nodeName.toUpperCase()=='TEXTAREA')
		{
			ele[i].value = '';
		}
	}
}

function shoutBoxReload(newShout)
{
  moveOut('shoutBox', newShout);
}

function moveOut(div, newText)
{
  div = $(div);
  var diff = 0;
  
  if(parseInt(div.style.left)<div.parentNode.offsetLeft+div.parentNode.offsetWidth){
    diff += parseInt(div.style.left);
    if(diff>=20) diff = 20;

  div.style.left = parseInt(div.style.left)+Math.round(diff);
  setTimeout("moveOut('"+div.id+"','"+newText.replace("'","\'")+"')",50);
  }else
  {
    div.innerHTML = newText;
    setTimeout("moveIn('"+div.id+"')",50);
  }
}

function moveIn(div)
{
  div = $(div);
  if(parseInt(div.style.left)>0){
    var diff = parseInt(div.style.left);
    if(diff>=50) diff = 20;
    else diff = diff/5;
  div.style.left = parseInt(div.style.left)-Math.round(diff);
  setTimeout("moveIn('"+div.id+"')",50);
  }else
  {
    setTimeout("loadSection('shoutbox','shoutBox',false)");
  }
}



function hiLight(anc)
{
  var siblings = anc.parentNode.getElementsByTagName('a');
  for(i=0; i<siblings.length; i++)
  {
    siblings[i].style.color = '#000000';
  }
  
  anc.style.color = '#599CC7';
}


function startShoutUpdate()
{
  var postData = [];
  var loadCMD = new ajax('shoutbox.php','',postData);
  loadCMD.post('FUNCCALL',false, 'fnShoutUpdate()');
}

function fnShoutUpdate()
{
		try{
		clearInterval(shoutUpdate);
		}catch(e){};
	  shoutUpdate = setInterval('loadSection("shoutboxrelay","shoutBox",false)',16000);
}



function submitForm(url,data,target)
{
	if(target==undefined) target='_self';
	frm = document.forms['tmp'];
	
	inp = "";
	
	for(i in data)
	{
		inp+="<input type='hidden' name='"+i+"' value='"+data[i]+"'/>";
	}
	frm.innerHTML = inp;
	frm.action = url;
	frm.target = target;
	frm.method = 'POST';
	frm.submit();
}

function viewPhoto(url,uid1)
{	
	window.location.href='album_viewer.php?img='+url+'&album='+curAlbum+'&uid='+uid1;
	
	return;
	//commenting below
  //var picFrame = preparePicFrame(640, 480);
  //picFrame = window.open('','photo',"width=800,height=600,scrollbars=1,resizable=1");
  var postData = {};
  postData['url'] = url;
  
  postData['uid'] = uid1;
  postData['album'] = curAlbum;
  postData['func'] = 'albumPhotoSection';
  
  curImage = url;
  
  submitForm('functions.ajax.php',postData,'photo');
  
  //var loadCMD = new ajax('functions.ajax.php',picFrame.document.body.innerHTML,postData);
  //loadCMD.post('OBJ_ELEMENT',true);
}

function viewGalPhoto(url)
{
  //var picFrame = preparePicFrame(800, 600);
  
  window.location.href='gallery_viewer.php?url='+url+'&catid='+catid;
	
	return;
  
  picFrame = window.open('','gallery',"width=800,height=600,resizable=1,scrollbars=1");
  var postData = {};
  postData['url'] = url;
  postData['catid'] = catid;
  postData['func'] = 'galPhotoSection';

  curImage = url;
	submitForm('functions.ajax.php',postData,'gallery');
  //var loadCMD = new ajax('functions.ajax.php','picHolder',postData);
  //loadCMD.post('HTML_ELEMENT',true);
}

function browse(page, postData)
{
  //var loadCMD = new ajax(page+'.php','mainBody',postData);
  //loadCMD.post('HTML_ELEMENT', true);
  createForm(page,postData,'POST');
}

function createForm(page, postData, method)
{
	var frm = document.forms['tmp'];
	frm.method = method;
	frm.action = page+'.php';
	var _t = [];
	for(i in postData)
	{
		var elm = "<input type='hidden' name='"+i+"' value='"+postData[i]+"'/>";
		frm.innerHTML +=elm;		
		_t.push(i+"="+postData[i]); 
	}
	
	frm.style.visibility = 'hidden';
	
	if(navigator.appVersion.indexOf('MSIE 6.0')!=-1)
	{
		if(window.event)
		{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		}
		window.location.href = page+".php?"+(_t.join('&'));
	}else
	{
		frm.submit();
	}
}


function insSmiley(icon)
{
	$('shout').value += icon;
}

function votePicture(voteBtn)
{
  var rates = voteBtn.parentNode.getElementsByTagName('input');
  var vote = 0;
  for(rateRadio = 0; rateRadio<rates.length; rateRadio++)
  {
    if(rates[rateRadio].type == 'radio' && rates[rateRadio].checked)
    {
       vote = rates[rateRadio].value;
       break;
    }
  }
  
  if(vote!=0)
  {
  var postData = new Array();
  postData['vote'] = vote;
  postData['userid'] = curProfile;
  postData['album'] = (arguments.length>1)?0:curAlbum;
  postData['url'] = curImage;
  postData['catid'] = catid;
  postData['func'] = 'votePic';
  
  var voteCMD = new ajax('functions.ajax.php','',postData);
  voteCMD.post('FUNCCALL',false);
  }else
  {
    alert("Please select some number to vote!");
  }
}

function hideVoteBar()
{
    //$('ratingBar').innerHTML = 'Thank you for voting!';
    
    $('voter').innerHTML = '';
    $('voter').style.display = 'none';
}


function preparePicFrame(w, h)
{
  var pos = new Array();
  pos.push(screen.width/2 - 320);
  pos.push(1);
  
  var picWindow = createWindow('picBox',createEle('span','picBox_title'),w,h,'picPanel',pos,true);
  var ratingBar = document.createElement('div');
  ratingBar.align = 'center';
  ratingBar.id = 'ratingBar';
  ratingBar.style.width = '100%';
  ratingBar.style.display = 'block';
  for(rateRadio = 1; rateRadio<=10; rateRadio++)
  {
      var rate = document.createElement('input');
      rate.type = 'radio';
      rate.value = rateRadio;
      rate.name = 'picRating';
      rate.style.border = 'none';
      rate.onclick = function()
      {
        this.checked = true;
      }
      var rateTxt = document.createTextNode(rateRadio);
      ratingBar.appendChild(rate);
      ratingBar.appendChild(rateTxt);
  }
  
  var vote = document.createElement('input');
  vote.type = 'button';
  vote.value = 'Vote!';
  vote.onclick = function()
  {
     votePicture(this);
  }
  ratingBar.appendChild(vote);
  
  var picHolder = document.createElement('div');
  picHolder.align = 'center';
  picHolder.style.width = '100%';
  picHolder.id = 'picHolder';
  
  picWindow.appendChild(ratingBar);
  picWindow.appendChild(picHolder);
  
  return picWindow;
}


function pChatSend()
{
  var postData = [];
  postData['txt'] = $('pChatTxt').value;
  postData['func'] = 'pChatSend';
  
  $('pChatTxt').value = '';
  
  var sendCMD = new ajax('functions.ajax.php','',postData);
  sendCMD.post('FUNCCALL',false);
}

function getChatNick()
{
  var pmpt = prompt("Please enter your nick name!");
  if(pmpt)
  {
    var postData = [];
    postData['nick'] = pmpt;
    postData['func'] = 'setNick';
    
    var sendCMD = new ajax('functions.ajax.php','',postData);
    sendCMD.post('FUNCCALL',false);
  }else
  {
    loadPage('home',true);
  }
}

function startSpot(ary)
{
	try{if(spotptr);}catch(e){spotptr = 0;}
	
	if(ary.length){
	$('denspot').innerHTML = "<a href='"+ary[spotptr][1]+"'><img src='gd.php?image="+ary[spotptr][1]+"&max=125' border=2 style='border-color:#fff;'/></a>"
														+"<br><a href='"+ary[spotptr][1]+"'>"+ary[spotptr][0]+"</a>";
	
		if(spotptr<ary.length-1)
		{
				spotptr++;
		}else
		{
			spotptr = 0;
		}
	}
	setTimeout(function(){
		startSpot(ary);
	},15000);
	

}


window.onblur = function()
{
  wndFocused = false;
  var chatBoxes = document.getElementsByTagName('div');
  for(cbs=0;cbs<chatBoxes.length;cbs++)
  {
    if(chatBoxes[cbs].getAttribute('id')!='undefined' && chatBoxes[cbs].getAttribute('id')!=null && chatBoxes[cbs].getAttribute('id')!='')
    {
      if(chatBoxes[cbs].getAttribute('id').indexOf('chatBox')!=-1)
      {
        var aryIndex =  chatBoxes[cbs].getAttribute('id').replace('chatBox','');
        if($('history_'+aryIndex))
        oldMessages[aryIndex] = $('history_'+aryIndex).innerHTML;
      }
    }
  }
}

window.onfocus = function()
{
  wndFocused = true;
  document.title = 'Awortinkos';
}
