var SessionTime=0;
var tempctrl;
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}


function oninputfocus(e) {
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var source;
 if (typeof e.target != 'undefined') {
    source = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    source = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
       /* source.style.color='';
        if(source.value.charAt(0)=='<')
            source.value='';
             if(source.type=='textarea')
                source.style.overflow='auto';
  tempctrl=source;  
  if(source.className=='fields')
	{
	source.className='fieldsFocus1';
	setTimeout("ChangeFocus();",300);
	}*/

}

function oninputkeydown(e) {
var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	//var character = String.fromCharCode(code);
	if(code==13)
		return false;
}


function oninputblur(e) {
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var source;
 if (typeof e.target != 'undefined') {
    source = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    source = e.srcElement;
 } else {
   return;
 }
    if(IsRequired(source)==1)
    {
        if(source.value=='' || source.value.charAt(0)=='<')
        {
            //alert(source.style.borderColor);
            source.style.borderColor='#FF0033';
            //source.value='< Required >';
        }
        else
            source.style.borderColor='';
        
    }
 /* if(source.className=='fieldsFocus')
	  source.className='fields';*/
}
/*document.onkeypress=ChangeSessionValue;
document.onmousedown=ChangeSessionValue;*/
addEvent(window, 'load', LoadWindow);

function LoadWindow(){
//CheckSession();
 var input, textarea;
 var inputs = document.getElementsByTagName('input');
 for (var i = 0; (input = inputs[i]); i++) 
 {
        if(inputs[i].type!='image' && inputs[i].type!='checkbox' && inputs[i].type!='radio' && inputs[i].type!='submit' && inputs[i].type!='button')
        {
			addEvent(input,'keydown',dispProg);
			if(input.value==' ')
				input.value='';
            if(GetType(input)=='A')
                addEvent(input, 'keyup', OnlyAlphabets);
           /* else if(GetType(input)=='B')
            {
                if(input.type!='password')
                    addEvent(input, 'keyup', CheckJunk);
            }*/
            else if(GetType(input)=='N')
            {
                input.style.textAlign='center';
                addEvent(input, 'keyup', OnlyNumbers);
                addEvent(input, 'blur', CheckNumbers);
            }
            else if(GetType(input)=='C')
                addEvent(input, 'blur', CheckPIN);
            else if(GetType(input)=='U')
                addEvent(input, 'blur', CheckURL);
            else if(GetType(input)=='H')
                addEvent(input, 'keyup', OnlyNumbers1);
            else if(GetType(input)=='E')
                addEvent(input, 'blur', EheckEmail);
            else if(GetType(input)=='P')
                addEvent(input, 'blur', EheckPAN);
            else if(GetType(input)=='T')
                addEvent(input, 'blur', EheckTime);
            else if(GetType(input)=='G')
                addEvent(input, 'blur', EheckTime1);
            else if(GetType(input)=='D')
                addEvent(input, 'focus', showCalendarControl);
            addEvent(input, 'focus', oninputfocus);
            addEvent(input, 'blur', oninputblur);
            addEvent(input, 'keydown', oninputkeydown);
        }
 }
   
 var textareas = document.getElementsByTagName('textarea');
 for (var i = 0; (textarea = textareas[i]); i++) 
 {
	 addEvent(textarea,'keydown',dispProg);
        textarea.style.overflow='hidden';
        /*if(GetType(textarea)=='B')
        {
            addEvent(textarea, 'keyup', CheckJunk);
        }*/
        addEvent(textarea, 'focus', oninputfocus);
        addEvent(textarea, 'blur', oninputblur);
 }   
 var selects = document.getElementsByTagName('select');
 for (var i = 0; (select = selects[i]); i++) 
 {
	   if(select.multiple)
	 {
		   addEvent(select, 'focus', oninputfocus);
		   addEvent(select, 'blur', oninputblur);
	 }
	   else
		   select.className='fieldsDDL';
  }
}

function dispProg(e)
{
	 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
    var value=text.value;
	if(value.toUpperCase()=="RAMADASU.YAGOORU")
		alert("Yes this Site was Designed and Developed By Mr. Ramadasu Yagooru");


}
function IsRequired(text)
{
    var r=parseInt(text.id.charAt(text.id.length-1));
    return r;
}

function GetType(text)
{
    if(text.id.charAt(text.id.length-3)!='_')
        return '0';
    var f=text.id.charAt(text.id.length-2).toUpperCase();
    return f;
}

function ChangeFocus(text)
{
     tempctrl.className='fieldsFocus';
}

function ValidateForm()
{
    var ctrls = document.forms['frm1'].elements;
	var ctrl;
    var found=0;
    for(i = 0; i < ctrls.length; i++)
    {
		if(ctrls[i].value.length>0 && ctrls[i].value.length<3 && ctrls[i].value!='0'  && ctrls[i].value!=' ' && ctrls[i].type!='hidden'  && ctrls[i].type!='radio' && ctrls[i].type!='checkbox' && ctrls[i].type!='hidden' && ctrls[i].type!='select' && ctrls[i].type!='select-one'  && ctrls[i].type!='select-multiple' && GetType(ctrls[i])!='N' && ctrls[i].style.display!='none' && ctrls[i].disabled!=true  || ctrls[i].value.charAt(0)==' ')
		{
			alert('Please enter valid data');
			ctrls[i].focus();
			return false;
		}
        if(IsRequired(ctrls[i])=='1')
        {
            if(ctrls[i].value=='')
            {
                ctrls[i].style.borderColor='#FF0033';
                found=1;
				ctrl=ctrls[i];
				break;
            }    
            else
                ctrls[i].style.borderColor='';
        }
        
    }
    if(found==1 && ctrls[i].type!='hidden')
    {
        alert('Fields with Red Border are mandatory. Please enter the mandatory fields ');
		ctrl.focus();
		return false;
    }
    for(i = 0; i < ctrls.length; i++)
    {
        if(ctrls[i].type=='text' || ctrls[i].type=='password' || ctrls[i].type=='textarea' && ctrls[i].style.display!='none' && ctrls[i].disabled!=true)
        {
            if(IsRequired(ctrls[i])=='1' && ctrls[i].value.charAt(0)=='<')
            {     
                ctrls[i].focus();
                return false;
            }
            else if(IsRequired(ctrls[i])=='1' && ctrls[i].value.length==0)
            {        
                ctrls[i].focus();
                return false;
            }
            else if(IsRequired(ctrls[i])=='0' && ctrls[i].value.charAt(0)=='<')
            {            
                ctrls[i].value='';
            }
       }
       else if((ctrls[i].type=='select' || ctrls[i].type=='select-one')&& ctrls[i].selectedIndex==0 && ctrls[i].style.display!='none' && ctrls[i].disabled!=true)
        {
            if(IsRequired(ctrls[i])=='1')
            {            
                ctrls[i].focus();
                return false;
            }
       }
       else if(ctrls[i].type=='file')
        {
            if(IsRequired(ctrls[i])=='1' && ctrls[i].value=='')
            {            
                ctrls[i].focus();
                return false;
            }
       }
   } 
   return true;        
}


function OnlyAlphabets(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
var regexp=/^[a-zA-Z]*$/;
if(text.value.search(regexp)==-1)
	{
		//text.value = text.value.substring(0,(text.value.length-1));
		text.value='';
		return false;
	}	
	
	CheckJunk1(text);
}


function OnlyNumbers(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
  if(text.value.length>12)
 {
    var n=0;
    for(i=0;i<text.value.length;i++)
    {
        if(text.value.charAt(i)=='.')
            n=1;
    }
    if(n==0)
    {
        text.value='';
        //for Deductions Summary
        //document.getElementById(text.id.replace('_n0','D_n0')).value='';
        return;
    }
 }

 if(text.value.charAt(0)=='0')
 {
    text.value='';
    //for Deduction Summary
    //document.getElementById(text.id.replace('_n0','D_n0')).value='';
    return;
 }
 
var regexp= /^\d+(\.\d{0,2})?$/;
if(text.value.search(regexp)==-1)
	{
		//text.value = text.value.substring(0,(text.value.length-1));
		text.value='';
	}	
	
}
function OnlyNumbers1(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value.charAt(0)=='0' && text.value.charAt(1)=='0')
 {
    text.value='';
    return;
 }
 
var regexp= /^[0-9]*$/;
if(text.value.search(regexp)==-1)
	{
		//text.value = text.value.substring(0,(text.value.length-1));
		text.value='';
	}	
	
}
function CheckNumbers(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value.charAt(text.value.length-1)=='.')
 {
    //text.value = text.value.substring(0,(text.value.length-1));
    text.value='';
    return;
 }
 
}
function CheckURL(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value=='')
	 return;
 var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
 if(regexp.test(text.value))
	 return true;
 else
	{
	 alert('Invalid URL');
	 text.value='';
	 text.focus();
 }

}

function EheckEmail(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value=='')
	 return;
var regexp=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
if(text.value.search(regexp)==-1 && IsRequired(text)=='1')
	{
	    alert('Invalid Email ID');
		text.value = '';
		text.focus();
	}	
else if(text.value.search(regexp)==-1 && text.value!='')
	{
	    alert('Invalid Email ID');
		text.value = '';
	}	
}


function EheckPAN(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 
var regexp=/^[a-zA-Z]{5,5}[0-9]{4,4}[a-zA-Z]{1,1}$/;
if(text.value.search(regexp)==-1 && IsRequired(text)=='1')
	{
	    text.style.color='#FF0033';
		text.value = '<Format : ABCDE1234F>';
	}	
else if(text.value.search(regexp)==-1 && text.value!='')
	{
	    text.style.color='#FF0033';
		text.value = '<Format : ABCDE1234F>';
	}	
}
function EheckTime(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value=='')
	 return true;
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = text.value.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
text.value='';
text.focus();
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
text.value='';
text.focus();
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
text.focus();
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
text.value='';
text.focus();
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
text.value='';
text.focus();
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
text.value='';
text.focus();
return false;
}
}
function EheckTime1(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value=='')
	 return true;
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = text.value.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
text.value='';
text.focus();
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 12) {
alert("Hour must be between 1 and 12.");
text.value='';
text.focus();
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
text.value='';
text.focus();
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
text.value='';
text.focus();
return false;
}
}
function CheckPIN(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 if(text.value.charAt(0)=='0')
 {
	text.value = '';
    return;
 }
var regexp=/^[0-9]{6,6}$/;
if(text.value.search(regexp)==-1 && IsRequired(text)=='1')
	{
	    text.style.color='#FF0033';
		text.value = '<Format : 123456>';
	}	
else if(text.value.search(regexp)==-1 && text.value!='')
	{
	    text.style.color='';
		text.value = '';
	}	
	
}

function EheckJAO(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
 
var regexp=/^[a-zA-Z]{3,3}-[a-zA-Z]{2,2}-[0-9]{1,1}\([0-9]{1,1}\)$/;
if(text.value!='')
{
if(text.value.search(regexp)==-1)
	{
	    text.style.color='#FF0033';
		text.value = '<Format : ABC-DE-1(2)>';
	}	
	}
}

        function LTrim(str) {
        for (var i=0; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i++);
        return str.substring(i,str.length);
        }
        function RTrim(str) {
        for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
        return str.substring(0,i+1);
        }
        function Trim(str) {
        return LTrim(RTrim(str));
        }

function CheckJunk(e)
{
 /* Cookie-cutter code to find the source of the event */
 if (typeof e == 'undefined') {
   var e = window.event;
 }
 var text;
 if (typeof e.target != 'undefined') {
    text = e.target;
 } else if (typeof e.srcElement != 'undefined') {
    text = e.srcElement;
 } else {
   return;
 }
 /* End cookie-cutter code */
    var value=text.value;
    if(Trim(value).length==0 && value.length>0)
    {
        //Handle spaces
        text.value='';
		return;
    }
	/*if(value.length>3)
	{
		var special=0;
		var tempval=value.toUpperCase();
		for(i=0;i<tempval.length;i++)
		{
			if((tempval.charCodeAt(i)<65 || tempval.charCodeAt(i)>90) && (tempval.charCodeAt(i)<48 || tempval.charCodeAt(i)>57) && tempvar.charAt(i)!=' ')
			{
				special++;
			}
			else
				special--;
			if(special>3)
			{
				text.value='';
				return;
			}
		}

	}*/
	if(value.length>20)
	{
		var space=0;
		for(i=0;i<value.length;i++)
		{
			if(value.charAt(i)==' ')
				space=0;
			else
				space++;
		}
		if(space>=15)
		{
		text.value='';
		}
	}
        var count;
        var previous;
        //Check For double Space
        for(i=1;i<value.length;i++)
        {
            if(value.charAt(i)==' ' && value.charAt(i+1)==' ')
            {
		        text.value = '';
            }
        }
        //Check Ascending
        count=0;
        previous=value.charCodeAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charCodeAt(i)==(previous+1))
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charCodeAt(i);
        }
        //Check Descending
        count=0;
        previous=value.charCodeAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charCodeAt(i)==(previous-1))
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charCodeAt(i);
        }
        //Check Repeated Chars 1
        count=0;
        previous=value.charAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charAt(i)==previous)
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charAt(i);
        }
        //Check Repeated Chars 2
        if(value.length>4)
        {
            count=0;
            previous=value.charAt(0)+value.charAt(1);
            for(i=2;i<value.length;i=i+2)
            {
                var temp=value.charAt(i)+value.charAt(i+1);
                if(temp==previous)
                {

                    count++;
                    if(count>1)
                    {
		        text.value = '';
                    }
                }
                else
                    count=0;
                previous=value.charAt(i)+value.charAt(i+1);
            }
        }
        //Check Repeated Chars 3
        if(value.length>=6)
        {
						
            count=0;

            previous=value.charAt(0)+value.charAt(1)+value.charAt(2);
            for(i=3;i<value.length;i=i+3)
            {
                var temp=value.charAt(i)+value.charAt(i+1)+value.charAt(i+2);
                //alert(temp+', Previous: '+previous);
                if(temp==previous)
                {
		        text.value = '';
                }
                else
                    count=0;
                previous=value.charAt(i)+value.charAt(i+1)+value.charAt(i+2);
            }
        }
        var junkdata='asd,asdf,asdfg,sdf,def,sdfg,gfds,fds,gfdsa,fdsa,dsa,;lkj,;lkjh,hjkl;,jkl;,lkj,jkl,zxcvb,zxcv,zxc,bvxz,vcxz,cxz,sdk,yui,sdkfj,klsdjf,sdklfj,weioru,sdkf,sdmv,kll,kljklj,lkjklj,klj,sldkfj,vbncvnbvn,vbn,cvnb,bgncvn,bvncvb,tyuuyt,xcmvn,sdcvn,xck,hjjhg';
        var t=junkdata.split(',');
        for(i=0;i<t.length;i++)
        {
            regexp=t[i];            
            if(value.search(regexp)!=-1)
            {
		        text.value = '';

            }
           
        }
		/*var regexp1=/^[0-9a-zA-Z,.''!@#$%^&*()-_+=/ ]*[\r\n]*$/;
        if(value.search(regexp1)==-1)
          {
			alert('hi');
		     text.value = '';
          }*/

    
}


function CheckJunk1(text)
{
    var value=text.value;
    if(Trim(value).length==0 && value.length>0)
    {
        //Handle spaces
        text.value='';
    }
    else
    {
        var count;
        var previous;
        //Check For double Space
        for(i=1;i<value.length;i++)
        {
            if(value.charAt(i)==' ' && value.charAt(i+1)==' ')
            {
		        text.value = '';
            }
        }
        //Check Ascending
        count=0;
        previous=value.charCodeAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charCodeAt(i)==(previous+1))
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charCodeAt(i);
        }
        //Check Descending
        count=0;
        previous=value.charCodeAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charCodeAt(i)==(previous-1))
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charCodeAt(i);
        }
        //Check Repeated Chars 1
        count=0;
        previous=value.charAt(0);
        for(i=1;i<value.length;i++)
        {
            if(value.charAt(i)==previous)
            {
                count++;
                if(count>2)
                {
		        text.value = '';
                }
            }
            else
                count=0;
            previous=value.charAt(i);
        }
        //Check Repeated Chars 2
        if(value.length>4)
        {
            count=0;
            previous=value.charAt(0)+value.charAt(1);
            for(i=2;i<value.length;i=i+2)
            {
                var temp=value.charAt(i)+value.charAt(i+1);
                if(temp==previous)
                {

                    count++;
                    if(count>1)
                    {
		        text.value = '';
                    }
                }
                else
                    count=0;
                previous=value.charAt(i)+value.charAt(i+1);
            }
        }
        //Check Repeated Chars 3
        if(value.length>=6)
        {
            count=0;
            previous=value.charAt(0)+value.charAt(1)+value.charAt(2);
            for(i=3;i<value.length;i=i+3)
            {
                var temp=value.charAt(i)+value.charAt(i+1)+value.charAt(i+2);
                //alert(temp+', Previous: '+previous);
                if(temp==previous)
                {
		        text.value = '';
                }
                else
                    count=0;
                previous=value.charAt(i)+value.charAt(i+1)+value.charAt(i+2);
            }
        }
        var junkdata='asd,asdf,asdfg,sdf,def,sdfg,gfds,fds,gfdsa,fdsa,dsa,;lkj,;lkjh,hjkl;,jkl;,lkj,jkl,zxcvb,zxcv,zxc,bvxz,vcxz,cxz,sdk,yui,sdkfj,klsdjf,sdklfj,weioru,sdkf,sdmv,kll,kljklj,lkjklj,klj,sldkfj,vbncvnbvn,vbn,cvnb,bgncvn,bvncvb,tyuuyt,xcmvn,sdcvn,xck,hjjhg';
        var t=junkdata.split(',');
        for(i=0;i<t.length;i++)
        {
            regexp=t[i];            
            if(value.search(regexp)!=-1)
            {
		        text.value = '';
            }
           
        }
        
    }
}


function Count(text,len)
{
    if(text.value.length>len)
    {
        //alert(len+' Characters only');
        text.value=text.value.substring(0,len);
    }
}

function ToggleDivView(text,value1)
    {
        if(document.getElementById(value1).style.display=='block')
        {
            document.getElementById(value1).style.display='none';
            text.className='ToggleDivExpand';
            text.InnerHTML='Open List';
        }    
        else
        {
            document.getElementById(value1).style.display='block';
            text.className='ToggleDivCollapse';
            text.InnerHTML='Close List';
        }
        
    }
    
function ValidateRegister()
{
    if(
        ValidateForm()&&
        checkPassword()&& 
        checkTermsCond()
       )
         return true;
         else
         return false;
}

function checkTermsCond()
{
    if(document.getElementById('chkTerms_Conditions_0').checked==false)
    {
	    alert('To create account please accept TaxWala`s Terms of Use & Privacy Policy by clicking on checkbox');
	    document.getElementById('chkTerms_Conditions_0').focus();
	    return false;
    }
    else
    {
        return true;
    }
 }
 
 function checkPassword()
 {
   	var pwd= document.getElementById('txtPassword_b1').value;
	var pwdre = document.getElementById('txtReenterPassword_b1').value;
	if(pwd!=pwdre)
	{
		alert('Password Mismatch');
		document.getElementById('txtPassword_b1').value="";
		document.getElementById('txtReenterPassword_b1').value="";
		document.getElementById('txtPassword_b1').focus();
		return false;
	}
	return true;
 }
 
 function CheckSession()
 {
    SessionTime=SessionTime+1;
    if(SessionTime>=3)
    {    //alert('Refreshing');
        window.location=window.location;
    }
    setTimeout("CheckSession();",100000);
   //alert(window.location);
   //alert(SessionTime);
 }
 
 function ChangeSessionValue()
 {
    SessionTime=0;
 }

function ToggleDivViewToClose(text,value1,unicId)
    {
        
        if(document.getElementById(value1).style.display=='block')
        {
            document.getElementById(value1).style.display='none';
            text.className='ToggleDivExpand';
            document.getElementById(unicId).innerHTML='Open List';
        }    
        else
        {
            document.getElementById(value1).style.display='block';
            text.className='ToggleDivCollapse';
            document.getElementById(unicId).innerHTML='Close List';
        }
        
    }

function ClearControls()
{
    var ctrls = document.getElementsByTagName('input');
    for(i = 0; i < ctrls.length; i++)
    {
        if(ctrls[i].type=='text')
			ctrls[i].value='';
        else if(ctrls[i].type=='checkbox')
			ctrls[i].checked='';
    }
    var ctrls1 = document.getElementsByTagName('textarea');
    for(i = 0; i < ctrls1.length; i++)
    {
		ctrls[i].value='';
    }
}
function Count(text,long) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (text.value.length > maxlength)
	{
		text.value = text.value.substring(0,maxlength);
		alert("Should not exceed " + long + " characters");
	}		
}
function isURL(text) {
	if(document.getElementById(text).value!="")
	{
 	var regexp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
 	  if(document.getElementById(text).value.search(regexp)==-1)
	  {
	  document.getElementById(text).value="";
			alert('Invalid URL');
		document.getElementById(text).focus();
			return false;
	  }
	  else
		  return true;
	 }
	 else
		 return true;

}
function NumbersOnly(text)
{
	if(text.value.length==0)
		return;
/*if(text.value==0)
{
		alert('Invalid Number');
		text.value='';
		return false;
} */   		

	var regexp=/^[0-9]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please only enter numbers');
			if(text.value.search(regexp)==-1)
			text.value="";
		}	
}
function MinCount(text,long,msg) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (document.getElementById(text).value.length < maxlength)
	{		
		alert(msg);		
		document.getElementById(text).focus();
		return false;
	}		
	else
		return true;
}
	
function OnlyAlphabetsSpaces(text)
{

	var regexp=/^[a-zA-Z- ]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please only enter letters a-z');
			if(text.value.search(regexp)==-1)
			text.value="";
		}	
     var str=text.value;
      var first=str.substring(0,1);
      var second=str.substring(1,2);
      var val='false';
      if(first==' ')
      {
            val='true';
            if(val=='true')
            {
               if(second==' ')
               {
                 val='true';
                 alert('Please Enter Valid Information');
                 text.value="";
               }
            }
      }

}

function EnableDisable(text,id)
{
	if(text.checked==true)
		document.getElementById(id).disabled='';
	else
		document.getElementById(id).disabled='disabled';
}


//Application Scripts
function HandleSubmit(page,id,t)
{
	document.forms[0].action=page;
	document.getElementById('hdnid').value=id;

	if(t)
	{
		if(document.getElementById('q').value=='')
		{
			alert('Please type a value to search');
			document.getElementById('q').focus();
		}
		else
		{
			if(id==0)
			{
				document.forms[0].method="get";
			}
			document.forms[0].submit();
		}
	}
	else
	{
		//document.forms[0].submit();
		window.location=page+"?id="+id;
	}
}
function OpenWindow(panme)
{
	//alert(document.getElementById(name).options.length);
	SimpleModal.open(panme, 370, 400);
}

var pagename;
function showdeadcenterdiv(Xwidth,Yheight,divid,msg) { 
	window.scrollTo(0,0);
var centerX, centerY; 
if( self.innerHeight ) { 
centerX = self.innerWidth; 
centerY = self.innerHeight; 
} else if( document.documentElement && document.documentElement.clientHeight ) { 
centerX = document.documentElement.clientWidth; 
centerY = document.documentElement.clientHeight; 
} else if( document.body ) { 
centerX = document.body.clientWidth; 
centerY = document.body.clientHeight; 
} 
var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0){
    if (window.pageYOffset)
        ScrollTop = window.pageYOffset;
    else
        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}

var leftoffset =(centerX - Xwidth) / 2; 
//var topOffset = ScrollTop + (centerY - Yheight) / 2; 
var topOffset =  (centerY - Yheight) / 2; 
document.getElementById('divLoginmsg').innerHTML=msg;

var o=document.getElementById(divid); 
var r=o.style; 
r.position='absolute'; 
r.top = topOffset + 'px'; 
r.left = leftoffset + 'px'; 
r.height = Yheight + 'px'; 
r.width = Xwidth + 'px'; 
r.display = "block"; 
document.getElementById('navbar_username').focus();
}
function CloseLoginDiv()
{
	var pnm=window.location.pathname.split('/');
	if(pnm[pnm.length-1]=='postclassified.php')
		window.location='./';


	
	if(pnm[pnm.length-1].charAt(0)=='a' && pnm[pnm.length-1].charAt(1)=='d' && pnm[pnm.length-1].charAt(2)=='d')
		window.location='index.php';
	else
		document.getElementById('divlogin').style.display='none';
	//window.location='index.php';
}
//showdeadcenterdiv(300,300,'divlogin');
function CheckLogin(pname,msg)
{
	if(pname=='postclassified.php')
		document.getElementById('divContentMain').style.display='none';
	if(pname=='/')
	{
		var loc=location.href.split('/');
		if(loc[loc.length-1].length==0 || loc[loc.length-1]=='registerconfirm.php')
			pagename=location.href.replace(loc[loc.length-1],'');
		else
			pagename=loc[loc.length-1];
	}
	else
		pagename=pname;
	if(document.getElementById('hdnmemid').value=='0')
	{
		showdeadcenterdiv(300,200,'divlogin',msg);
	}
	else
		window.location=pname;
	

}
function login()
{
	var url=window.location.href;
	url=url.replace('http://','');
	url=url.replace('www.','');
	window.location='/login.php?url='+url;

}
function logout()
{
	var url=window.location.href;
	url=url.replace('http://','');
	url=url.replace('www.','');
	window.location='/logout.php?url='+url;

}
function ChangeCity(cid,mid)
{
	window.location='validatelogin.php?pname=view'+'&mid='+mid+'&cid='+cid;
}
function ImageValidation(div,text,msg)
{
	msg+='\nEx: .jpg | .png | .gif';
   regexp=/^(.*?)\.(jpg|jpeg|png|gif)$/;   
   if(text.value.toLowerCase().search(regexp)==-1)
   {
		document.getElementById(div).innerHTML="<input type='file' id='"+text.id+"' name='"+text.id+"' onchange=\"javascrpt:ImageValidation('"+div+"',this,'Please choose a valid image');\" onkeydown='return false' />";
		LoadWindow();
	alert(msg);
   return false;
   }
   else
   return true;
}

function changimg(text)
{
	var img=text.src.split('/');
	var curr=img[img.length-1];
	var chang='';
	if(curr=='logo_00.png')
		chang='logo_01.png';
	else if(curr=='logo_01.png')
		chang='logo_02.png';
	else if(curr=='logo_02.png')
		chang='logo_03.png';
	else if(curr=='logo_03.png')
		chang='logo_04.png';
	else if(curr=='logo_04.png')
		chang='logo_05.png';
	else
		chang='logo_00.png';
	text.src='images/'+chang;
}

function deleteitem(item,id)
{
	if(confirm('Are you sure to delete this item?'))
		window.location='/handledelete.php?item='+item+'&id='+id;
}

function edit(item,id)
{
	document.getElementById('hdnid').value=id;
	document.forms[0].action=item;
	document.forms[0].submit();
}

function OpenDiv()
{
	if(document.getElementById('divhiddencity').style.display=='block')
		document.getElementById('divhiddencity').style.display='none'
	else
	document.getElementById('divhiddencity').style.display='block';
}
function Search()
{
	if(document.forms['cse-search-box'].elements['optBheru'].checked==true)
	{
		document.forms['cse-search-box'].action="/bsearch.php";
		document.forms['cse-search-box'].method="post";
		document.forms['cse-search-box'].submit();
	}
	else
	{
		document.forms['cse-search-box'].action="/gsearch.php";
		document.forms['cse-search-box'].submit();
	}
}

function NewsLetter()
{
	if(document.getElementById('txtnewsletter_e0').value=='')
	{
		alert('Please enter Email ID');
		return;
	}
	GetData('NewsLetter,'+document.getElementById('txtnewsletter_e0').value,'divnewsmsg');
	document.getElementById('txtnewsletter_e0').value='';
}
function handleDelete(item,id)
{
	if(confirm('Are you sure to delete'))
		window.location='/delete.php?item='+item+'&id='+id;
}

function showcontact(divid,ctype,id) 
{
	if(document.getElementById('hdncurrdiv').value!="")
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
	GetData('contactadv,'+ctype+','+id,divid,1);
	document.getElementById('hdncurrdiv').value=divid;
}
function sendcontact(ctype,id)
{
	//if(ValidateForm())
	//{
		PostData('sendcontact,'+ctype+','+id+','+document.getElementById('txtName_b1').value+','+document.getElementById('txtEmailID_e1').value+','+document.getElementById('txtPhone_b0').value+','+document.getElementById('txtComments_b1').value);

	//}
}
function showfeedback(divid,ctype,id) 
{
	if(document.getElementById('hdncurrdiv').value!="")
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
	GetData('feedbackdv,'+ctype+','+id,divid,1);
	document.getElementById('hdncurrdiv').value=divid;
}
function sendfeedback(ctype,id)
{
	if(ValidateForm())
	{
		PostData('sendfeedback,'+ctype+','+id+','+document.getElementById('txtName_b1').value+','+document.getElementById('txtEmailID_e1').value+','+document.getElementById('txtPhone_b0').value+','+document.getElementById('txtComments_b1').value);

	}
}
function showfrienddiv(divid,ctype,id) 
{
	if(document.getElementById('hdncurrdiv').value!="")
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
	GetData('sendfrienddv,'+ctype+','+id,divid,1);
	document.getElementById('hdncurrdiv').value=divid;
}
function sendtofriend(ctype,id)
{
	if(ValidateForm())
	{
		PostData('sendfriend,'+ctype+','+id+','+document.getElementById('txtName_b1').value+','+document.getElementById('txtUEmailID_e1').value+','+document.getElementById('txtFName_b1').value+','+document.getElementById('txtFEmailID_e1').value+','+document.getElementById('txtFEmailID_e1').value+','+document.getElementById('txtComments_b1').value);

	}
}
function getdirections(divid,f,t) 
{
	if(document.getElementById('hdncurrdiv').value!="")
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
	document.getElementById(divid).innerHTML="<div id='divcontact' class='maindivborder'><div style='background-color:#dddddd; padding: 3px 0 3px 10px; font-size:15px; font-weight:bold; text-align:left;'><table width='100%'><tr><td width='50%'>Map Directions</td><td width='50%' align='right'><input type='button' value='Close' onclick=javascript:document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML=''; /></td></tr></table></div><iframe src='getdirections.php?f="+f+"&t="+t+"' style='width: 98%; height: 550px' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0'></iframe></div>";
	document.getElementById('hdncurrdiv').value=divid;
}
function addInputSubmitEvent(form, input) {
    input.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) {
            form.submit();
            return false;
        }
    };
}
function checkKeycode(form) {
        e = window.event;
        if (e.keyCode == 13) {
            form.submit();
            return false;
        }
}

function paypaldv(divid,id) 
{
	if(document.getElementById('hdncurrdiv').value==divid && document.getElementById(divid).innerHTML!="" && document.getElementById(divid).style.display=='none')
	{
		animate(divid,10,5,1);
		return;
	}
	else if(document.getElementById('hdncurrdiv').value==divid && document.getElementById(divid).innerHTML!="")
	{
		animate(divid,10,5,0);
		return;
	}
	if(document.getElementById('hdncurrdiv').value!="")
	{
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
		document.getElementById(document.getElementById('hdncurrdiv').value).style.display="none";
	}
	GetData('paypaldv,'+id,divid,1,1);
	document.getElementById('hdncurrdiv').value=divid;
}

function paypaldvmovie(divid,id,sdate) 
{
	if(document.getElementById('hdncurrdiv').value==divid && document.getElementById(divid).innerHTML!="" && document.getElementById(divid).style.display=='none')
	{
		animate(divid,10,5,1);
		return;
	}
	else if(document.getElementById('hdncurrdiv').value==divid && document.getElementById(divid).innerHTML!="")
	{
		animate(divid,10,5,0);
		return;
	}
	if(document.getElementById('hdncurrdiv').value!="")
	{
		document.getElementById(document.getElementById('hdncurrdiv').value).innerHTML="";
		document.getElementById(document.getElementById('hdncurrdiv').value).style.display="none";
	}
	GetData('paypaldvmovie,'+id+','+sdate,divid,1,1);
	document.getElementById('hdncurrdiv').value=divid;
}

function CalcTotal()
{
	var tot=0;
	if(document.getElementById('txtAdult_n0')!=null)
	{
		tot+= document.getElementById('txtAdult_n0').value * document.getElementById('hdnadult').value;
		document.getElementById('txtadult').innerHTML=document.getElementById('txtAdult_n0').value * document.getElementById('hdnadult').value;
	}
	if(document.getElementById('txtChild_n0')!=null)
	{
		tot+= document.getElementById('txtChild_n0').value * document.getElementById('hdnchild').value;
		document.getElementById('txtchild').innerHTML=document.getElementById('txtChild_n0').value * document.getElementById('hdnchild').value;
	}
	if(document.getElementById('txtStudent_n0')!=null)
	{
		tot+= document.getElementById('txtStudent_n0').value * document.getElementById('hdnstudent').value;
		document.getElementById('txtstudent').innerHTML=document.getElementById('txtStudent_n0').value * document.getElementById('hdnstudent').value;
	}
	if(document.getElementById('txtSenior_n0')!=null)
	{
		tot+= document.getElementById('txtSenior_n0').value * document.getElementById('hdnsenior').value;
		document.getElementById('txtsenior').innerHTML=document.getElementById('txtSenior_n0').value * document.getElementById('hdnsenior').value;
	}
	document.getElementById('txtTotal_n0').value=tot;
}
function paypal()
{
	if(document.getElementById('txtTotal_n0').value=="" || document.getElementById('txtTotal_n0').value=="0")
	{
		alert("Please Input No of Tickets");
		return false;
	}
	else
		document.frm1.submit();
}
function centerDiv(id)
{
	if(document.getElementById(id)==null)
		return false;
	var width=parseInt((document.getElementById(id).style.width.replace('px',''))/2);
	var height=parseInt((document.getElementById(id).style.height.replace('px',''))/2);

	var ScrollTop = document.body.scrollTop;
 	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var cw = parseInt(document.body.clientWidth/2);
	var left=cw-width;
	var top=height+ScrollTop;
	document.getElementById(id).style.left=left+'px';
	document.getElementById(id).style.top=top+'px';
}

function toggleCheckbox(id)
{
	if(document.getElementById(id).checked==true)
		document.getElementById(id).checked=false;
	else
		document.getElementById(id).checked=true;
}

function CalcTotals()
{
	document.getElementById('hdnurl').value=window.location.href;
	var totamt=0;
	var totamts=0;
	var tot=document.getElementById('totCats').value;
	var tamt=0.0;
	var tqty=0;
	for(i=1;i<=tot;i++)
	{
		if(document.getElementById('txtQ'+i+'_n0').value!='')
		{
			tamt=parseFloat(document.getElementById('txtP'+i).value)*parseFloat(document.getElementById('txtQ'+i+'_n0').value);
			samt=parseFloat(document.getElementById('txtTh'+i).value)*parseFloat(document.getElementById('txtQ'+i+'_n0').value);
			document.getElementById('spnT'+i).innerHTML='$ '+tamt;
			totamt+=tamt+samt;
			totamts+=samt;
			tqty+=parseInt(document.getElementById('txtQ'+i+'_n0').value);
		}
		else
		{
			document.getElementById('spnT'+i).innerHTML='$ 0';
		}
	}
	totamt=roundNumber(totamt,2);
	totamts=roundNumber(totamts,2);
	if(totamts.length<3)
		totamts='0'+totamts;
	document.getElementById('txtTotal_n0').value=totamt;
	document.getElementById('spnQty').innerHTML	= tqty;
	document.getElementById('spnTotAmt').innerHTML	= '$ '+totamt;
	document.getElementById('spnTot').innerHTML	='$ '+totamts;
	document.getElementById('txtservice').value	=totamts;

}
function roundNumber(number,decimal_points) {
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}

var x=1;
var actual=0;
function animate(div,step,delay,t)
{
	var h;
	if((document.getElementById(div).style.height=="auto" || document.getElementById(div).style.height.length==0) && actual>0)
	{
		document.getElementById(div).style.overflow='hidden';
		h=getDim(div);
		actual=h;
	}
	else if(document.getElementById(div).style.height=="auto" || document.getElementById(div).style.height.length==0)
	{
		document.getElementById(div).style.overflow='hidden';
		h=getDim(div);
		actual=h;
	}
	else
		h=parseInt(document.getElementById(div).style.height);	
	if(t==1)
	{
		x=1;
		document.getElementById(div).style.height=x+'px';
		document.getElementById(div).style.display='block';
		expand(div,h,step,delay);
	}
	else
	{
		x=actual;
		collapse(div,step,delay);
	}
}
function collapse(div,step,delay)
{
	if(x<step)
	{
		//setTimeout('togglediv("'+div+'")',10); 
		clearTimeout(t);
		document.getElementById(div).style.display='none';
		document.getElementById(div).style.height=actual+'px';
	}
	else
	{
		document.getElementById(div).style.height=x+'px';
		x-=step;
		t=setTimeout('collapse("'+div+'",'+step+','+delay+')',delay); 
	}
}
function expand(div,max,step,delay)
{
	if(x<max)
	{
		document.getElementById(div).style.height=x+'px';
		x+=step;
		t=setTimeout('expand("'+div+'",'+max+','+step+','+delay+')',delay); 
	}
}

function getDim (id) 
{ 
	//document.getElementById(id).style.height="auto";
	// match box models
	if (document.all)
		gh = document.getElementById(id).offsetHeight+10;
	else
		gh = document.getElementById(id).offsetHeight;
	return gh;
}	
