
var confirmPopup = function(mess,callback){
		
		if (typeof callback != 'function') {
			var follow=callback;
			callback = function() { window.location.href = follow; }
		}
		
		jqN('#DMI_header').before('<div class="sn_alert_pop"  style="display:none" id="sn_alert_popID">'+mess+'<span id="close-style-box">X</span><p><form><input type="button" id="sn_alert_button_yes" value="Yes" />&nbsp;<input type="button" id="sn_alert_button_no" value="No" /></form></p></div>')
		jqN('.sn_alert_pop').fadeIn('fast');
		jqN('#close-style-box').click(function(){jqN('.sn_alert_pop').remove();});
		jqN('#sn_alert_button_yes').click(function(){jqN('.sn_alert_pop').remove();callback();return true;});
		jqN('#sn_alert_button_no').click(function(){jqN('.sn_alert_pop').remove();});

}


var sendAlert = function(mess, typeOf, timing){
		jqN(".sn_alert_pop").remove();
		jqN(".sn_alert_pop2").remove();
		if (typeOf == 'good') {
			jqN('#DMI_header').before('<div class="sn_alert_pop" style="display:none"  id="sn_alert_popID"><div id="sn_alert_messages">'+mess+'</div><span id="close-style-box">X</span></div>')
			jqN('.sn_alert_pop').fadeIn('slow').animate({opacity: 1.0}, timing).fadeOut('slow', function(){if(this.parentNode){jqN(this).remove();}});
		}
		else if (typeOf == 'bad') {
			jqN('#DMI_header').before('<div class="sn_alert_pop2"  style="display:none"  id="sn_alert_popID"><div id="sn_alert_messages">'+mess+'</div><span id="close-style-box">X</span></div>')
			jqN('.sn_alert_pop2').fadeIn('slow').animate({opacity: 1.0}, timing).fadeOut('slow', function(){if(this.parentNode){jqN(this).remove();}});
		}
		jqN('#close-style-box').click(function(){jqN('#sn_alert_popID').remove()})
}


//count remaining characters.
//expects Element ids instead of field names in a form.
//expects 2 fields one which is the data field where the user enters his data and the other field keeps track of the number of character that's left from the maxLimit.
//the second field could be changed into a mere div which can be updated at a later stage.
//truncates the field at maxLimit - in effect disallows user from entering more than maxLimit characters.
function sn_textCounter(sourceField, charCountField, maxLimit)
{

	  var field = document.getElementById(sourceField);
	  var counter = document.getElementById(charCountField);
	  if (field.value.length > maxLimit) 
	  {	  
		  field.value =field.value.substring(0, maxLimit);
	  }
	  else
	  {
		  counter.value = maxLimit - field.value.length;
	  }

}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

