// JavaScript Document


function clear_label(fieldname){
	if (fieldname.defaultValue == fieldname.value)
		fieldname.value = '';
    else if (fieldname.value == '')
		fieldname.value = fieldname.defaultValue;
}
	
function clearTextarea(id, contents) {	

	if (  $(id).value == contents ) {	
		 $(id).value = "";	
	
	}
}

function checkTextarea(id,  contents) {	
	if (  $(id).value == "" ||  $(id).value == null ) {	
		 $(id).value = contents;	
	}
}


/*
function report_comment(comment_class,comment_id){
	var report_comment_link = 'report_comment_' + comment_id;
	
	new Ajax.Request('AJAX/report_comment.html',{
			method: 'POST',
			parameters: {comment_class: comment_class,
						 comment_id: comment_id}
	});
	toggle_reported_comment_view(comment_id);
	$(report_comment_link).hide();
}
*/



function mail_article(from_name,to_address,news_article_id){

	new Ajax.Request('AJAX/mail_article.php',{
			method: 'POST',
			parameters: {from_name: from_name,
						 to_address: to_address,
						 news_article_id: news_article_id},
			onSuccess: function(transport){
					if(transport.responseText == 'sent'){						
						$('share_success').show();
						$('share_error').hide();
						$('sharee_email').value = "";
						$('sharee_email').focus();
						
					}
					else if(transport.responseText == 'unsent'){
						$('share_success').hide();
						$('share_error').show();
					}
			}			
	});
	
}


function mail_force_article(from_name,to_address,news_article_id){
	new Ajax.Request('AJAX/mail_force_article.php',{
			method: 'POST',
			parameters: {from_name: from_name,
						 to_address: to_address,
						 news_article_id: news_article_id},
			onSuccess: function(transport){
					if(transport.responseText == 'sent'){						
						$('share_success').show();
						$('share_error').hide();
						$('sharee_email').value = "";
						$('sharee_email').focus();
						
					}
					else if(transport.responseText == 'unsent'){
						$('share_success').hide();
						$('share_error').show();
					}
			}			
	});
}

function mail_caper_article(from_name,to_address,caper_id){
	new Ajax.Request('AJAX/mail_caper.php',{
			method: 'POST',
			parameters: {from_name: from_name,
						 to_address: to_address,
						 caper_id: caper_id},
			onSuccess: function(transport){
					if(transport.responseText == 'sent'){						
						$('share_success').show();
						$('share_error').hide();
						$('sharee_email').value = "";
						$('sharee_email').focus();
						
					}
					else if(transport.responseText == 'unsent'){
						$('share_success').hide();
						$('share_error').show();
					}
			}			
	});
}

function modalFetch() {
	
		$('modal').style.display = "block";
		$('modal').style.width = document.viewport.getDimensions().width + "px";
		$('modal').style.height = document.viewport.getDimensions().height + "px";
		$('modal_data').style.height = document.viewport.getDimensions().height - 100 + "px";			
		Effect.BlindDown('modal_data', { duration: 0.5 });	
		
		loadingIcon("modal_data", 20, "Fetching Data...");				
	}
	
function loadingIcon(id, heightOffset, wording) {

	$(id).innerHTML = "<div style=\"color: #cccccc; text-align: center; padding-top: " + heightOffset + "px;\"><img src=\"images/loading.gif\" /><br /><br />" + wording + "</div>";

}


	function inspect(obj, maxLevels, level)
	{
	  var str = '', type, msg;
	
		// Start Input Validations
		// Don't touch, we start iterating at level zero
		if(level == null)  level = 0;
	
		// At least you want to show the first level
		if(maxLevels == null) maxLevels = 1;
		if(maxLevels < 1)     
			return '<font color="red">Error: Levels number must be > 0</font>';
	
		// We start with a non null object
		if(obj == null)
		return '<font color="red">Error: Object <b>NULL</b></font>';
		// End Input Validations
	
		// Each Iteration must be indented
		str += '<ul>';
	
		// Start iterations for all objects in obj
		for(property in obj)
		{
		  try
		  {
			  // Show "property" and "type property"
			  type =  typeof(obj[property]);
			  str += '<li>(' + type + ') ' + property + 
					 ( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';
	
			  // We keep iterating if this property is an Object, non null
			  // and we are inside the required number of levels
			  if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
			  str += inspect(obj[property], maxLevels, level+1);
		  }
		  catch(err)
		  {
			// Is there some properties in obj we can't access? Print it red.
			if(typeof(err) == 'string') msg = err;
			else if(err.message)        msg = err.message;
			else if(err.description)    msg = err.description;
			else                        msg = 'Unknown';
	
			str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
		  }
		}
	
		  // Close indent
		  str += '</ul>';
	
		return str;
	}

function valueCheck(action, id, defaultText) {
   
    switch (action) {
       
        case "focus":
       
        if ( document.getElementById(id).value == defaultText) {
       
            document.getElementById(id).value = "";
        }
       
        break;
       
        case "blur":
       
        if ( document.getElementById(id).value == "") {
       
            document.getElementById(id).value = defaultText;       
       
        }
       
        break;
       
    }
   
}
