var KEY_NULL = null;
var KEY_NONE = 0;
var KEY_BCKSPC = 8;
var KEY_TAB = 9;
var KEY_ENTER = 13;
var KEY_ESC = 27;
var KEY_SPACE = 32;

function getSliderText(sValue,eValue)
{
	var sm  = parseInt(sValue / 60);
	var ss  = sValue - (parseInt(sValue / 60) * 60 );
	var em  = parseInt(eValue / 60);
	var es  = eValue - (parseInt(eValue / 60) * 60 );
	if (sm < 10 )
	{
		sm = '0' + sm;
	}
	if (ss < 10 )
	{
		ss = '0' + ss;
	}
	if (em < 10 )
	{
		em = '0' + em;
	}
	if (es < 10 )
	{
		es = '0' + es;
	}
	return 'From <span>'  + sm + ':'  + ss  +  '</span> - To <span>' + em  + ':'  + es + '</span>';
}
function loadAudioContent(eid,id)
{
	var start = jQuery("#slider").slider("values", 0);
	var end = jQuery("#slider").slider("values", 1);
	var timestamp_id = new Date().getTime();
	jQuery("#audiocontent").load("index.php?option=com_rsevents&task=showmp3flashcontent&controller=events", {cid : eid,fstart:start,fend:end,timestamp :timestamp_id},function(responseText, textStatus, XMLHttpRequest){
			 });
}

function expandoption(ele)
{
	if (jQuery(ele).parent().children(".optiondetails").is(":hidden"))
	{
		jQuery(".mp3SoundClip .optionlist .optiondetails").slideUp();
		jQuery(ele).parent().children(".optiondetails").slideDown();
	}
}
function clipsoundpart(eid)
{
	/*
	var start = jQuery("#slider").slider("values", 0);
	var end = jQuery("#slider").slider("values", 1); */


	var start = jQuery("#starttime").val();
	var end = jQuery("#endtime").val();
	var timestamp_id = new Date().getTime();
	jQuery("#audiocontent").load("index.php?option=com_rsevents&task=showmp3flashcontent&controller=events", {cid : eid,fstart:start,fend:end,timestamp :timestamp_id},function(responseText, textStatus, XMLHttpRequest){ 
				if (textStatus == "success")
				{
					jQuery(".optioncontent").slideDown();
					jQuery("#hstart").val(start);
					jQuery("#hend").val(end);
				}
			 });
}
function doOption1(eid)
{
	var start = jQuery("#hstart").val();
	var end  = jQuery("#hend").val();
	var timestamp_id = new Date().getTime();
	var comment = jQuery("#opt1comment").val();

	jQuery.get("index.php?option=com_rsevents&task=savesoundbyte&controller=events", {cid : eid,fstart:start,fend:end,timestamp :timestamp_id,fcomment:comment},function(responseText, textStatus, XMLHttpRequest){ 
		if (textStatus == "success")
		{
			if (responseText == "error")
			{
				location.replace('index.php?option=com_user&view=login&Itemid=137');
			}
			else
			{
				showSoundClipMsg("Download link successfully sent to user email ID.");
			}
		}
	 });
}

function doOption2(eid)
{

	var start = jQuery("#hstart").val();
	var end  = jQuery("#hend").val();
	var timestamp_id = new Date().getTime();
	var comment = jQuery("#opt2comment").val();

	jQuery.get("index.php?option=com_rsevents&task=sendsoundbytemyself&controller=events", {cid : eid,fstart:start,fend:end,timestamp :timestamp_id,fcomment:comment},function(responseText, textStatus, XMLHttpRequest){ 
		if (textStatus == "success")
		{
			if (responseText == "error")
			{
				location.replace('index.php?option=com_user&view=login&Itemid=137');
			}
			else
			{
				showSoundClipMsg("Sound Clip link successfully sent to user email ID.");
			}
		}
	 });
}

function doOption3(eid)
{

	var start = jQuery("#hstart").val();
	var end  = jQuery("#hend").val();
	var timestamp_id = new Date().getTime();
	var comment = jQuery("#opt3comment").val();
	var email = jQuery("#opt3email").val();

	jQuery.get("index.php?option=com_rsevents&task=sendsoundbytefriend&controller=events", {cid : eid,fstart:start,fend:end,timestamp :timestamp_id,femail:email,fcomment:comment},function(responseText, textStatus, XMLHttpRequest){ 
		if (textStatus == "success")
		{
			if (responseText == "error")
			{
				location.replace('index.php?option=com_user&view=login&Itemid=137');
			}
			else
			{
				showSoundClipMsg("Sound Clip link successfully sent to your friend's email ID.");
			}
		}
	 });
}

function showSoundClipMsg(msgtext)
{
	jQuery("#soundclipmsg").html(msgtext);
		jQuery("#soundclipmsg").fadeIn(2000,function() {
				jQuery("#soundclipmsg").fadeOut(2000);
		  });		
}

function numbersOnly(e,ele,zeroValueAllow)
{
	var key;
	var keychar;
	
	if (window.event) 
	{
		key = window.event.keyCode;
	}
	else if (e) 
	{
		key = e.which;
	}
	else
	{
		return true;
	}

	keychar = String.fromCharCode(key);

	// for Ctrl + R  		
	if (e.ctrlKey && ( keychar == 'R' || keychar == 'r' ))
	{
		return true;
	}
	// Control keys (no @#$% "magic numbers")
	if ((key == KEY_NULL) ||  (key == KEY_NONE) || (key == KEY_BCKSPC) || (key == KEY_TAB) || (key == KEY_ENTER) || (key == KEY_ESC) )
	 {
		return true;
	 }
	else 
	{ 
		var val =  document.getElementById(ele).value;
		if (zeroValueAllow)
		{
			if ( val.length == 0 )
			{
				if (keychar == '0' )
					return true;

			}
			if (("0123456789").indexOf(keychar) > -1 )
			{
				return true;
			}
		}
		else
		{
			if (keychar == '0' )
			{		
					if ( val.length == 0 )
						return false;	
					else
						return true;
			}
			else if (("123456789").indexOf(keychar) > -1 )
			{
				return true;
			}
		}
		
	}
	return false;
}
function putText(ele,zeroValueAllow)
{
	 var val =  document.getElementById(ele).value;
	 var newval = val;
	 
	//newval =  ltrim(val,'0');
	if (zeroValueAllow)
	{

		 if (val == 0 || val == '')
			newval = '0';
		 else
			newval =  ltrim(val,'0');
	}
	else
	{
		newval =  ltrim(val,'0');
	}

	document.getElementById(ele).value = newval;	
	
}
function trim(str, chars) 
{
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) 
{
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

