function updDisableButton(){
	var i, j;
	for(i = 0; i < document.forms.length; i++)
	{
		for(j = 0; j < document.forms[i].elements.length; j++)
		{
			if(document.forms[i].elements[j].type.toLowerCase() == "submit" || document.forms[i].elements[j].type.toLowerCase() == "button")
			{
				document.forms[i].elements[j].disabled = true;
				document.forms[i].elements[j].setAttribute("class", "button_grey");
			}
		}
	}
}

function jsUpload()
{
	document.getElementById("upload_status").innerHTML = '<img src="images/upload_loader.gif">';
	document.upload_form.submit();
	return true;
}

var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new Array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec")

function getthedate()
{
	var mydate=new Date();
	var year=mydate.getYear();

	if (year < 1000)
		year+=1900;

	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();

	if (daym<10)
		daym="0"+daym;

	var hours=mydate.getHours();
	var minutes=mydate.getMinutes();
	var seconds=mydate.getSeconds();
	var dn="AM";

	if (hours>=12)
		dn="PM";

	if (hours>12){
		hours=hours-12;
	}

	if (hours==0)
		hours=12;

	if (minutes<=9)
		minutes="0"+minutes;

	if (seconds<=9)
		seconds="0"+seconds;

	//change font size here
	var cdate="<font class='clock'>"+dayarray[day]+", "+daym+" "+montharray[month]+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
	+"</font>";

	if (document.all)
		document.all.clock.innerHTML=cdate;
	else if (document.getElementById)
		document.getElementById("clock").innerHTML=cdate;
	else
		document.write(cdate);
}
function addBreakLine(notes)
{
	return(notes.replace(/\n/g, "<br>"));
}
function startclock(){
	if (document.all||document.getElementById);
		setInterval("getthedate()",1000);
}
function changeDiv(id, method)
{
	var itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all)     {
		itm = document.all[id];
	} else if (document.layers)   {
		itm = document.layers[id];
	}

	if (itm.style)
	{
		if ( method == 'show' )
		{
			itm.style.display = "";
		}
		else
		{
			itm.style.display = "none";
		}
	}
	else
	{
		itm.visibility = "show";
	}
}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",800)
}

function allNumeric(sText)
{
	var ValidChars = "0123456789.";
	var aNum=true;
	var Char;

	for (i = 0; i < sText.length && aNum == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			aNum = false;
		}
	}
	if(!aNum)
		alert("Only numeric value is allowed");
	
	return aNum;
}

function trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = rtrim(TRIM_VALUE);
	TRIM_VALUE = ltrim(TRIM_VALUE);

	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function rtrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;

} //End Function

function ltrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;

} //End Function

function trim_comma(sTemp){

	if(sTemp.length < 1){
		return"";
	}
	sTemp = rtrim(sTemp);
	sTemp = ltrim(sTemp);

	var nTemp=""
	for (var i=0;i<sTemp.length;i++) {
	  	var a = sTemp.charAt(i)
		nTemp += a.replace(",","")
	}
	return nTemp;
}

function emailCheck (emailStr,emailid)
{
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;

	var emailPat=/^(.+)@(.+)$/;

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	var quotedUser="(\"[^\"]*\")";

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	var word="(" + atom + "|" + quotedUser + ")";

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");



	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

		alert("Email address seems incorrect (check @ and .'s)");
		document.getElementsByName( emailid )[0].value = "";
		return false;
	}
	if (emailStr.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
	{
		alert("This email contains invalid characters.");
		document.getElementsByName( emailid )[0].value = "";
		return false;
	}


	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		alert("This username contains invalid characters.");
		document.getElementsByName( emailid )[0].value = "";
		return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		alert("This domain name contains invalid characters.");
		document.getElementsByName( emailid )[0].value = "";
		return false;
		   }
	}

	if (user.match(userPat)==null) {

		alert("The username doesn't seem to be valid.");
		document.getElementsByName( emailid )[0].value = "";
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			alert("Destination IP address is invalid!");
			document.getElementsByName( emailid )[0].value = "";
			return false;
		   }
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	document.getElementsByName( emailid )[0].value = "";
	return false;
	   }
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	document.getElementsByName( emailid )[0].value = "";
	return false;
	}

	if (len<2) {
	alert("This address is missing a hostname!");
	document.getElementsByName( emailid )[0].value = "";
	return false;
	}

	return true;
}

function ConfirmTransfer( form_name, arr_list, gofile )
{
	var j =0;
	
	with (form_name)
	{
		for (var i=0; i < elements.length; i++)
		{
			if (elements[i].name == "site" && elements[i].value == "")
			{
				document.getElementById('error').className = "formErrors";
				document.getElementById('error').innerHTML = "Sorry! The following errors occured<br>Please Select Site";
				return false;
			}
			if (elements[i].type == 'checkbox' && elements[i].name == arr_list && elements[i].checked == true)
			{
				gofile = gofile + elements[i].value + ",";
				j++;
			}
		}

		if (j <= 0)
		{
			document.getElementById('error').className = "formErrors";
			document.getElementById('error').innerHTML = "Sorry! The following errors occured<br>No Item is Selected";
		}
		else
		{
			location.href = gofile;
		}
	}
}

function getTimeStamp(iDate,iHour,iMin,iAP)
{
	var hour = eval(iHour);
	var min = eval(iMin);
	var date = iDate //dd MMM yyyy
	year = date.substring(7,11);
	month = date.substring(3,6);
	day = date.substring(0,2);

	var humDate = new Date(Date.UTC(year,(getMonthNum(month)-1),day,get24Hour(hour),stripLeadingZeroes(min),0));
	timeStamp = (humDate.getTime()/1000.0);

	return timeStamp;
	function get24Hour(hour)
	{
		if(iAP == "pm" && hour != "12")
		{
			a = hour+12
			return a
		}
		else if (iAP == "am" && hour == "12")
			return 0;
		else
			return hour;
	}
	function stripLeadingZeroes(input)
	{
	    	if((input.length > 1) && (input.substr(0,1) == "0"))
	      		return input.substr(1);
	    	else
	      		return input;
	}

	function getMonthNum(abbMonth)
	{
		var arrMon = new Array("Jan","Feb","Mar","Apr","May","Jun",
  			"Jul","Aug","Sep","Oct","Nov","Dec");
		for(i=0; i<arrMon.length; i++)
		{
			if(abbMonth == arrMon[i])
			return i+1;
		}
	}
}

var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new Array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec")

function getthedate()
{
	var mydate=new Date();
	var year=mydate.getYear();

	if (year < 1000)
		year+=1900;

	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();

	if (daym<10)
		daym="0"+daym;

	var hours=mydate.getHours();
	var minutes=mydate.getMinutes();
	var seconds=mydate.getSeconds();
	var dn="AM";

	if (hours>=12)
		dn="PM";

	if (hours>12){
		hours=hours-12;
	}

	if (hours==0)
		hours=12;

	if (minutes<=9)
		minutes="0"+minutes;

	if (seconds<=9)
		seconds="0"+seconds;

	//change font size here
	var cdate="<font class='text'>"+dayarray[day]+", "+daym+" "+montharray[month]+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
	+"</font>";

	if (document.all)
		document.all.clock.innerHTML=cdate;
	else if (document.getElementById)
		document.getElementById("clock").innerHTML=cdate;
	else
		document.write(cdate);
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function addClassName(elm, className){
    var currentClass = elm.className;
    if(!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)){
        elm.className = currentClass + ((currentClass.length > 0)? " " : "") + className;
    }
    return elm.className;
}

function removeClassName(elm, className){
    var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");
    elm.className = elm.className.replace(classToRemove, "").replace(/^\s+|\s+$/g, "");
    return elm.className;
}

function hasClass(el, c) {
  if (!el || !el.className.length) return;
  var bits = el.className.split(' '), has = false;
  for (var j = 0; j < bits.length; j++) if (bits[j] === c) has = true;
  return has;
}

function activateThisColumn(column) {
  var div = document.getElementById('dolphinnav');

  var as = div.getElementsByTagName('a');

  for (var g=0; g<as.length; g++) {
    removeClassName(as[g], 'current');
  }


	addClassName(as[column], 'current');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,'',features);
}

function autoResize(id)
{
  var newheight;
  var newwidth;

  if(document.getElementById)
  {
    newheight=document.parent.getElementById(id).contentWindow.document.body.scrollHeight;
    newwidth=document.parent.getElementById(id).contentWindow.document.body.scrollWidth;
  }

  document.getElementById(id).height=(newheight) + "px";
  document.getElementById(id).width=(newwidth) + "px";
}

//-------------------------------------------------------------
//	Action Related: Check All, Select All etc.
//-------------------------------------------------------------
function CheckAll(form_name,arr_list)
{
	with (form_name)
	{
		if(form_name.check_all.checked)
		{
			for (var i=0; i < elements.length; i++)
			{
				if (elements[i].type == 'checkbox' && elements[i].name == arr_list && !elements[i].disabled)
					elements[i].checked = true;
			}
		}
		else
		{
			for (var i=0; i < elements.length; i++)
			{
				if (elements[i].type == 'checkbox' && elements[i].name == arr_list)
					elements[i].checked = false;
			}
		}
	}
}


//-------------------------------------------------------------
//	Cookie Related
//-------------------------------------------------------------
function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function setFocus(fieldid)
{
	document.getElementById(fieldid).focus();
}

