function chkPay(){
	var pays=document.getElementsByName("pay[]");
	var modes=document.getElementsByName("radpayment");
	var bo1=document.getElementsByName("advbox[]");
	var bosat1=false;
	var bosat=false;
	var pay=false;
	var mode=false;
	var n=0;
	
	for(i=0;i<=pays.length-1;i++){
		if(pays[i].checked){
			pay=true;
			n=i;
		}
	}
	
	if(!pay){
		alert("Please Choose a Service Number to proceed")
		return pay;
	}
		
		
    if((pay) && (n<=bo1.length-1) && (!bosat)){
	   for(i=0;i<=bo1.length-1;i++){ 
	        if (!bo1[i].disabled  && bo1[i].value!= 0){
			   bosat=true;	
		    }
	   }
	}
	
	if((pay) && (n<=bo1.length-1) && (!bosat)){   
		alert ('Enter advance amount to pay');
		return bosat;
	}
	
	
	for(i=0;i<=modes.length-1;i++){
		if(modes[i].checked){
			mode=true;
		}
	}
	if(!mode){	
		alert("Please select a Mode of Payment")
		return mode;
	}
	
	if(pay && mode ){
//		document.forms.frmUser.submit.disabled=true;
	    return true;
	}
	else{
	    return false;
	}
	
}

function closeit() 
{
		//alert('hello1111');

	if (mywindow != null)
	{ 
		//alert('hello2222');

		if (!mywindow.closed) mywindow.close(); 
	}
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
mywindow=window.open(href, windowname, 'width=500,\height=275,\scrollbars=yes,\left=100,\TOP=100,\location=no','_blank');
return false;
}
	
function advboxn(){ 
	var advpay=document.getElementsByName("pay[]");
	var bo=document.getElementsByName("advbox[]");
	var bol=bo.length;
    for(i=0;i<=advpay.length-1;i++){ 
		if(advpay[i].checked && i<=bo.length-1){
			bo[i].disabled=false;
			alert('There is no pending bill for you.\nEnter advance amount to pay.');
		    bo[i].value=0;	
			bo[i].focus();
		}
	
		else {
			if(i<=bo.length-1){
			bo[i].value='';
	        bo[i].disabled=true;} 
		}
		
	}
}
function advboxval(){ 
	var bo2=document.getElementsByName("advbox[]");
	
	for(i=0;i<=bo2.length-1;i++)
	{
		if(bo2[i].value == 0)
		{ alert ('Please enter advance amount');
		   bo2[i].focus();
		   return false;
		}
	}
	
}

function KeyCheck(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (((keycode>47) && (keycode<58) )  || (keycode==8) ) 
	{ 
	return true; 
	}
else return false;
}

function browcls(){
{
 if (window.event.clientX < 0 && window.event.clientY < 0)
 {
   alert("Window is closing...");
 }
}
}
function chkerrsub(){
	var modes=document.getElementsByName("radsup");
	var mode=false;
	for(i=0;i<=modes.length-1;i++){
		if(modes[i].checked){
			mode=true;
		}
	}
	if(!mode){
		alert("Please select the type of Support required")
		return mode;
	}
	if(mode){
		//document.forms.frmUser.submit.disabled=true;
	return true;
	
	}
	else{
	return false;
	}
	
}


   var isNN = (navigator.appName.indexOf("Netscape")!=-1);
   
function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}

function checkUsername(){
	var userName = $("txtuser");
		if(userName=="") {
		$("txtuserErr").innerHTML="<br>Missing : Username";
		$("txtuser").focus();
	} else {
		
		$("txtuserErr").innerHTML="";
		val = agent.call('',"checkUsername","",userName.value);
		
		
		if(val>0){
		
			$("txtuser").value="";
			$("txtuserErr").innerHTML="<br>Username Not Available test";
			$("txtuser").focus();
			return false();
			
		} else {
			//$("txtuserErr").innerHTML="<br><span class=subHead>Username  Accepted</span>";
		}
	}
 }
function checkconsno()
{
	
	var cno=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	$("txtconsnoErr").innerHTML="";
	var reg=$("drpregion");
	//var cno=$("txtconsno");
	
	if(cno == "") {
		$("txtconsnoErr").innerHTML="Missing : Service No";
		
	} else {
		
		$("txtconsnoErr").innerHTML="";
		var val = agent.call('',"chkConsno","",cno+":"+reg.value);
		var row=eval(val);
		if(val.length >2 ){
			$("txtconsnoErr").innerHTML="Service No verified";
			$("cusname").value=row[0]['cname'];
			$("cusadd").value=row[0]['addres'];
		} else {
			$("txtconsnoErr").innerHTML="<span class=subHead>Invalid Service No / Region</span>";
			$("txtconsno").value="";
			
			return false;
		}
	}
}

function checkbifurno()
 { 
    var srno=$("regser").value;
	var cno=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	$("txtconsnoErr").innerHTML="";
	var reg=$("drpregion");
	
	if(cno == "") 
	{
		$("txtconsnoErr").innerHTML="Missing : Service No";
		
	} 
	else 
	{ 
		$("txtconsnoErr").innerHTML="";
		var val = agent.call('',"chkbifurno","",cno+":"+reg.value);
		var row=eval(val);
		
        if(val.length >2)
		{
			if(cno=row[0]['ncuscode'])
			{   
				$("txtconsnoErr").innerHTML="Service No verified";
				document.all.aldreg.submit1.disabled=false;
			//	document.forms.aldreg.submit.disabled=true;
				return true;
		    } 
		   else 
			{  
			    document.all.aldreg.submit1.disabled=true;
				$("txtconsnoErr").innerHTML="<span class=subHead>Invalid Service No / Region</span>";
				$("txtconsno").value="";
				return false;
		    }
		}
		else
		{
			document.all.aldreg.submit1.disabled=true;
			$("txtconsnoErr").innerHTML="<span class=subHead>Invalid Service No / Region</span>";
			$("txtconsno").value="";
			return false;
		}
    }   
 }


function checkuseno()
{
	$("cusname").value="";
	$("username").value="";
	var cno=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	$("txtconsnoErr").innerHTML="";
	var reg=$("drpregion");
	if(cno == "") {
		$("txtconsnoErr").innerHTML="Missing : Service No";
		
	} else {
		
		$("txtconsnoErr").innerHTML="";
		val = agent.call('',"chkConsno","",cno+":"+reg.value);
		val2 = agent.call('',"chkusercode","",cno+":"+reg.value);
		var row=eval(val);
		var row1=eval(val2);
		
		if(val.length >2)
		{ 
			$("txtconsnoErr").innerHTML="Service No verified";
			$("cusname").value=row[0]['cname'];
			 
			 if(val2.length >1 ) 
			 {
			   $("username").value=row1[0]['first_name']; 
			   document.all.ownten.txteyourname.disabled=false;
			 }
		} 
		else 
		{
			$("txtconsnoErr").innerHTML="<span class=subHead>Invalid Service No / Region</span>";
		//$("txtconsno").value="";
			
			return false;
		}
		     
		    
			 
	}
}


function chkmailid()
{	
    var selIndex = document.aldreg1.drpregion.selectedIndex;
    var cno = document.aldreg1.drpregion.options[selIndex].text;
	
		val = agent.call('',"chkmailid","",cno);
		val2 = agent.call('',"chkConsno","",cno);
	
		var row=eval(val);
		var row2=eval(val2);
			 if(val.length >2 ) 
				 { 
				   $("txtemailid1").value=row[0]['email_id'];
				   document.all.aldreg1.submit1.disabled=false;
				 }
 
			else 
				{ 
					if(val2.length >1 ) 
				 		{ 
				   			$("txtemailid1").value=row2[0]['email_id'];   
							document.all.aldreg1.submit1.disabled=false;
				 		}
				    else
					{
					 $("txtemailid1").value="";			
					}
					
					return false;
				}
		    	 
 }

function updserno()
{	
    var selIndex = document.aldreg5.drpregion1.selectedIndex;
    var cno = document.aldreg5.drpregion1.options[selIndex].text;
	$("txtErr").innerHTML="";
		val = agent.call('',"uptConsno","",cno);
	
		var row=eval(val);
		
			 if(val.length >0 ) 
				 { 
				   $("regser").value='0'+row[0]['new_reg']+row[0]['ncuscode'];
				   document.aldreg5.submit1.disabled=false;
				 }
 
			 else
				{
					$("regser").value=cno;	
					$("txtErr").innerHTML="No Change in the service number";
					 document.aldreg5.submit1.disabled=true;
					return false;
				} 
 }


function chkconfmail()
{
	var cno=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	$("txtconsnoErr").innerHTML="";
	var reg=$("drpregion");
	if(cno == "") {
		$("txtconsnoErr").innerHTML="Missing : Service No";
		
	} else {
		$("txtconsnoErr").innerHTML="";
		val = agent.call('',"chkConsno","",cno+":"+reg.value);
		val2 = agent.call('',"chkusercode","",cno+":"+reg.value);
		var row=eval(val);
		var row1=eval(val2);
		
		if(val.length >2)
		{ 
			$("txtconsnoErr").innerHTML="Service No verified";
			
			 if(val2.length >1 ) 
			 {
			   $("txtemailid1").value=row1[0]['email_id']; 
			   $("txteusername").value=row1[0]['username'];  
			    document.all.confmail.submit2.disabled=false;
			 }
		} 
		else 
		{
			$("txtconsnoErr").innerHTML="<span class=subHead>Invalid Service No / Region</span>";
			 $("txtemailid1").value="";			
  
			return false;
		}
		    	 
	}
}

function chkinvalid()
{
	var cno=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	
	$("txtconsnoErr").innerHTML='';
	var reg=$("drpregion").value;
	
	if(cno == "") {
		$("txtconsnoErr").innerHTML="Missing : Service No";
		return false;
	} else {
		
		$("txtconsnoErr").innerHTML='';
		val = agent.call('',"chkConsno","",cno+":"+reg);
		val2 = agent.call('',"chkusercode","",cno+":"+reg);
		var row=eval(val);
		var row1=eval(val2);
		
		
		if(val.length >2)
		{ 
			$("txtconsnoErr").innerHTML="Service No verified";
			$("cusname").value=row[0]['cname'];
			var status=row[0]['stat'];
		
			if(status=='L')
			{$("status").value = 'LIVE'; }
			if(status=='A')	
			{$("status").value = 'ACCOUNT CLOSED'; }
			if(status=='M')
			{$("status").value = 'METER REMOVED'; }
			if(status=='D')
			{$("status").value = 'DISCONNECTED'; }
			if(status=='T')
			{$("status").value = 'TRANSFERRED'; }
			document.all.invalid.submit1.disabled=false;
			return true;
		} 
		else 
		{
			$("txtconsnoErr").innerHTML="Invalid Service No / Region";
			//$("txtconsno").innerHTML='';
			return false;
		}
		
	}
}


function namevalid()
{
  var nam=document.getElementById("txteyourname").value;

   if(nam=='')
	{
	  $("urrname").innerHTML = "Missing: Username";
//	  document.aldreg.txteyourname.focus();	
	  return false;
    }
	else
	{
	  $("urrname").innerHTML = "";	
	  document.all.ownten.txtemailid1.disabled=false;
	}
	return true;
}

function mailvalid()
{
  var mai=document.getElementById('txtemailid1').value;
   if(mai=='')
	{
	  $("urrmail").innerHTML = "Missing: 	E-mail id";
	// document.aldreg.txtemailid1.focus();	
	  return false;
    }
	else
	{
	  $("urrmail").innerHTML = "";
	   document.all.ownten.submit3.disabled=false;
	}
	return true;
}

function delconfirm()
{ 
	var payCons=document.getElementsByName('operate[]');
	for(i=0;i<=payCons.length-1;i++)
	{
		if(payCons[i].checked)
		{
		 
			//var del=confirm("Are you sure to delete the Consumer No (s)");
			val = agent.call('',"delconso","",payCons[i].value);
		}
	}
}
function deleteconfirm(){

		var payCons=document.getElementsByName('Delete');
		
				var del=confirm("Are you sure to delete the Consumer No ");
				
				return del;
			
}

function Checkpassword(){

var passwrd = $("txtpass").value;

if(passwrd.length < 6 && passwrd!=''  ) 
			{ 
					alert("Password should be Min 6  characters");
					$("txtpass").value="";
					//$("txtpass").focus();
					
			}	
			
			
}


function Checkrepass(){

var passwrd = $("txtpass").value;
var repasswrd = $("txtrepass").value;
if(passwrd!=repasswrd) 
			{ 
					alert("Confirm Password does not match");
					$("txtrepass").value="";
					//$("txtpass").focus();
					
			}	
			
			
}

function Checkaddress(){

var resaddress = $("txtresaddr");

if(resaddress.value.length > 250) 
			{ 
					alert("Address Fields allow Max 250 characters");
					$("txtresaddr").value="";
					$("txtresaddr").focus();
					
			}	
						
}

function Checkadd(){

var resaddress1 = $("txtaddr");

if(resaddress1.value.length > 250) 
			{ 
					alert("Address Fields allow Max 250 characters");
					$("txtaddr").value="";
					$("txtaddr").focus();
					
			}	
			
			
}


/*function Checksection(){

var section = $("txtsection");

if(section.value.length !=3 ) 
			{ 
					alert("Enter Valid Section Code");
					
					$("txtsection").focus();
					
			}	
			
			
}*/
function sumAmt(){
var pays=document.getElementsByName("pay[]");
var sum=0.0;
for(i=0;i<=pays.length-1;i++){
	if(pays[i].checked){
		var amt=pays[i].value.split(":");
		sum=sum+(parseFloat(amt[0]));
	}
}
document.getElementById('tPay').innerHTML=format(sum,2);
}

function format (expr, decplaces) {
var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces));
while (str.length <= decplaces) {
str = "0" + str;
}
var decpoint = str.length - decplaces;
return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
function assign(){
	var conNo=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	//var conNo=$("cno").value;
	var regNo=document.getElementById("creg").value;
	var payCons=document.getElementsByName('pay[]');
	for(i=0;i<=payCons.length-1;i++){
	temp=payCons[i].value.split(":")
		if(temp[1] == (regNo+conNo))
		{
			alert("Consumer No : "+conNo+" is already in the List");
			return false;
		}
	}
	params=regNo+":"+conNo;
	agent.call('',"consumerno","allocate",params);
	$("status").style.visibility="visible";
}
function addCNo(){
 	var newcusNo=$("txtsection").value+$("txtarea").value+$("txtservice").value;
	//var newcusNo=$("cno").value;
	var regNo=document.getElementById("creg").value;
	var ecno=document.getElementById("ecusno").value;
	
	var payCons=document.getElementsByName('operate[]');
	for(i=0;i<=payCons.length-1;i++){
		if(payCons[i].value == (regNo+newcusNo))
		{
			alert("Consumer No : "+newcusNo+" is already in the List");
			return false;
		}
	}
	params=ecno+":"+newcusNo+":"+regNo;
	agent.call('',"addCno","newcusHandle",params);
	
	$("status").style.visibility="visible";
} 

function progbar(){
	var bar=document.getElementById("status1");
	ProgressImage = document.getElementById("proimage");
	bar.style.visibility='visible';
	setTimeout("ProgressImage.src = ProgressImage.src",100);
	//return true;
	
	var bar1=document.getElementById("status2");
	//ProgressImage = document.getElementById("proimage");
	bar1.style.visibility='visible';
	//setTimeout("ProgressImage.src = ProgressImage.src",100);
	//return true;
	}
function newcusHandle(obj)
{
	//alert(obj);
	
	$("status").style.visibility="hidden";
	if(obj.indexOf('Invalid')== 0){
		alert("Please provide valid Consumer No");
	}
	else{
		var newvalue=obj.split(":");
		var cmctab=document.getElementById("cmc");
		var newcmc=cmctab.insertRow(cmctab.rows.length);
		var conserialNo=newcmc.insertCell(0);
		var consumerNo=newcmc.insertCell(1);
		var conName=newcmc.insertCell(2);
		var conAddress=newcmc.insertCell(3);
		var conOption=newcmc.insertCell(4);
		
		conserialNo.innerHTML=(cmctab.rows.length) - 1;
		
		consumerNo.innerHTML=newvalue[0];
		conName.innerHTML=newvalue[1];
		conAddress.innerHTML=newvalue[2];
		conOption.innerHTML='<input type="checkbox" value="'+ newvalue[0]+'" name="operate[]" />';
		conOption.align="center";
		$("top").style.visibility="hidden";
		$("txtsection").value="";
		$("txtarea").value="";
		$("txtservice").value="";
		$('acmc').disabled=false;
		$('scmc').disabled=false;
		
	}
}
function testAjax(obj)
{
	//var id=10
	//agent.call('',"test","testJs",id)
	var coors = findPos(obj);
	$("top").style.visibility="visible";
	$("top").style.top = eval(coors[1]+ 40) + 'px';
	$("top").style.left = eval(coors[0] )+ 'px';
	$('acmc').disabled=true;
	$('scmc').disabled=true;
}
function cancelOp(){
	$('top').style.visibility='hidden';
	$('status').style.visibility='hidden';
	$('acmc').disabled=false;
	$('scmc').disabled=false;
}
function allocate(obj)
{
	
	$("status").style.visibility="hidden";
	if((obj.indexOf('Invalid')== 0) || (obj.indexOf('Bill')== 0)){
		alert("Please provide valid Consumer No");
	}
	else{
		var newvalue=obj.split(":");
		var cmctab=document.getElementById("cmc");
		var newcmc=cmctab.insertRow(cmctab.rows.length);
		var conserialNo=newcmc.insertCell(0);
		var consumerNo=newcmc.insertCell(1);
		var conName=newcmc.insertCell(2);
		var conAddress=newcmc.insertCell(3);
		var conAmt=newcmc.insertCell(4);
		var conOption=newcmc.insertCell(5);
		conserialNo.innerHTML=(cmctab.rows.length) - 1;
		consumerNo.innerHTML=newvalue[0].substr(2);
		conName.innerHTML=newvalue[1];
		conAddress.innerHTML=newvalue[2];
		conAmt.innerHTML=newvalue[3];
		conAmt.align="right";
		conOption.innerHTML='<input onclick="sumAmt();" type="radio" value="'+newvalue[3]+':'+ newvalue[0]+'" name="pay[]" />';
		conOption.align="center";
		$("top").style.visibility="hidden";
		$("cno").value="";
		$('acmc').disabled=false;
		$('scmc').disabled=false;
	}
}
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		curWidth=obj.offsetTop
		while (obj == obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop,curWidth];
}
function chkPayment(){
	var pgc=document.getElementById("radpayment1").checked;
	var pgn=document.getElementById("radpayment2").checked;
	if(pgc || pgn)
	{
		return true;
	}
	else{
		alert("Please choose a Payment Mode");
		return false;		
	}
}

function recal(obj){
var msg = 'Please unselect in ascending order only';
var msg1 = 'Please select in descending order only';
var el, prevEl, nextEl, e = -1, f = obj.form;
while (el = f.elements[++e]) if (el == obj) {
prevEl = (f.elements[e-1]) ? f.elements[e-1] : null;
nextEl = (f.elements[e+1]) ? f.elements[e+1] : null;
break;
}
if ((nextEl && nextEl.type == 'checkbox' && nextEl.checked)) {
alert(msg);
el.checked=true;
}
if ((prevEl && prevEl.type == 'checkbox' && !prevEl.checked)) {
alert(msg1);
el.checked=false;
}

	var tab=document.getElementById("cmc");
	var ccharge=parseFloat(document.getElementById("cchargev").value);
	var totamt=parseFloat(document.getElementById("totamtv").value);
	var rlength=parseFloat(document.getElementById("rlen").value);
	var netamt=0.0;
	var rleng=rlength-1;
	var total=ccharge;
	
	if(tab.rows.length>rlength)
	    {
		   for(i=rleng;i<=tab.rows.length-1;i++)
		   {
			   if(tab.rows[i].cells[2].firstChild.checked)
				{
					var temp=tab.rows[i].cells[2].firstChild.value.split("-");
					total+=parseFloat(temp[4]);	
					//temp[3]=true;		
				}
	           else
			    {
				total+=0;
			    }
		    }		
        }
		
		
	 tab.rows[tab.rows.length-1].cells[1].innerHTML="Rs."+total;
	 //document.getElementById("totamtv").value=+total;
	if(document.getElementById('srvchg'))
	{
		var bcharge=(total*2.0946)/100;
		netamt=parseFloat(bcharge+total);
		var tab1=document.getElementById("cmc1");
		netamt=format(netamt,2)
		bcharge=format(bcharge,2)
		document.getElementById("srvchg").innerHTML=bcharge;
		tab1.rows[tab1.rows.length-1].cells[1].innerHTML="Rs."+netamt;
	}

return temp;
}

function confirmpay()
{
    if(document.all.frmUser.chbox.checked==true)
	{
	  document.all.frmUser.scmc.disabled=false;
	}
	if(document.all.frmUser.chbox.checked==false)
	{
	  document.all.frmUser.scmc.disabled=true;
	}

}

function js_array_to_php_array (a)
{
    var a_php = "";
    var total2 = 0;
    for (var key in a)
    {
        ++ total2;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total2 + ":{" + a_php + "}";
    return a_php;
}

function disbut(val){
document.forms.frmUser.login.disabled=true;

}

function dissub(val){
document.forms.frmUser.chkout1.disabled=true;

}
function dissub1(val){
document.forms.frmUser.chkout.disabled=true;

}

function in_order(box) {
var msg = 'Please delete these records in ascending order only, starting from the last.';
var el, prevEl, nextEl, e = -1, f = box.form;
while (el = f.elements[++e]) if (el == box) {
prevEl = (f.elements[e-1]) ? f.elements[e-1] : null;
nextEl = (f.elements[e+1]) ? f.elements[e+1] : null;
break;
}
if ((prevEl && prevEl.type == 'checkbox' && prevEl.checked) ||
(nextEl && nextEl.type == 'checkbox' && !nextEl.checked)) {
alert(msg);
return false;
}
return true;
}

//////////////Light Box///////////

var LightAlert = function (obj){
	this.fadetimer = null;
	this.browser = this.getBrowser();
	this.setting = this.setup(obj);
	this.body = parent.document.getElementsByTagName("body")[0];
	this.lightalert = this.createBox();
	this.overlay = {};
	this.init(obj);
}

LightAlert.prototype = {
	init: function(obj){
		THIS = this;
		this.overlay = this.displayOverlay(); //overlay
		this.displayMessage(obj); //box
		this.addEvent(window, "resize", function(){ THIS.getScroll() });
	},

	getBrowser: function(){
		b = navigator.userAgent.toLowerCase();
		if (b.indexOf('opera')!=-1) return 'opera';
		else if (b.indexOf('msie 7')!=-1) return 'ie7';
		else if (b.indexOf('msie')!=-1)  return 'ie6';
		else if (b.indexOf('safari')!=-1) return 'safari';
		else if (b.indexOf('gecko')!=-1)  return 'gecko';
	},

	setup: function(pars){
		var obj = {};
		if(this.browser=="ie6" || this.browser=="ie7" || this.browser=="safari" || this.browser=="gecko")
		{a=this.browser;}
		
		obj.interval = 50;
		obj.show = pars.show || "0";
		obj.fade = pars.fade || "1"; 
		obj.fadein = 0; // 100 = n
		obj.fadetime = 500; // half seconds
		obj.fadestep = 25;
		obj.pause = 5000; //pause 5 seconds before fading out
		obj.overlayOpac = 65;
		obj.font =  pars.font || "bold 15px Trebuchet MS";
	  //obj.position = this.browser == ("ie6" || "ie7") ? "absolute" : "fixed";	
		obj.position = a ? "absolute" : "fixed";	
		obj.bgcolor = pars.bgcolor || "#FFF";
		obj.border = pars.border || "1px solid #CCC";
		obj.icon = pars.icon || "./images/exclaim.gif";
		obj.w = pars.w || "300";
		obj.padding = "15px 15px 15px 59px";
		obj.bwidth = this.getBrowserWidth();
		return obj;
	},
	
	createBox: function(){
		box = document.createElement("div");
		box.style.font = this.setting.font;	
		box.style.padding = this.setting.padding;
		box.style.width = this.setting.w+"px";
		box.style.left = (this.setting.bwidth - this.setting.w) /2+"px";
		box.style.top = 0;
		box.style.position = this.setting.position;
		box.style.background = this.setting.bgcolor+" url("+this.setting.icon+") no-repeat 1em";
		box.style.border = this.setting.border;
		box.onclick = function(){THIS .destroy();}
		if (this.setting.fadein < 100){
			if (this.isIE())
				box.style.filter = "alpha(opacity="+this.setting.fadein+")";
			else
				box.style.opacity= this.setting.fadein / 100;
		}
		return box;
	},

	displayOverlay: function(){
		THIS = this;
		overlay = document.createElement("div");
		overlay.style.position = this.setting.position;
		overlay.style.backgroundColor = "#000";

		if (this.isIE())
			overlay.style.filter = "alpha(opacity="+this.setting.overlayOpac+")";
		else
			overlay.style.opacity= this.setting.overlayOpac/100;


		overlay.style.width = this.setting.bwidth+"px";
		overlay.style.height = this.getBrowserHeight()+"px";
		
		if (a==this.browser ){
			overlay.style.height = Math.max(document.documentElement.clientHeight,document.body.scrollHeight) + 30;
		}
		overlay.style.left = 0;
		overlay.style.top = 0;
		overlay.onclick = function(){
			THIS.destroy();
		}
		this.body.appendChild(overlay);
		return overlay;
	},

	displayMessage: function(obj){
		var msg;
		if (typeof(obj) == "string")
			msg = obj;
		if (typeof(obj) == "object")
			msg = obj.msg;

		msg = typeof(msg) == "undefined" ? "//Syntax Error: msg is not defined" : msg;
		
		this.lightalert.innerHTML = msg;
		this.body.appendChild(this.lightalert);
		//realign to middle
	//  box.style.top = (this.getBrowserHeight() - this.lightalert.clientHeight) / 2 +"px";
		box.style.top = ((document.body.scrollHeight - document.body.clientHeight) + (document.body.clientHeight / 3))  +"px";
	//  box.style.top = (this.getBrowserHeight()) / 1 +"px";
		this.fadeIn();
	},
	
	fadeIn: function(){
		THIS = this;
		if (this.setting.fadein < 100 && this.setting.fade=="1"){
			this.setting.fadein += this.setting.fadestep;
			if (this.isIE()) {
				this.lightalert.style.filter = "alpha(opacity="+this.setting.fadein+")";
			}else{
				this.lightalert.style.opacity=this.setting.fadein/100;
			}
			this.fadetimer = setTimeout(function(){THIS.fadeIn()},this.setting.interval);
		}else{
			if (this.setting.fade=="0"){
				if (this.isIE())
					this.lightalert.style.filter = 100;
				else
					this.lightalert.style.opacity=1;
			}
			clearTimeout(this.fadetimer);
			if (this.setting.show == "0")
				setTimeout(function(){THIS.fadeOut()},this.setting.pause);
		}	
	},

	fadeOut: function(){
		THIS = this;
		if (this.setting.fadein > 0 && this.setting.fade=="1"){
			this.setting.fadein -= this.setting.fadestep;
			if (this.isIE()) {
				this.lightalert.style.filter = "alpha(opacity="+this.setting.fadein+")";
			}else{
				this.lightalert.style.opacity=this.setting.fadein/100;
			}
			this.fadetimer = setTimeout(function(){THIS.fadeOut()},this.setting.interval);
		}else{
			clearTimeout(this.fadetimer);
			this.destroy();
		}
	},

	destroy: function(){
		try{
			THIS = this;
			clearTimeout(this.fadetimer);
			this.body.removeChild(this.lightalert);
			this.body.removeChild(this.overlay);
			this.removeEvent(window, "resize", function(){THIS.getScroll()});
		}catch(e){}
	},
	
	isIE: function(){
		if (this.browser == "ie6" || this.browser == "ie7")
			{return true;}
			else{return false;}
	},

	getScroll: function(){
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
		this.lightalert.style.left = (w - this.setting.w) /2+"px";
		this.lightalert.style.top = (this.getBrowserHeight() - this.setting.h) /2+"px";

		this.overlay.style.width = this.getBrowserWidth()+"px";
		this.overlay.style.height = this.getBrowserHeight()+"px";
		if (this.browser == "ie6"){
			this.overlay.style.height = Math.max(document.documentElement.clientHeight,document.body.scrollHeight) + 30;
		}
		return t;
	},
	
	getBrowserWidth: function(){
		if (window.innerWidth){
			return window.innerWidth;
		}else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;}
		else if (document.body){
			return document.body.clientWidth;
		}
		return 0;
	},

	getBrowserHeight: function(){
		if (window.innerHeight){
			return window.innerHeight;
		}else if (document.documentElement && document.documentElement.clientHeight != 0){
			return document.documentElement.clientHeight;}
		else if (document.body){
			return document.body.clientHeight;
		}
		return 0;
	},

	addEvent: function( obj, type, fn ) { 
		if ( obj.attachEvent ) { 
			obj['e'+type+fn] = fn; 
			obj[type+fn] = function(){obj['e'+type+fn]( window.event );} 
			obj.attachEvent( 'on'+type, obj[type+fn] ); 
		} else 
			obj.addEventListener( type, fn, false ); 
	},

	removeEvent: function ( obj, type, fn, funcObj ) { 
		THIS = this;
		if ( obj.detachEvent ) { 
			obj.detachEvent( 'on'+type, obj[type+fn] ); 
			obj[type+fn] = null; 
		} else {
			obj.removeEventListener( type, fn, false ); 
			
		}
	}
}

function alert(obj){
	new LightAlert(obj);
}
