// This function is used to open a new window

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0 + my changes of onClick (down)
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


var newWin;
function OpenWin(url,windowname,width,height)
{
 if (!url)
 {
 alert ("Please specify a URL to open");
 return false;
 }
 if (!windowname) windowname = 'newWin';
 if (!width) width = 300;
 if (!height) height = 350;
 //if (window.innerHeight && height > (window.innerHeight-0)) height = window.innerHeight-0;
 if (screen.availHeight && height > (window.availHeight)) height = window.availHeight;
 else {
 		if (window.outerHeight && height > (window.outerHeight-0)) height = window.outerHeight-0;
 }
 //if (window.innerWidth && width > window.innerWidth) width = window.innerWidth;
 if (window.availWidth && width > window.availWidth) width = window.availWidth;
 else {
 		if (window.outerWidth && width > window.outerWidth) width = window.outerWidth;
 }
 var properties = "menubar=no,toolbars=no,directory=no,scrolling=yes,status=no,scrollbars=yes,resizable=yes,maximize=yes,left=0,top=0,width="+width+",height="+height;
 if (newWin && ! newWin.closed)
 	newWin.close();	
 newWin = window.open(url,windowname,properties);
 newWin.focus();
 //return newWin;
}
function eCheckNum(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ")  || (ch == ".")  || (ch == ";")  || (ch == "&")  ||  (ch == ",")  ||  (ch == "_")  ||  (ch == "(")  ||  (ch == ")")  ||  ch == "@"))
           {
             return false;
        theForm.elements[eCheckNum.arguments[i]].focus();
             //(ch >= "0" && ch <= "9") (ch == "-")   ||
                                }
        }
   return true;
}

function CheckNum(theForm){
   for(var i=1; i<CheckNum.arguments.length; i++)
         if (!eCheckNum(theForm.elements[CheckNum.arguments[i]])){
            alert("Field entry is not valid");
            theForm.elements[CheckNum.arguments[i]].focus();
            return false;
        }
   return true;
}


function eCheckAlphaNum(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ")  || (ch == ".")  || (ch == "-")   || (ch == "&")  ||  (ch == ",")  ||  (ch == "_")  ||  (ch == "(")  ||  (ch == ")")  || (ch >= "0" && ch <= "9") || ch == "@"))
           {
             return false;
        theForm.elements[eCheckAlphaNum.arguments[i]].focus();

                                }
        }
   return true;
}

function CheckAlphaNum(theForm){
   for(var i=1; i<CheckAlphaNum.arguments.length; i++)
         if (!eCheckAlphaNum(theForm.elements[CheckAlphaNum.arguments[i]])){
            alert("Field entry is not valid");
            theForm.elements[CheckAlphaNum.arguments[i]].focus();
            return false;
        }
   return true;
}

function CheckRequiredFields(theForm)
{
   for(i=1; i<CheckRequiredFields.arguments.length; i++)
        if(theForm.elements[CheckRequiredFields.arguments[i]].value=="")
        {
            alert("This field is required");
            theForm.elements[CheckRequiredFields.arguments[i]].focus();
            return false;
        }
   return true;
}

function deleterow(form,formobj)
{
var end=eval("document."+form+".end.value");
var count=0;
var i=0;
  for(i=1;i<=end;i++)
  {
     box=eval("document."+formobj+i);
        if(box.checked==true)
        {
                count=i;
        }
  }
             if(count < 1)
                  {
                alert("You have to select atleast one checkbox");
          return false;
                  }
      else if(!delrecord())
            {
       return false;
            }

//return mess;
 return true;
}

function delrecord(record)
{
var label="Are you sure you want to delete selected "+record+" ?\nClick on OK to delete.";

  if(!confirm(label))
  {
    return false;
  }

return true;
}

function email(formobj)
{
   var em=formobj.value;
   var len=em.length;
   var fm=em.indexOf("@");
   var fm1=em.indexOf(".");
   var fm3=em.indexOf(" ");
   var m=0 ;
   var check=false;
   var messg="";

   if(fm==-1 || fm3!=-1 || fm1==-1)
   {
      check=true;
      messg+="This is not valid email address\n";
   }
   if(em.substring(0,1)=="@" || em.substring(0,1)==".")
   {
      check=true;
      messg+="Email address should be start from a valid character or number\n";
   }
   for(i=0;i<len;i++)
   {
      if(em.substring(i,i+1)=="@")
      {
         m=m+1;
      }
      if((em.substring(i,i+1)=="@") && (em.substring(i+1,i+2)=="."))
      {
         check=true;
         messg+="after '@' character should be present\n";
      }
      if((em.substring(i,i+1)==".") && ((em.substring(i+1,i+2)=="@" ||em.substring(i+1,i+2)=="") || (em.substring(i+2,i+3)=="")))
      {
         check=true;
         messg+="After '.' atleast two character should be present\n";
      }
   }
   if(check==true)
   {
      return messg;
   }
   else if(m > 1)
   {
      return messg+="Not more then one '@' is allowed\n";
   }
   else
   {
      return messg="";
   }

}
function doacc(chkbox)
{
   if(chkbox.checked)
   document.addproducts.products.value+=chkbox.value+'-';
   else
   {
   acc=document.addproducts.products.value;
   document.addproducts.products.value=acc.replace('-'+chkbox.value+'-','-');
   }
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
var NSX = (navigator.appName == "Netscape");
var IE4 = (document.all) ? true : false;

/**
	* hides/makes visible a table row
	*
	* @param   string   the element name
	* @param   string		"hide" forces hide, "show" forces show, leave parm out forces toggle
	* @return  boolean  always true
	*/
var toggleTimeout1 = null;
var toggleTimeout2 = null;
function toggleVis(divname)
{
	var x=MM_findObj(divname), a=toggleVis.arguments;
	
	if (x!=null) {
		if (document.all || document.getElementById) {	// IE & Gecko & Opera
			if ((x.style.display=="none" && a.length == 1) || (a.length > 1 && a[1] == "show")) // none means show, "" means hide
				x.style.display=""; // hide
			else
				x.style.display="none"; // show
		}
		else {	// Netscape 4
			if ((x.display=="show" && a.length == 1) || (a.length > 1 && a[1] == "show"))
				x.display="hide";
			else
				x.display="show";
		}
	}
} // end of the 'toggleVis()' function

function clearToggleTimeout()
{
	if (toggleTimeout1 && toggleTimeout1!=null)
		clearTimeout(toggleTimeout1);
	if (toggleTimeout2 && toggleTimeout2!=null)
		clearTimeout(toggleTimeout2);
	toggleTimeout1 = null;
	toggleTimeout2 = null;
}
function delayToggleVis()
{
	var toggleTimeout;
	a=delayToggleVis.arguments;
	if (a.length > 1)
		toggleTimeout = window.setTimeout("toggleVis('" + a[0] + "', '" + a[1] + "');", 250);
	else
		toggleTimeout = window.setTimeout("toggleVis('" + a[0] + "');", 250);
	return toggleTimeout;
}
			
function cv_to_kmsq(area, measure)
{
	if (area!="" && measure!="" && area > 0)
	{
		if (measure == "1")
			area = area; //square km.
		else
		{
			if (measure == "2")
				area = area / 100;	// "hectares"
			else
			{
				if (measure == "5")
					area = area * 2.5899881;	// "square miles"
				else 
				{
					if (measure == "6")
						area = area / 247.10538;	// acres
					else
						area = 0;
	}	}	}	}
	else
		area = 0;
	return area;
}

function helpOver(url)
{
	if (!url) helpUrl = helpUrlDefault;
	else helpUrl = url;
	var x=MM_findObj('help');
	if (x)
	{
		x.src = './images/tab_help_fl.gif';
	}
}

function helpClick(url)
{
	if (!url) var url = helpUrl;
	OpenWin(url, 'help', 1000, 710)
}

function helpKeyUp(url)
{
	if (!url) var url = helpUrlDefault;
/*	if (document.all)
			e = window.event;
	var key = window.event.keyCode ? window.event.keyCode : window.event.which ? window.event.which : window.event.charCode;
	//if (document.layers)
	//		key = e.which;
	//if (document.all)
	//		key = e.keyCode;
	// if (event.keyCode == event.DOM_VK_F1) {var buttonname = session + "/BUTTON.999-999=*1"; document.getElementsByName(buttonname)[0].click(); event.stopPropagation(); event.preventDefault();}
	if (key == 112) // 112 F1 */
		OpenWin(url, 'help', 1000, 710);
}

document.onkeydown=function fnCallback(evt) {
   if ( evt == null )
       evt = event;

   if ( evt.keyCode == 112 ) //F1
   {
		helpKeyUp(helpUrl);
		evt.preventDefault();  // disable default help in Firefox
		return false;
   }
};

/*document.onkeyup=function(evt) {
	if (evt==undefined) evt="";
	//var keycode = (evt)?evt.keyCode:evt.keyCode;
	var keycode = (evt) ? evt.keyCode : evt.which ? evt.which : evt.charCode;
	if (keycode==112) {
		helpKeyUp(helpUrl);
		//if (evt.preventDefault) {
		//	if (evt.cancelable)
		//		evt.preventDefault();
		//}
		//else
		//	evt.returnValue = false;
	}
	return false;
};*/ 

function helpOut()
{
	helpUrl = helpUrlDefault;
	var x=MM_findObj('help');
	if (x)
	{
		x.src = './images/tab_help.gif';
	}
}

var helpUrl = "showHelp.php";
var helpUrlDefault = "showHelp.php";


// BROWSER DETECTION

//initialization, browser, os detection
var d, dom, nu='', brow='', ie, ie4, ie5, ie5x, ie6, ie7;
var ns4, moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full=''; 
var mac, win, old, lin, ie5mac, ie5xwin, konq, saf, op, op4, op5, op6, op7;

d=document;
n=navigator;
nav=n.appVersion;
nan=n.appName;
nua=n.userAgent;
old=(nav.substring(0,1)<4);
mac=(nav.indexOf('Mac')!=-1);
win=( ( (nav.indexOf('Win')!=-1) || (nav.indexOf('NT')!=-1) ) && !mac)?true:false;
lin=(nua.indexOf('Linux')!=-1);
// begin primary dom/ns4 test
// this is the most important test on the page
if ( !document.layers )
{
	dom = ( d.getElementById ) ? d.getElementById : false;
}
else { 
	dom = false; 
	ns4 = true;// only netscape 4 supports document layers
}
// end main dom/ns4 test

op=(nua.indexOf('Opera')!=-1);
saf=(nua.indexOf('Safari')!=-1);
konq=(!saf && (nua.indexOf('Konqueror')!=-1) ) ? true : false;
moz=( (!saf && !konq ) && ( nua.indexOf('Gecko')!=-1 ) ) ? true : false;
ie=((nua.indexOf('MSIE')!=-1)&&!op);
if (op)
{
	str_pos=nua.indexOf('Opera');
	nu=nua.substr((str_pos+6),4);
	brow = 'Opera';
}
else if (saf)
{
	str_pos=nua.indexOf('Safari');
	nu=nua.substr((str_pos+7),5);
	brow = 'Safari';
}
else if (konq)
{
	str_pos=nua.indexOf('Konqueror');
	nu=nua.substr((str_pos+10),3);
	brow = 'Konqueror';
}
// this part is complicated a bit, don't mess with it unless you understand regular expressions
// note, for most comparisons that are practical, compare the 3 digit rv nubmer, that is the output
// placed into 'nu'.
else if (moz)
{
	// regular expression pattern that will be used to extract main version/rv numbers
	pattern = /[(); \n]/;
	// moz type array, add to this if you need to
	moz_types = new Array( 'Firebird', 'Phoenix', 'Firefox', 'Iceweasel', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv' );
	rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
	rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
	// search for occurance of any of characters in pattern, if found get position of that character
	rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';
	//check to make sure there was a result, if not do  nothing
	// otherwise slice out the part that you want if there is a slice position
	( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';
	// this is the working id number, 3 digits, you'd use this for 
	// number comparison, like if nu >= 1.3 do something
	nu = rv_full.substr( 0, 3 );
	for (i=0; i < moz_types.length; i++)
	{
		if ( nua.indexOf( moz_types[i]) !=-1 )
		{
			moz_brow = moz_types[i];
			break;
		}
	}
	if ( moz_brow )// if it was found in the array
	{
		str_pos=nua.indexOf(moz_brow);// extract string position
		moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1 ) ,3);// slice out working number, 3 digit
		// if you got it, use it, else use nu
		moz_brow_nu = ( isNaN( moz_brow_nu ) ) ? moz_brow_nu = nu: moz_brow_nu;
		moz_brow_nu_sub = nua.substr( (str_pos + moz_brow.length + 1 ), 8);
		// this makes sure that it's only the id number
		sub_nu_slice = ( moz_brow_nu_sub.search( pattern ) != -1 ) ? moz_brow_nu_sub.search( pattern ) : '';
		//check to make sure there was a result, if not do  nothing
		( sub_nu_slice ) ? moz_brow_nu_sub = moz_brow_nu_sub.substr( 0, sub_nu_slice ) : '';
	}
	if ( moz_brow == 'Netscape6' )
	{
		moz_brow = 'Netscape';
	}
	else if ( moz_brow == 'rv' || moz_brow == '' )// default value if no other gecko name fit
	{
		moz_brow = 'Mozilla';
	} 
	if ( !moz_brow_nu )// use rv number if nothing else is available
	{
		moz_brow_nu = nu;
		moz_brow_nu_sub = nu;
	}
	if (n.productSub)
	{
		release_date = n.productSub;
	}
}
else if (ie)
{
	str_pos=nua.indexOf('MSIE');
	nu=nua.substr((str_pos+5),3);
	brow = 'Microsoft Internet Explorer';
}
// default to navigator app name
else 
{
	brow = nan;
}
op5=(op&&(nu.substring(0,1)==5));

op6=(op&&(nu.substring(0,1)==6));
op7=(op&&(nu.substring(0,1)==7));
op8=(op&&(nu.substring(0,1)==8));
op9=(op&&(nu.substring(0,1)==9));
ie4=(ie&&!dom);
ie5=(ie&&(nu.substring(0,1)==5));
ie6=(ie&&(nu.substring(0,1)==6));
ie7=(ie&&(nu.substring(0,1)==7));
// default to get number from navigator app version.
if(!nu) 
{
	nu = nav.substring(0,1);
}
/*ie5x tests only for functionavlity. dom or ie5x would be default settings. 
Opera will register true in this test if set to identify as IE 5*/
ie5x=(d.all&&dom);
ie5mac=(mac&&ie5);
ie5xwin=(win&&ie5x);