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(){
	//addInputSubmitEvent(document.cse-search-box, document.getElementById('q'));
	//addInputSubmitEvent(document.cse-search-box, document.getElementByname('optSearch'));
//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')
        {
			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')
            {
                if(input.value=='0' || input.value=='0.00')
                    input.value='';
                input.style.textAlign='right';
                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)=='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++) 
 {
        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 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[0].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!='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].value='';
			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 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].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=='/')
	{
		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()
{
	if(document.getElementById('txtUserName_b0').value=='')
	{
		alert('Please enter User Name');
		return false;
	}
	else if(document.getElementById('txtPassword_b0').value=='')
	{
		alert('Please enter Password');
		return false;
	}
	ValidateLogin('login,'+document.getElementById('txtUserName_b0').value+','+document.getElementById('txtPassword_b0').value);	
}
function ChangeCity(cid,mid)
{
	window.location='validatelogin.php?pname=view'+'&mid='+mid+'&cid='+cid;
}
function ImageValidation(div,text,msg)
{
   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.getElementById('optBheru').checked==true)
		HandleSubmit('bsearch.php',10,2);
	else
		HandleSubmit('gsearch.php',0,1);

}
function Search1()
{
	if(document.getElementById('optBheru').checked==true)
		HandleSubmit('/bsearch.php',10,2);
	else
		HandleSubmit('/gsearch.php',0,1);

}

function NewsLetter()
{
	if(document.getElementById('txtnewsletter_e0').value=='')
	{
		alert('Please enter Email ID');
		return;
	}
	if(document.getElementById('ddlnewscity').selectedIndex==0)
	{
		alert('Please select a city');
		return;
	}
	GetData('NewsLetter,'+document.getElementById('txtnewsletter_e0').value+','+document.getElementById('ddlnewscity').value,'divnewsmsg');
	document.getElementById('txtnewsletter_e0').value='';
	document.getElementById('ddlnewscity').selectedIndex=0;
}

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;
        }
}
