/*
  (C) 2007 MyCampusLife Productions for MyUTLife.com
  No part of this file may be reproduced without EXPLICIT
  permission from the author: Wes Alvaro
  Contact : aych ee ell ell oh _at_ doubleyou ee ess ay ell vee ay are oh _dot_ com
*/
//var myutl = object();
//myutl.nextStep = function(params){
function nextStep(params){
  page = '/content/valid.php?v=create';
  Request('create',page,params);
  return false;
}
function helpWin(task){
  page = '/content/valid.php?v=help&task='+task;
  window.open(page,'help','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=600,height=400');
}
function picUpload(type,id){
  page = '/content/uploader.php?getType='+type
  if(id) page = page + '&getID='+id;
  window.open(page,'pics','status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=700,height=450');
}
function create(what,id){
  page = '/content/valid.php?v=create';
  Request('create',page,'what='+what+'&id='+id);
  Effect.Appear('create');
}
function selectCheck(){
  $('selected').innerHTML='Continue to the next step';
  $('next').disabled=false;
}
function updateDiv(div, action, spif){
  if (spif){
    new Effect.SlideUp(div);
    new Ajax.Updater(div, action, {method:'get', onComplete:function(){ new Effect.SlideDown(div);},asynchronous:true});
  } else {
    new Ajax.Updater(div, action, {method:'get', asynchronous:true});
  }
  return false;
}
function UPE(action, pid){
  action = '/content/valid.php?v=p&task='+action+'&pid='+pid;
  //new Effect.BlindUp('pEX');
  // , onComplete:function(){ new Effect.SlideDown('pEX');}
  new Effect.ScrollTo('pEX');
  new Ajax.Updater('pEX', action, {method:'get',asynchronous:true});
  return false;
}
/*function UM(action, pid){
  action = '/content/valid.php?v=p&task='+action+'&pid='+pid;
  new Ajax.Updater('main', action, {method:'get',asynchronous:true});
  return false;
}*/
function inPlaceProfileEdit(pid, field, r){
  if (!r)
    new Ajax.InPlaceEditor(field, '/content/edit.php?v=p&task=change&change='+field+'&pid='+pid);
  else
    new Ajax.InPlaceEditor(field, '/content/edit.php?v=p&task=change&change='+field+'&pid='+pid, { rows: r } );
}

function profileChanges(pid){
  inPlaceProfileEdit(pid, 'class', 0);
  inPlaceProfileEdit(pid, 'hometown', 0);
  inPlaceProfileEdit(pid, 'homestate', 0);
  inPlaceProfileEdit(pid, 'info', 10);
  inPlaceProfileEdit(pid, 'quotes', 10);
  inPlaceProfileEdit(pid, 'movies', 10);
  inPlaceProfileEdit(pid, 'books', 10);
  inPlaceProfileEdit(pid, 'bday', 0);
}
function hideMe(id){
  Effect.Fade(id);
}
/******************************************************
 * Make the lockout blackbox
 *****************************************************/
var drag;
clearUp = function (){
  $('coverall').innerHTML = '';
  Effect.Appear('dialogue', { duration: 0.5});
  drag = new Draggable('dialogue',{scroll:window,handle:'handle'});
}
function whiteout(){
  Effect.Fade('dialogue', { duration: 0.5 });
  Effect.Fade('coverall', { duration: 0.5, queue: 'end' });
  drag.destroy();
}
function getPageScroll(){
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}	
	pageHeight = ((yScroll < windowHeight)?windowHeight:yScroll);
	pageWidth  = ((xScroll < windowWidth)?xScroll:windowWidth);
	return new Array(pageWidth,pageHeight,windowWidth,windowHeight)
}
function blackout(page, x){
  $('coverall').innerHTML = 'Loading...';
	var pageSize = getPageSize();
	$('coverall').style.width =  pageSize[0]+'px';
	$('coverall').style.height = pageSize[1]+'px';
	new Effect.Appear('coverall', { duration: 0.5 });
	var pageScroll = getPageScroll();
	var convTop = pageScroll[1] + (pageSize[3] / 10);
	var convLeft = pageScroll[0]+40;
	$('dialogue').style.top = convTop+'px';
	$('dialogue').style.left = convLeft+'px';
  if (!page) page = 'content/valid.php?v=u&action=login';
  if (x) $('dialogue').style.width = x+'px';
  new Ajax.Updater('dialogue-text', page, { method: 'get', onComplete: function() {clearUp();} });
}
function showMsg(id, tofro){
  getRequest('msg','content/valid.php?v=p&task=messages&show='+id+'&dir='+tofro);
  if($('title'+id).style.fontWeight == 'bold') 
    $('title'+id).style.fontWeight = '';
}
function msgDel(id, archive){
  showAlert('', 'info', 'msgAlert');
  getRequest('msgAlert','content/valid.php?v=p&task=messages&del='+id+((archive)?'&archive':''));
}
function msgReply(name, id){
  if ($('reply').innerHTML != '') $('reply').innerHTML = '';
  else getRequest('reply','content/valid.php?v=p&task=messages&slim&inline&box=compose&to='+id+'&name='+name);
}
function sendMessage(params){
  showAlert('Sending Message...', 'info', 'result');
  Request('result', 'content/valid.php?v=p&task=messages&send=true', params);
}
function showBox(id, page){
  if(!page) page=0;
  req = 'content/valid.php?v=p&task=messages&slim&box='+id+'&page='+page;
  getRequest('box',req);
}
function multMsgDel(ids, archive){
  if(!ids.length){
    alert ('Please select some messages, first.');
    return;
  }
  showAlert('Working...', 'info', 'boxact');
  action = '/content/valid.php?v=p&task=messages';
  if (archive) action += '&archive'; 
  getRequest('boxact', action, ids);
  ids = '&'+ids;
  ids = ids.split('&del%5B%5D=');
  var style = ((archive)?'overline':'line-through');
  for (var i = 0; i < ids.length; i++){
    if(ids[i] == '') continue;
    if($('title'+ids[i]).style.textDecoration.indexOf(style) == -1)
      $('title'+ids[i]).style.textDecoration += ' '+style;
    else $('title'+ids[i]).style.textDecoration = '';
  }
}
function emptyTrash(){
  showAlert('Emptying Trash...', 'info', 'boxact');
  if(confirm('Do you really want to empty your trash bin?\n (This cannot be undone.)'))
  getRequest('boxact','/content/valid.php?v=p&task=messages&emptytrash')
  else showAlert('Cancelled', 'info', 'boxact');
}
/****************************************************************
 *  Request methods for grabbing a page and updating an id.
 *  GET and POST methods available with:
 *    ID, PAGE, PARAMS   
 **************************************************************/ 
function getRequest(id, page, params){
    $(id).innerHTML = 'Loading...';
    if (params)
      new Ajax.Updater(id, page, { method: 'get', parameters: params, asynchronous:true, evalScripts:true});
    else
      new Ajax.Updater(id, page, { method: 'get', asynchronous:true, evalScripts:true});
    return false;
}
function Request(id, page, params){
    $(id).innerHTML = 'Loading...';
    new Ajax.Updater(id, page, { method: 'post', parameters: params, asynchronous:true, evalScripts:true});
    return false;
}
var working = 0;
var id = 1;
function appendReview(params){
  if (working){
    alert('Please wait for previous request to complete');
    return false;
  }
  working = 1;
	var d = document.createElement('div');
	d.innerHTML = 'Loading...';
	d.id = 'r'+ (id++);
  $('reviews').appendChild(d);
  getRequest(d.id, '/content/edit.php', params);
  working = 0;
  Effect.Fade('commentForm');
  return false;
}

/**********************
 * Load options
 * ******************/ 
function loadOpts(page, params){
  id = 'useropts';
  $(id).innerHTML = 'Loading';
  new Effect.ScrollTo(id);
  if(!page) page = 'content/edit.php?v=ao';
  else page = '/content/'+page;
  Element.show(id);
  new Ajax.Updater(id, page, { method: 'get', parameters: params, asynchronous:true, evalScripts:true}); 
}
function showAlert(info, type, id){
  if(!id) id = 'alert';
  new Effect.ScrollTo(id);
  $(id).innerHTML = info;
  Element.show(id);
  $(id).className = type;
}
function deleteThis(task,v,id){
  loadOpts('delete.php?v='+v+'&task=del'+task+'&id='+id);
}
function narrowResults(params, page){
  if(!page) page = 'content/filter.php?task=narrow&what=food';
  new Ajax.Updater('results', page, { method: 'get', parameters: params, asynchronous:true, evalScripts:true});
}
function swapFeature(source){
  $('feature').src = source;
  new Effect.ScrollTo('feature'); return false;
}


