<!---------------------------------------------------------------------->
<!------------------ Returns current date for the User ----------------->
<!---------------------------------------------------------------------->

function getDateTimeInViewFormat(field)
{
	time_field = field.split(" ");
	var date_value = time_field[0];
	var time_value = time_field[1];

	var split_time_value = time_value.split(":");

	var dates = date_value.split("-");
	var month_of_date = dates[2];
	if(month_of_date.length == 3)
	month_of_date = month_of_date.substring(0,2);

	var seconds = split_time_value[2];
		split_seconds = seconds.split(".");

	var second_data = "00";
	if(split_seconds.length > 1)
		second_data = split_seconds[0];

	return month_of_date+"-"+getFullMonth(dates[1])+"-"+dates[0]+" "+split_time_value[0]+":"+split_time_value[1]+":"+second_data;
}

function getDateInFormat(field)
{
	field = field.split("-");
	var month_of_date = field[2];

	if(month_of_date.length == 3)
	  month_of_date = month_of_date.substring(0,2);

	return month_of_date+"-"+getFullMonth(field[1])+"-"+field[0];
}

function deleteTableRows(tableId,upto)
{
    var init = eval(tableId+".rows.length");

    if(init >= 1)
    {
    	if(upto == 0)
    	{
    	    for(var i=init;i>0;i--)
    	    {
    	        eval(tableId+".deleteRow("+(i - 1)+")");
    	    }
    	}
    	else if((upto == null) || (upto == ""))
    	{
    	    for(var i=init;i>1;i--)
    	    {
    	        eval(tableId+".deleteRow("+(i - 1)+")");
    	    }
    	}
    }
}

function avoidDuplicate(arrayValue)
{
   newActivity = new Array();
   var k = 0;

	for(var a=0;a<arrayValue.length;a++)
	{
		for(var b=parseInt(a)+1;b<arrayValue.length;b++)
		{
			if(arrayValue[a] == arrayValue[b])
			{
			  arrayValue[a] = "nil";
			}
		}

		if(arrayValue[a] != "nil")
		{
		    newActivity[k] = arrayValue[a];
		    k++;
		}
	}

  return newActivity;
  }

// if num is null then it will delete the options from the 1st position.

// if num is 0 then it will delete the options from the 0th position.

function optionDelete(option_list_object,num)
{
	var selectcount=option_list_object.options.length;
	if(num == 0)
	{
		for(k=selectcount-1;k>=0;k--)
		{
			option_list_object.options[k]=null;

		}
	}
	else
	{
		if(selectcount > 1)
		{
			for(k=selectcount-1;k>0;k--)
			{
				option_list_object.options[k]=null;
			}
		}
	}
}


function generateSort(elap_array)
{
 	for(var x=0;x<elap_array.length;x++)
 	{
 	     for(var y=parseInt(x+1);y<elap_array.length;y++)
 	     {
 	     	if(elap_array[x] > elap_array[y])
 	      	{
 	      	   temp_min = elap_array[x];
 	      	   elap_array[x] = elap_array[y];
 	      	   elap_array[y] = temp_min;
 	      	}
 	     }
 	}
 	return elap_array;
}


function getTotalDays(st_month,ed_month)
{
    var tot = 0;
	for(var i=eval(parseInt(st_month));i<eval(parseInt(ed_month));i++)
	{
		tot += getDaysOfMonth(i);
	}

	return tot;
}

function Check_Leap(Year)
{
     if(Year%4==0)
		return 29;
     else
		return 28;
}

function getDaysOfMonth(Month,Year)
{
	var totaldays = 30;

	switch(Month)
	{
	   case 1:
	   {
				totaldays=31;
				break;
			}
	   case 2:
	   {
				totaldays=Check_Leap(Year);
				break;
			}
	   case 3:
	   {
				totaldays=31;
				break;
			}
	   case 4:
	   {
				totaldays=30;
				break;
			}
	   case 5:
	   {
				totaldays=31;
				break;
			}
	   case 6:
	   {
				totaldays=30;
				break;
			}
	   case 7:
	   {
				totaldays=31;
				break;
			}
	   case 8:
	   {
				totaldays=31;
				break;
			}
	   case 9:
	   {
				totaldays=30;
				break;
			}
	   case 10:
	   {
				totaldays=31;
				break;
			}
	   case 11:
	   {
				totaldays=30;
				break;
			}
	   case 12:
	   {
				totaldays=31;
				break;
			}
	}
	return totaldays;
}

function generateNumericSort(elap_array)
{
 	for(var x=0;x<elap_array.length;x++)
 	{
 	     for(var y=parseInt(x+1);y<elap_array.length;y++)
 	     {
 	     	x_val = parseInt(elap_array[x]);
 	     	y_val = parseInt(elap_array[y]);

 	     	if(x_val > y_val)
 	      	{
 	      	   temp_min = x_val
 	      	   elap_array[x] = y_val;
 	      	   elap_array[y] = temp_min;
 	      	}
 	     }
 	}
 	return elap_array;

}

function getMonthNo(mon)
{
	month_no = 0;

	switch(mon)
	{
	   case "Jan":
	   case "jan":
				month_no=1;
				break;
	   case "Feb":
	   case "feb":
				month_no=2;
				break;
	   case "Mar":
	   case "mar":
				month_no=3;
				break;
	   case "Apr":
	   case "apr":
				month_no=4;
				break;
	   case "May":
	   case "may":
				month_no=5;
				break;
	   case "Jun":
	   case "jun":
				month_no=6;
				break;
	   case "Jul":
	   case "jul":
				month_no=7;
				break;
	   case "Aug":
	   case "aug":
				month_no=8;
				break;
	   case "Sep":
	   case "sep":
				month_no=9;
				break;
	   case "Oct":
	   case "oct":
				month_no=10;
				break;
	   case "Nov":
	   case "nov":
				month_no=11;
				break;
	   case "Dec":
	   case "dec":
				month_no=12;
				break;
	}
	return month_no;
}

function getFullMonth(num)
{
	month_str = "";

	switch(num)
	{
	   case "01":
	   case "1":
				month_str="Jan";
				break;
	   case "02":
	   case "2":
				month_str="Feb";
				break;
	   case "03":
	   case "3":
				month_str="Mar";
				break;
	   case "04":
	   case "4":
				month_str="Apr";
				break;
	   case "05":
	   case "5":
				month_str="May";
				break;
	   case "06":
	   case "6":
				month_str="Jun";
				break;
	   case "07":
	   case "7":
				month_str="July";
				break;
	   case "08":
	   case "8":
				month_str="Aug";
				break;
	   case "09":
	   case "9":
				month_str="Sep";
				break;
	   case "10":
				month_str="Oct";
				break;
	   case "11":
				month_str="Nov";
				break;
	   case "12":
				month_str="Dec";
				break;
	}
	return month_str;
}

function replaceSpecialChar(data)
{
	var return_data = "";

	if(data != "")
	{
		for(var repl_a=0;repl_a<data.length;repl_a++)
		{
			if(data.charAt(repl_a) == "ö")
				return_data += "'";
			else if(data.charAt(repl_a) == "ü")
				return_data += "`";
			else if(data.charAt(repl_a) == "ÿ")
				return_data += "\"";
			else
				return_data += data.charAt(repl_a);
		}
	}
	return return_data;
}

function duplicateSpecialChar(data)
{
	var return_data = "";

	if(data != "")
	{
		for(var repl_a=0;repl_a<data.length;repl_a++)
		{
			if(data.charAt(repl_a) == "'")
				return_data += "ö";
			else if(data.charAt(repl_a) == "`")
				return_data += "ü";
			else if(data.charAt(repl_a) == "\"")
				return_data += "ÿ";
			else
				return_data += data.charAt(repl_a);
		}
	}
	return return_data;
}

function getFileExtension(data)
{
	if(data != "")
	{
		var split_data = data.split(".");

		if(split_data.length > 1)
			data = split_data[split_data.length-1].toLowerCase();
	}
	return data;
}

function getFileName(data)
{
	if(data != "")
	{
		var ind_val = data.lastIndexOf("/");

		if(ind_val == -1)
			ind_val = data.lastIndexOf("\\");

		if(ind_val != -1)
			data = data.substring(eval(parseInt(ind_val)+parseInt(1)))
	}
	return data;
}

function escapeValue(escaping_value)
{
	var escaped_value = "";

	if(escaping_value != "")
	{
		escaping_value	=	escape(escaping_value);

		for(var kk=0;kk<escaping_value.length;kk++)
		{
			if(escaping_value.charAt(kk) == "%")
			{
				if(escaping_value.substring(kk,new Number(kk+6)) == "%0D%0A")
				{
					escaped_value += "<br>";
					kk=new Number(kk+5);
				}
				else if(escaping_value.substring(kk,new Number(kk+3)) == "%0A")
				{
					escaped_value += "<br>";
					kk=new Number(kk+2);
				}
				else if(escaping_value.substring(kk,new Number(kk+3)) == "%0D")
				{
					escaped_value += "<br>";
					kk=new Number(kk+2);
				}
				/*else if(escaping_value.substring(kk,new Number(kk+3)) == "%20")
				{
					escaped_value += " ";
					kk=new Number(kk+2);
				}
				else if(escaping_value.substring(kk,new Number(kk+3)) == "%3C")
				{
					escaped_value += "<";
					kk=new Number(kk+2);
				}
				else if(escaping_value.substring(kk,new Number(kk+3)) == "%3E")
				{
					escaped_value += ">";
					kk=new Number(kk+2);
				}*/
				else
				{
					escaped_value += escaping_value.charAt(kk);
				}
			}
			else
			{
				escaped_value += escaping_value.charAt(kk);
			}
		}
	}

	return unescape(escaped_value);
}

function addTag(clicked_action, clicked_row_no)
{
	var include_text_object = null;

	if(clicked_row_no >= 0)
	{
		clicked_row_no	   = (--clicked_row_no);
		include_text_object	= document.content_panel.other_description[clicked_row_no]
	}
	else
	{
		include_text_object	= clicked_row_no;
	}

	var temporary_storage = include_text_object.value;

	if(clicked_action == "Bold")
	{
		temporary_storage = temporary_storage+"<b></b>";
	}
	else if(clicked_action == "Italic")
	{
		temporary_storage = temporary_storage+"<i></i>";
	}
	else if(clicked_action == "Underline")
	{
		temporary_storage = temporary_storage+"<u></u>";
	}
	else if(clicked_action == "Hr")
	{
		temporary_storage = temporary_storage+"<HR ALIGN=center width=100%>";
	}
	else if(clicked_action == "Address")
	{
		temporary_storage = temporary_storage+"<ADDRESS></ADDRESS>";
	}
	else if(clicked_action == "Citation")
	{
		temporary_storage = temporary_storage+"<CITE></CITE>";
	}
	else if(clicked_action == "Ordered")
	{
		temporary_storage = temporary_storage+"<OL>  <LI>  </OL>";
	}
	else if(clicked_action == "UnOrdered")
	{
		temporary_storage = temporary_storage+"<UL>  <LI>  </UL>";
	}
	else if(clicked_action == "Preformat")
	{
		temporary_storage = temporary_storage+"<PRE></PRE>";
	}
	else if(clicked_action == "Emphasis")
	{
		temporary_storage = temporary_storage+"<EM></EM>";
	}
	else if(clicked_action == "Sub")
	{
		temporary_storage = temporary_storage+"<SUB></SUB>";
	}
	else if(clicked_action == "Super")
	{
		temporary_storage = temporary_storage+"<SUP></SUP>";
	}

	else if(clicked_action == "Right")
	{
		temporary_storage = temporary_storage+"<P align=right> </P>";
	}

	else if(clicked_action == "Center")
	{
		temporary_storage = temporary_storage+"<P align=center> </P>";
	}


	include_text_object.value	= temporary_storage;
}

