// LCS 3021  May 6, 2003
var separator = ";";  // used for string=> multiple select list
var max_schedule_item = 10;  // used for max period of the schedule
var PAN_TILT = true;

var HelpOptionsVar = "width=480,height=420,scrollbars,toolbar,resizable,dependent=yes";
var bigsub   = "width=620,height=460,scrollbars,menubar,resizable,status,dependent=yes";
var upg_fw_sub ="width=620,height=270,scrollbars,menubar,resizable,status,dependent=yes";
var wsec_sub   = "width=620,height=390,scrollbars,menubar,resizable,status,dependent=yes";
var systime_sub = "width=620,height=310,scrollbars,menubar,resizable,status,dependent=yes";
var smallsub = "width=440,height=320,scrollbars,resizable,dependent=yes";
var specialsub = "width=440,height=320,scrollbars,resizable,dependent=no";
var sersub   = "width=500,height=380,scrollbars,resizable,status,dependent=yes";
var memsub   = "width=630,height=320,scrollbars,menubar,resizable,status,dependent=yes";
var viewingWinoptions = "width=800,height=500,scrollbars=no,resizable,status";
var motionsub = "width=810,height=540,scrollbars=no,resizable,status,dependent=yes";
var helpWinVar = null;
var glossWinVar = null;
var datSubWinVar = null;
var Valid_blank=" ";
var ValidStr = 'abcdefghijklmnopqrstuvwxyz-';
var hex_str = "ABCDEFabcdef0123456789";
var Valid_st = 'abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "';
var Valid_ch = "~!@#$%^&*()_+|}{:?><,./;'[]\``=-\\";
var Valid_Strd = Valid_st + Valid_ch;
var Valid_str_name=Valid_Strd+Valid_blank;
var Valid_Str = 'abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var Valid_Stri = 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var Valid_str_num='0123456789';
var Valid_Strs = 'abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-';
var Valid_st1 = 'abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var Valid_Strd1 = Valid_st1 + Valid_ch;
var Valid_domain= 'abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-';

	
var lang = "@h_lang#";   // "@h_lang#", "us", "eu"
// visibility
// Value: inherit | visible | hidden
var Vshowit = "visible";
var Vhideit = "hidden";

var viewinName = "view" + Math.ceil((Math.random() * 1000000));

function openViewWin()
{
	viewWindowVar = window.open("/main.htm", "viewWin", viewingWinoptions);
//	viewWindowVar = window.open("main.htm", "viewWin", viewingWinoptions);
}


var restart_time = 5000; // msecs


function changeTab(url)
{
	location.href=url;
}


// Browser Issue
function isNS()
{
 if(navigator.appName.indexOf("Netscape") != -1)
 return true;
 else return false;
}
function isIE()
{
 if(navigator.appName.indexOf("Microsoft Internet Explorer") != -1)
 {
 	if (false == isMac() && false == isOpera() && false == isNS())
 	{
 		return true;
 	}
 }
 return false;
}
function isOpera()   //only good for Opera 8.54
{
  if(navigator.userAgent.indexOf("Opera") >= 0)
  {
	  return true;
  }
  else {
	  return false;
  }
}
function isMac()
{
 if(navigator.appVersion.indexOf("Mac") != -1)
 return true;
 else return false;
}


function isWin()
{
 if(navigator.appVersion.indexOf("Win") != -1)
		return true;
  else return false;
}
function isWindows(){
  if(navigator.platform.indexOf("Win") != -1)
		return true;
  else return false;
}

var showit = "block";
var hideit = "none";

function show_hide(el,shownow)  // IE & NS6; shownow = true, false
{
        if (document.all)
                document.all(el).style.display = (shownow) ? showit : hideit ;
        else if (document.getElementById)
                document.getElementById(el).style.display = (shownow) ? showit : hideit ;
}
function setVisible(el,shownow)  // IE & NS6; shownow = true, false
{
  if (document.all)
    document.all(el).style.visibility = (shownow) ? Vshowit : Vhideit ;
  else if (document.getElementById)
   document.getElementById(el).style.visibility = (shownow) ? Vshowit : Vhideit ;
}

function showMsg(caller)
{
	var serverAdd = "http://"  +  self.location.host + ":" + self.location.port;
	var timeoutStr ;
	
	if (msgVar == "restart")
	{
		rALERT(caller,addstr(msg_restart, restart_time/1000));
	}
	else if (msgVar == "changeIP")
	{
		rALERT(caller,addstr(msg_changeIP, restart_time/1000));
		top.close();
	}
	else if(msgVar.indexOf("The settings of web server of camera have been") != -1)
	{
		rINFO(caller,msgVar);
	}
	else if(msgVar.indexOf("SMTP Server Test Passed") != -1)
	{
		rINFO(caller,msgVar);
	}
	else if(msgVar == "@" + "m" + "essage#")
	{
		;
	}
	else if (msgVar.length > 1)
	{
		rALERT(caller,msgVar);
	}
}

function closeWin(win_var)
{
	if   ((win_var != null) && (win_var.closed == false)) 
			win_var.close();
}

function openHelpWin(file_name)
{
   helpWinVar = window.open(file_name,'help_win',HelpOptionsVar);
   if (helpWinVar.focus)
		setTimeout('helpWinVar.focus()',200);
}

function openGlossWin()
{
	glossWinVar = window.open('','gloss_win',GlossOptionsVar);
	if (glossWinVar.focus)
		setTimeout('glossWinVar.focus()',200);
}

var randomn = Math.round(Math.random()*1000);
function openDataSubWin(filename,win_type)
{
	closeWin(datSubWinVar);
	datSubWinVar = window.open(filename,'datasub_win' + randomn,win_type);
	if (datSubWinVar.focus)
		setTimeout('datSubWinVar.focus()',200); 
}

function closeSubWins()
{
	closeWin(helpWinVar);
	closeWin(glossWinVar);
	closeWin(datSubWinVar);
}

function String2HexStr(str)
{
	var temp = "";
	for (var i=0; i<str.length; i++)
	{
		intCharCode = str.charCodeAt(i);
		//alert(intCharCode);
		if (intCharCode < 48 || intCharCode > 122)
		{
			temp = temp+"%"+intCharCode.toString(16);
		}
		else
		{
			temp = temp+str.charAt(i);
		}
	}
	return temp;
}

function is485Hex(str) {
   var i;
   for(i = 0; i<str.length; i++)
   {
	   var c = str.substring(i, i+1);
	   if(("0" <= c && c <= "9") || ("a" <= c && c <= "f") || ("A" <= c && c <= "F") || ("," == c)) // &cedil;
	   { continue; }
       return (msg_hex485key);
   }
   return "";
}

function checkBlank(fieldObj, fname)
{
	var msg = "";
	if (fieldObj.value.length < 1)
		msg = addstr(msg_blank,fname);
	return msg;
}

function checkNoBlanks(fObj, fname)
{
	var space = " ";
 	if (fObj.value.indexOf(space) >= 0 )
			return addstr(msg_nospaces, fObj.value);
	else return "";
}
function checkHostName(str)
{
		var at="@";
		var dot=".";
		var dash="-";
		var unline="_";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var i;
		var aa;	
		//host name must include "." and "." can't be the first/last char.
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||str.charAt(lstr-1)==".")
		{
			return false; 
		} 
		//"-" can't be the first/last char
		if(str.indexOf(dash)==0 ||str.charAt(lstr-1)=="-")
		{
			return false; 
		} 
		//"_" can't be the first/last char
		if(str.indexOf(unline)==0 ||str.charAt(lstr-1)=="_")
		{
			return false; 
		} 
		// can't include space
		if (str.indexOf(" ")!=-1)
		{		   
		    return false;
		}
		// xx-.com is invalid 	
		if(str.indexOf("-.")!=-1)
		{					
			return false;
		}
		
		// xx.-com is invalid    
		if(str.indexOf(".-")!=-1 )
		{
			return false;
		}
		// xx..com is invalid
		if(str.indexOf("..")!=-1)
		{
			 return false;
		}
		for (i=0;i<=lstr-1;i++)
		{ 
			aa=str.charAt(i) 
			if (!((aa=='.') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z')))
			{ 
				return false; 
			} 
		}
		return true;	
}
function checkDomainName(input_field, field_name,valid_char)
{
	if (checkHostName(input_field.value)==false)
				return addstr(msg_invalid,field_name,valid_char);
	return "";
}
function CheckEmail(str)
{ 

	var at="@";
	var dot=".";
	var dash="-";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var i;
	var aa;
	// it must include "@", and "@" can't be the first/last chars
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.charAt(lstr-1)=="@")
	{ 
		return false; 
	} 
	// "-" can't be the last chars
	if(str.charAt(lstr-1)=="-")
	{ 
		return false; 
	} 
	// it must include ".", and "." can't be the first/last chars
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||str.charAt(lstr-1)==".")
	{
		return false; 
	} 
	// only one "@"
	if (str.indexOf(at,(lat+1))!=-1)
	{ 
		return false;
	}

	// it can't be "." or "-" to the heel of "@", it can't be "@" to the heal of "."
	// xx.@xx.com, xx@-xx.com, xx@.com, are invalid		
	if (str.substring(lat-1,lat)==dot 
		 || str.substring(lat+1,lat+2)==dot 
		 || str.substring(lat+1,lat+2)==dash)
	{ 
		return false;
	}

	// after "@", it must include ".", between the "@" and ".", it msut be the other chars
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false; 
	} 
		
	// can't include space
	if (str.indexOf(" ")!=-1)
	{		   
		return false;
	}
	/*
	// after "@", "_" is invalid
	// xx@xx_xx.com is invalid	
	if(str.indexOf("_",lat+1)!=-1)
	{ 
		return false; 
	} 
	*/
	// after "@", the "." can't be to the heel of "-"
	// xx@xx-.com is invalid	
	if(str.indexOf("-.",lat+1)!=-1)
	{ 
		return false; 
	} 
	// after "@", the "-" can't be to the heel of "."
	// xx@xx.-com is invalid
	if(str.indexOf(".-",lat+1)!=-1)
	{ 
		return false; 
	} 
	// after "@", the "." can't be to the heel of "."
	// xx@xx..com is invalid
	if(str.indexOf("..",lat+1)!=-1)
	{ 
		return false; 
	} 
	for (i=0;i<=lstr-1;i++)
	{ 
		aa=str.charAt(i) 
		if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z')))
		{ 
			return false; 
		} 
	} 
	return true; 
} 
function checkMailAdd(input_field, field_name)
{
	if (CheckEmail(input_field.value)==false)
		return addstr(msg_mail, field_name);
	return "";
}

function checkValid(text_input_field, field_name, Valid_Str, max_size, mustFill)
{
	var error_msg= "";
	var size = text_input_field.value.length;
	var str = text_input_field.value;

	if ((mustFill) && (size != max_size) )
		return (addstr(msg_nospaces,field_name));
 	for (var i=0; i < size; i++)
  	{
  	  	if (!(Valid_Str.indexOf(str.charAt(i)) >= 0))
  	  	{

			if(Valid_Str=='abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
				Valid_Str = 'A-Z,a-z,0-9 and "-"';
			if(Valid_Str=='abcdefghijklmnopqrstuvwxyz-')
				Valid_Str = 'a-z';
			if(Valid_Str=='abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "')
				Valid_Str = 'A-Z,a-z,0-9,",balnk and "_"';		
			if(Valid_Str=='abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
				Valid_Str = 'A-Z,a-z,0-9,and "_"';		
			if(Valid_Str=='abcdefghijklmnopqrstuvwxyz_\nABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-')
				Valid_Str = 'A-Z,a-z,0-9,"-","." and "_"';						
			
			error_msg = addstr(msg_invalid,field_name,Valid_Str);
			break;
  	  	}
  	}
  	return error_msg;
}

function checkInvalid(text_input_field, field_name, InvalidStr)
// check that no chars in "InvalidStr" appear in input
{
  var str = text_input_field.value;
  var error_msg = "";

  for (var i=0; i < InvalidStr.length; i++)
  {
    if (str.indexOf(InvalidStr.charAt(i)) >= 0)
    {
		 error_msg = addstr(msg_notallow,field_name,InvalidStr);
		 break;
    }
  }
  return error_msg;
}

function checkRTPPort(rtp_port, min_port, max_port)
{
	var error_msg = "";
    
	if (rtp_port < min_port || rtp_port > max_port || rtp_port%2 != 0)
	{
		 error_msg = addstr(msg_rtp_port, min_port, max_port);
	}
    
    return error_msg;
}

function checkInt(text_input_field, field_name, min_value, max_value, required)
// NOTE: Doesn't allow negative numbers, required is true/false
{
	var str = text_input_field.value;
	var error_msg = "";
	

	if (text_input_field.value.length==0) // blank
	{
		if (required)
			error_msg = addstr(msg_blank,field_name);
	}
	else // not blank, check contents
	{
		for (var i=0; i < str.length; i++)
		{
			if ((str.charAt(i) < '0') || (str.charAt(i) > '9'))
				error_msg = addstr(msg_check_invalid,field_name);
		}
		if (error_msg.length < 2) // don't parse if invalid
		{

			var int_value = parseInt(str,10);
			if (int_value < min_value)
				error_msg = addstr(msg_outofrange,field_name,min_value,max_value);
			if (int_value > max_value)
				error_msg = addstr(msg_outofrange,field_name,min_value,max_value);
		}
	}
//	if (error_msg.length > 1)
//		error_msg = error_msg + "\n";
	return(error_msg);
}

function blankIP(fn) // true if 0 or blank
{
	return ( (fn.value == "") || (fn.value == "0") )
}

function checkIp(ip1,ip2,ip3,ip4,msg,null_flag)
{
	if( (null_flag == false) && blankIP(ip1) && blankIP(ip2) && blankIP(ip3) && blankIP(ip4) )
		return "";
	var errmsg =  checkInt(ip1,msg,1,255,true);
    
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip2,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip3,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip4,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? addstr(msg_validIP,msg) : "";
	return errmsg;
}

function checkNetMask(ip1,ip2,ip3,ip4,msg)
{
	var errmsg =  checkInt(ip1,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip2,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip3,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? errmsg : checkInt(ip4,msg,0,255,true);
	errmsg =  (errmsg.length > 1) ? addstr(msg_validMask,msg) : "";
	return errmsg;
}


function search_string(s_string, sub_string)
{
	var i=0, j;
	var first_char = sub_string.charAt(0);
	var sub_length = sub_string.length;
	
	while (i < s_string.length)
	{
		if (s_string.charAt(i) == first_char)
		{
			j = 0;
			while ((j < sub_length) && (s_string.charAt(i+j) == sub_string.charAt(j)))
					j++;
			if (j == sub_length) // all chars match
				return(i); // match starts at i
		}
		i++;
	}
	return -1; // not found
}

function getRadioCheckedValue(radio_object)
{
	var size = radio_object.length;
	for (var i = 0; i < size; i++)
	{
		if (radio_object[i].checked == true)
			return(radio_object[i].value);
	}
	return (radio_object[0].value); // first value if nothing checked
}

function getRadioIndex(radio_object, checked_value)  
{
	var size = radio_object.length;
	for (var i = 0; i < size; i++)
	{
		if (radio_object[i].value == checked_value)
			return  i;
	}

	return  0;   // if no match
}

function GetSellistValue(sel_object)
{
	var size = sel_object.length;
	for (var i = 0; i < size; i++)
	{
		if (sel_object[i].selected == true)
			return(sel_object[i].value);
	}
	return (sel_object[0].value); // first value if nothing checked
}

function GetSellistIndex(sel_object, checked_value)  
{
	var size = sel_object.length;
	for (var i = 0; i < size; i++)
	{
		if (sel_object[i].value == checked_value)
			return  i;
	}
	return  0;   // if no match
}

function getSelIndex(sel_object, sel_text,caseSensitive)
// caseSensitive: true = exact match, false = ignore case
{
	if (sel_text.length == 0)
		return 0;   //  Nothing may be valid. e.g. New SAP contain errors & returned.
	var size = sel_object.options.length;
	var match;
	for (var i = 0; i < size; i++)
	{
		if (caseSensitive)
		  match = ( (sel_object.options[i].text == sel_text) || (sel_object.options[i].value == sel_text) )
		else
		  match =  ( (sel_object.options[i].text.toLowerCase() == sel_text.toLowerCase()) || (sel_object.options[i].value.toLowerCase() == sel_text.toLowerCase()) );
		if (match)
			return(i);
	}
	return 0;  // if no match
}

function dupSelEntry(sel_object,newvalue,caseSensitive)
// check if renaming current value to existing value
// caseSensitive: true = exact match, false = ignore case
{
	var counter = 0;
	var match;
	var size = sel_object.options.length;
	var index = sel_object.selectedIndex;

	for (var i = 0; i < size; i++)
	{
		if (caseSensitive)
		  match = (sel_object.options[i].text == newvalue) ;
		else
		  match =  (sel_object.options[i].text.toLowerCase() == newvalue.toLowerCase() );
		if ((match) && (i != index))
			return true;
	}
	return false;
}

function chkSelected(selObj, err_msg)
{
    if(!(selObj.selectedIndex >= 0 ))
	{
	    rALERT("",err_msg);//alert(err_msg);
	    return false;
	}
	return true;
}
function addOption(selObj, textStr, valueStr)  // value optional
{
	if (addOption.arguments.length == 3)
		selObj.options[selObj.options.length] = new Option(textStr, valueStr);
	else
		selObj.options[selObj.options.length] = new Option(textStr, ""); // value blank
}

function delOption(sel_obj, position)
{
	for (var i = position; i < sel_obj.options.length - 1; i++)
	{
		sel_obj.options[i].text = sel_obj.options[i + 1].text;
		sel_obj.options[i].value = sel_obj.options[i + 1].value;
	}
	sel_obj.options.length = sel_obj.options.length - 1;
}

function getOptionList(sel_obj, strType)  
// return string. strType  = "text", "value" 
{
	var size = sel_obj.options.length; 
	var i; 
	var str = "";
	for(i = 0; i < sel_obj.options.length;  i++)
		str+= (strType=="value")? sel_obj.options[i].value + separator : sel_obj.options[i].text + separator; 
	return str;
}



// End Select List functions ===========================================================

var plus = "+";
var minus = "-";
var bID;
var cID;
var hID;
function change_text_num(text_input_field, operator, min_value, max_value)
// change up 1, or down 1, within limits  operator "+" or "-"
{
	var size = text_input_field.value.length;
	var str = text_input_field.value;
	
	if (size==0)
	{
		text_input_field.value = min_value;
		text_input_field.focus();
		return;
	}
	if (isNaN(parseInt(text_input_field.value)))
		return;
	var int_value = parseInt(text_input_field.value);
	if (operator == "+")
		text_input_field.value = ++int_value;
	else if (operator == "-")
		text_input_field.value = --int_value;
	if (int_value < min_value )
			text_input_field.value = min_value;
	else if (int_value > max_value )
			text_input_field.value = max_value;
	text_input_field.focus();
//	return;
}


function makeStr(strchar, strSize)
{
	var newStr = "";
	for (var i = 0; i < strSize; i++)
		newStr+= strchar;
	return newStr;
}

function ignoreSpaces(string)
{
       var temp = "";
       var first=1;
       
       string = '' + string;
       splitstring = string.split(" ");
       for(i = 0; i < splitstring.length; i++)
            if(splitstring[i]!=""){
                if(first==1){
                      if(splitstring[i]!=" "){
                          temp=splitstring[i];
                          first=0;
                      }
                }          
               else
                      temp = temp +  " " + splitstring[i];
            }          
       return temp;
}

function addstr(input_msg)
{
	var last_msg = "";
	var str_location;
	var temp_str_1 = "";
	var temp_str_2 = "";
	var str_num = 0;
	temp_str_1 = addstr.arguments[0];
	while(1)
	{
		str_location = temp_str_1.indexOf("%s");
		if(str_location >= 0)
		{
			str_num++;
			temp_str_2 = temp_str_1.substring(0,str_location);
			last_msg += temp_str_2 + addstr.arguments[str_num];
			temp_str_1 = temp_str_1.substring(str_location+2,temp_str_1.length);
			continue;
		}
		if(str_location < 0)
		{
			last_msg += temp_str_1;
			break;
		}
	}
	return last_msg;
}

function submitDemo(form_obj)
{
	show_data(form_obj);
}

function show_data(form_obj)   
// shows form information - used only for debugging
{
	var headvar = "<" + "h" + "e" + "a" + "d" + ">";
	var headend = "<" + "/" + "h" + "e" + "a" + "d" + ">";
	var bodyvar = "<" + "b" + "o" + "d" + "y" + ">";
	var form_size = form_obj.elements.length;
	var debug_win = window.open("","debug","width=540,height=360,menubar=yes,scrollbars=yes,resizable=yes");
	with(debug_win.document)
	{
		open();
		writeln('<html>' + headvar + '<title>Debugging Window</title>' + headend);
		writeln(bodyvar + '<h2>Form being submitted</h2>');
		writeln('<p>Form Name: ' + form_obj.name);
		writeln('<br>Form Action: ' + form_obj.action);
		writeln('<br>Form Target: ' + form_obj.target);
		writeln('</p><h3>Form Data</h3><p>Following table shows ALL fields, even if not submitted.</p>');
		writeln('<p><table border=1><tr bgcolor="#cccccc"><th nowrap>Field Name</th><th>Type</th><th>Value</th></tr>');
		for (var i = 0; i < form_size; i++)
		{
			writeln('<tr><td nowrap>' + form_obj.elements[i].name + '</td>');
			writeln('<td nowrap>' + form_obj.elements[i].type + '</td>');
			writeln('<td nowrap>');
			if ((form_obj.elements[i].type=="select-one") || (form_obj.elements[i].type=="select-multiple"))
				writeln('Selected item: ' + form_obj.elements[i].options[form_obj.elements[i].selectedIndex].text);			
			else 
				writeln(form_obj.elements[i].value);
			if ((form_obj.elements[i].type == "radio") && (form_obj.elements[i].checked))
						write(' (Selected)');
			if ((form_obj.elements[i].type == "checkbox") && (form_obj.elements[i].checked))
					writeln(' (Checked)');
			writeln('</td></tr>');
		}
		writeln('</table></body></html>');
		close();
	}
}

/* BUTTON FUNCTIONS */
function rolloverImg(img)
{
    src = img.src;
    if(src.indexOf('_up') != -1)
    {
        img.src = src.replace('_up', '_over');
    }
    else if(src.indexOf('_over') != -1)
    {
        img.src = src.replace('_over', '_up');
    }
}
			
function overImg(img)
{
    src = img.src;
    if(src.indexOf('_over') != -1)
    { img.src = src.replace('_over', '_up'); }
    else if(src.indexOf('_down') != -1)
    { img.src = src.replace('_down', '_up'); }
}

function pressImg(img)
{
    src = img.src;
    if(src.indexOf('_over') != -1)
    { img.src = src.replace('_over', '_down'); }
    else if(src.indexOf('_down') != -1)
    { img.src = src.replace('_down', '_over'); }
}

// IP Fields
var fieldIndex = 0;
var currentField = null;
var ipfield = false;
var lastf = false;
var fstf = false;

function setfIPfield(formObj,fieldObj)
{
    ipfield = true;
    fstf = true;
    lastf = false;
    currentField = fieldObj;
    fieldObj.select();
    for (var i = 0; i < formObj.elements.length; i++)
        if (formObj.elements[i].name == fieldObj.name)
            fieldIndex = i;
}

function preloadImg(img)
{
    src = img.src;
    document.onImg = new Image();
    document.onImg.src = src.replace('_off', '_on');
}
			
function openPopUp(url, width, height, scrolling, name) { //v2.0
	if (!width) width = 320;
	if (!height) height = 240;
	if (!scrolling) scrolling = "no"; 
	features = "width="+width+","
		+ "height="+height+","
		+ "name="+name+","
		+ "toolbar=no,"
		+ "location=no,"
		+ "status=no,"
		+ "menubar=no,"
		+ "scrollbars="+scrolling+","
		+ "top="+(window.screen.height-height)/2+","
		+ "left="+(window.screen.width-width)/2;
	window.open(url,"win"+Math.round(Math.random()*1000),features);
}


function setHTML(windowObj, el, htmlStr)
{
    if (document.all)
	{
	  if (windowObj.document.all(el) )
        windowObj.document.all(el).innerHTML = htmlStr;
	}
	else if (document.getElementById)
	{
	  if (windowObj.document.getElementById(el) )
	    windowObj.document.getElementById(el).innerHTML = htmlStr;
	}
}

function randomString(len, string)
{
    var str = "";

    for (var i=0; i<len; i++)
    {
        str += string.charAt(Math.ceil(Math.random()*100000000)%string.length);
    }

    return str;
}

function ToHex(i)
{
	var hex_string = "0123456789abcdef";
	return hex_string.charAt((i>>4)&0x0f)+hex_string.charAt(i&0x0f);
}

function array(n) {
  for(i=0;i<n;i++) this[i]=0;
  this.length=n;
}

function integer(n) { return n%(0xffffffff+1); }

function shr(a,b) {
  a=integer(a);
  b=integer(b);
  if (a-0x80000000>=0) {
    a=a%0x80000000;
    a>>=b;
    a+=0x40000000>>(b-1);
  } else
    a>>=b;
  return a;
}

function shl1(a) {
  a=a%0x80000000;
  if (a&0x40000000==0x40000000)
  {
    a-=0x40000000;  
    a*=2;
    a+=0x80000000;
  } else
    a*=2;
  return a;
}

function shl(a,b) {
  a=integer(a);
  b=integer(b);
  for (var i=0;i<b;i++) a=shl1(a);
  return a;
}

function and(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0) 
    if (t2>=0) 
      return ((t1&t2)+0x80000000);
    else
      return (t1&b);
  else
    if (t2>=0)
      return (a&t2);
    else
      return (a&b);  
}

function or(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0) 
    if (t2>=0) 
      return ((t1|t2)+0x80000000);
    else
      return ((t1|b)+0x80000000);
  else
    if (t2>=0)
      return ((a|t2)+0x80000000);
    else
      return (a|b);  
}

function xor(a,b) {
  a=integer(a);
  b=integer(b);
  var t1=(a-0x80000000);
  var t2=(b-0x80000000);
  if (t1>=0) 
    if (t2>=0) 
      return (t1^t2);
    else
      return ((t1^b)+0x80000000);
  else
    if (t2>=0)
      return ((a^t2)+0x80000000);
    else
      return (a^b);  
}

function not(a) {
  a=integer(a);
  return (0xffffffff-a);
}

var state = new array(4); 
var count = new array(2);
count[0] = 0;
count[1] = 0;                     
var buffer = new array(64); 
var transformBuffer = new array(16); 
var digestBits = new array(16);

var S11 = 7;
var S12 = 12;
var S13 = 17;
var S14 = 22;
var S21 = 5;
var S22 = 9;
var S23 = 14;
var S24 = 20;
var S31 = 4;
var S32 = 11;
var S33 = 16;
var S34 = 23;
var S41 = 6;
var S42 = 10;
var S43 = 15;
var S44 = 21;

function F(x,y,z) {
	return or(and(x,y),and(not(x),z));
}

function G(x,y,z) {
	return or(and(x,z),and(y,not(z)));
}

function H(x,y,z) {
	return xor(xor(x,y),z);
}

function I(x,y,z) {
	return xor(y ,or(x , not(z)));
}

function rotateLeft(a,n) {
	return or(shl(a, n),(shr(a,(32 - n))));
}

function FF(a,b,c,d,x,s,ac) {
    a = a+F(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
}

function GG(a,b,c,d,x,s,ac) {
	a = a+G(b, c, d) +x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
}

function HH(a,b,c,d,x,s,ac) {
	a = a+H(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
}

function II(a,b,c,d,x,s,ac) {
	a = a+I(b, c, d) + x + ac;
	a = rotateLeft(a, s);
	a = a+b;
	return a;
}

function transform(buf,offset) { 
	var a=0, b=0, c=0, d=0; 
	var x = transformBuffer;
	
	a = state[0];
	b = state[1];
	c = state[2];
	d = state[3];
	
	for (i = 0; i < 16; i++) {
	    x[i] = and(buf[i*4+offset],0xff);
	    for (j = 1; j < 4; j++) {
		x[i]+=shl(and(buf[i*4+j+offset] ,0xff), j * 8);
	    }
	}

	/* Round 1 */
	a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
	d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
	c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
	b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
	a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
	d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
	c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
	b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
	a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
	d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
	c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
	b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
	a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
	d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
	c = FF ( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
	b = FF ( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */

	/* Round 2 */
	a = GG ( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
	d = GG ( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
	c = GG ( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
	b = GG ( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
	a = GG ( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
	d = GG ( d, a, b, c, x[10], S22,  0x2441453); /* 22 */
	c = GG ( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
	b = GG ( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
	a = GG ( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
	d = GG ( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
	c = GG ( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
	b = GG ( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
	a = GG ( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
	d = GG ( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
	c = GG ( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
	b = GG ( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */

	/* Round 3 */
	a = HH ( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
	d = HH ( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
	c = HH ( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
	b = HH ( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
	a = HH ( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
	d = HH ( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
	c = HH ( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
	b = HH ( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
	a = HH ( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
	d = HH ( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
	c = HH ( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
	b = HH ( b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
	a = HH ( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
	d = HH ( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
	c = HH ( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
	b = HH ( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */

	/* Round 4 */
	a = II ( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
	d = II ( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
	c = II ( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
	b = II ( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
	a = II ( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
	d = II ( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
	c = II ( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
	b = II ( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
	a = II ( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
	d = II ( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
	c = II ( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
	b = II ( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
	a = II ( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
	d = II ( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
	c = II ( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
	b = II ( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */

	state[0] +=a;
	state[1] +=b;
	state[2] +=c;
	state[3] +=d;

}

function MD5_init() {
	count[0]=count[1] = 0;
	state[0] = 0x67452301;
	state[1] = 0xefcdab89;
	state[2] = 0x98badcfe;
	state[3] = 0x10325476;
	for (i = 0; i < digestBits.length; i++)
	    digestBits[i] = 0;
}

function update(b) { 
	var index,i;
	
	index = and(shr(count[0],3) , 0x3f);
	if (count[0]<0xffffffff-7) 
	  count[0] += 8;
        else {
	  count[1]++;
	  count[0]-=0xffffffff+1;
          count[0]+=8;
        }
	buffer[index] = and(b,0xff);
	if (index  >= 63) {
	    transform(buffer, 0);
	}
}

function finish() {
	var bits = new array(8);
	var	padding; 
	var	i=0, index=0, padLen=0;

	for (i = 0; i < 4; i++) {
	    bits[i] = and(shr(count[0],(i * 8)), 0xff);
	}
        for (i = 0; i < 4; i++) {
	    bits[i+4]=and(shr(count[1],(i * 8)), 0xff);
	}
	index = and(shr(count[0], 3) ,0x3f);
	padLen = (index < 56) ? (56 - index) : (120 - index);
	padding = new array(64); 
	padding[0] = 0x80;
        for (i=0;i<padLen;i++)
	  update(padding[i]);
        for (i=0;i<8;i++) 
	  update(bits[i]);

	for (i = 0; i < 4; i++) {
	    for (j = 0; j < 4; j++) {
		digestBits[i*4+j] = and(shr(state[i], (j * 8)) , 0xff);
	    }
	} 
}

function hexa(n) {
	var hexa_h = "0123456789abcdef";
	var hexa_c=""; 
	var hexa_m=n;

	for (hexa_i=0;hexa_i<8;hexa_i++) {
		hexa_c=hexa_h.charAt(Math.abs(hexa_m)%16)+hexa_c;
		hexa_m=Math.floor(hexa_m/16);
	}
	return hexa_c;
}


var ascii="01234567890123456789012345678901" +
          " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
          "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function MD5(entree) 
{
	var l,s,k,ka,kb,kc,kd;

	MD5_init();
	for (k=0;k<entree.length;k++) {
		l=entree.charAt(k);
		update(ascii.lastIndexOf(l));
	}
	finish();
	ka=kb=kc=kd=0;
	for (i=0;i<4;i++) ka+=shl(digestBits[15-i], (i*8));
	for (i=4;i<8;i++) kb+=shl(digestBits[15-i], ((i-4)*8));
	for (i=8;i<12;i++) kc+=shl(digestBits[15-i], ((i-8)*8));
	for (i=12;i<16;i++) kd+=shl(digestBits[15-i], ((i-12)*8));
	s=hexa(kd)+hexa(kc)+hexa(kb)+hexa(ka);
	return s; 
}

/* Date Format */
var year = '<select size=1 name="yr" id="yr" onChange="setDays(this.form.mth,this.form.day,this)"><option value="2005">2005</option><option value="2006">2006</option><option value="2007">2007</option><option value="2008">2008</option><option value="2009">2009</option><option value="2010">2010</option><option value="2011">2011</option><option value="2012">2012</option><option value="2013">2013</option><option value="2014">2014</option><option value="2015">2015</option><option value="2016">2016</option><option value="2017">2017</option><option value="2018">2018</option><option value="2019">2019</option><option value="2020">2020</option><option value="2021">2021</option><option value="2022">2022</option><option value="2023">2023</option><option value="2024">2024</option><option value="2025">2025</option><option value="2026">2026</option><option value="2027">2027</option><option value="2028">2028</option><option value="2029">2029</option><option value="2030">2030</option></select>';

var month = '<select name="mth" id="mth" size="1" onChange="setDays(this,this.form.day,this.form.yr)"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>';

var date = '<SELECT size="1" name="day"id="day"><option value="1">1</option><option value="2">2</OPTION><option value="3">3</OPTION><option value="4">4</OPTION><option value="5">5</OPTION><option value="6">6</OPTION><option value="7">7</OPTION><option value="8">8</OPTION><option value="9">9</OPTION><option value="10">10</OPTION><option value="11">11</OPTION><option value="12">12</OPTION><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select>';




