initAdvancedForm();
var Tablinks;
var CustomUpload;
var CustomUploadInput;
var CustomUploadName;
var CommentForm;
function initAdvancedForm()
{
	CommentForm = document.getElementById("commentform");
	
	// init tabs
	/*
	document.getElementById("guest_anchor").style.fontWeight='bold';	

	Tablinks = document.getElementById("tablinks").getElementsByTagName("A");
	for(var i=0; i < Tablinks.length; i++)
	{
		Tablinks[i].onclick = changeFormTab;		
		//Tablinks[i].onclick = function(){ return false; };
	}
	*/
	
	// init other links
	var Links = CommentForm.getElementsByTagName("A");
	for(var i=0; i < Links.length; i++)
	{
		var rel = Links[i].getAttribute("rel");
		if (!rel) continue;
		if (rel.match(/^commentsize\:.*$/i))
		{
			Links[i].onmousedown = startCommentResize;
			Links[i].onmouseup = endCommentResize;
		}
	}
	
	/*
	CustomUpload = document.getElementById("customUpload");
	CustomUploadInput = CustomUpload.getElementsByTagName("INPUT")[0];
	CustomUploadName = document.getElementById("UploadedFile");
	
	if(document.all) { //IE
		CustomUpload.onmousemove = moveUploadInput;
	}
	else {
		if (window.addEventListener){
			CustomUpload.addEventListener("mousemove", moveUploadInput, false);
		}
		else if (window.attachEvent){
			CustomUpload.attachEvent("mousemove", moveUploadInput);
		}
	}
	
	CustomUploadInput.onchange = uploadUserImage();
	//pa(CustomUploadInput);
	//CustomUpload.onmousemove = moveUploadInput;
	//CustomUpload.mousemove = moveUploadInput;
	*/
}

function activeLoginTab() {
	$('guest_anchor').style.fontWeight='normal';$('existinguser_anchor').style.fontWeight='bold';$('newuser_anchor').style.fontWeight='normal';$('guestuser').hide();$('exuser').show();return false;
}


function changeFormTab()
{
	disableTabLinks();
	this.className = 'active';	
	var rel = this.getAttribute("rel");
		
	if( rel == 'newuser' )
	{		
		$('guest_anchor').style.fontWeight='normal';
		$('existinguser_anchor').style.fontWeight='normal';
		$('newuser_anchor').style.fontWeight='bold';
		$('guestuser').show();
		$('exuser').hide();
		$('newuseraddon').style.display = 'block';
		$('is_guest').value = '0';
	}
	
	if( rel == 'guest' )
	{		
		
		$('guest_anchor').style.fontWeight='bold';
		$('existinguser_anchor').style.fontWeight='normal';
		$('newuser_anchor').style.fontWeight='normal';
		$('exuser').hide();
		$('guestuser').show();
		$('newuseraddon').hide();
		$('is_guest').value = '1';
	}
	
	if( rel == 'existinguser' )
	{		
		$('exuser').style.display = 'block';
		$('guest_anchor').style.fontWeight='normal';
		$('existinguser_anchor').style.fontWeight='bold';
		$('newuser_anchor').style.fontWeight='normal';
		$('guestuser').hide();
		$('newuseraddon').hide();
		$('is_guest').value = '1';
	}
	
	return false;
}

function disableTabLinks()
{
	for(var i=0; i < Tablinks.length; i++)
	{
		Tablinks[i].className = "";
	}
}

function moveUploadInput(ev)
{
	var IE = (document.all)? true : false;
	var tempX = 0;
	var tempY = 0;
	
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.offsetX;
    tempY = event.offsetY;
  } else {  // grab the x-y pos.s if browser is NS
  	//pa(ev);
    tempX = ev.layerX;
    tempY = ev.layerY;
  	//alert(ev.layerX);
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

	var s = 'X=' + tempX +  ' Y=' + tempY;
	CustomUploadName.innerHTML = s;
	
	CustomUploadInput.style.top = (tempY - 10) + "px";
	CustomUploadInput.style.left = (tempX - 90) + "px";
}

/*
* comment resizing
*/
var comment_resizing = false;
function startCommentResize()
{
	var rel = this.getAttribute("rel");
	var values = rel.match(/^commentsize\:(.*)$/i);
	
	comment_resizing = true;
	commentResize( values[1] );
	return false;
}
function endCommentResize()
{
	comment_resizing = false;
	return false;
}
function commentResize( dir )
{
	var comment = document.getElementById('comment');
	var current_height = parseInt(comment.offsetHeight);
	if ( dir == 'inc' ) {
		comment.style.height = (current_height + 5) + "px";
	}
	if ( dir == 'dec' && current_height > 100 ) {
		comment.style.height = (current_height - 5) + "px";
	}
	
	if(comment_resizing) {
		setTimeout("commentResize('"+dir+"');", 50);
	}
}


/*
* pa function
*/
function pa( obj )
{
	if(!obj || typeof(obj) != 'object') {
		var _type = typeof(obj);
		if(_type == 'undefined') {
			alert("["+_type+"]");
		}
		else {
			var _output = "[" + _type + "] => `" + obj + "`";
			alert(_output);
		}
		return;
	}
	
	var 
		_output = "\t OBJECT PROPERTIES: \n"; 
		separator = "";
		spacer = "";
		i = 0;
	
	try{
		for( var _key in obj ) {
			if((i % 2) == 1){ separator = "\n"; spacer = "\t\t"; }
			else{ separator = ""; spacer = ""; };
			
			_output += spacer + "[" + _key + '] => `' + obj[_key] + '`' + separator;
			++i;
		}
	}
	catch(err){ 
		_output += "Can't get properties for: " + obj;
	}
	
	alert(_output);
}