
var d=document;

function trim(val) 
{
    a = val.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
}

var ErrorMsg=function(title,msg,icn)
{
         Ext.MessageBox.show({
            title: title,
            msg: msg,
            buttons: Ext.MessageBox.OK,
            icon: icn=='ERROR'?Ext.MessageBox.ERROR:Ext.MessageBox.WARNING
         });
}
var ShowError=function(msg)
{
         Ext.MessageBox.show({
            title: 'Error...',
            msg: msg,
            buttons: Ext.MessageBox.OK,
            icon: Ext.MessageBox.WARNING
         });
}
var MsgBox=function(title,msg)
{
         Ext.MessageBox.show({
            title: title,
            msg: msg,
            buttons: Ext.MessageBox.OK
         });
}
 function OpenNewWindow(pagename, windowname)
 {
 
   if (pagename.indexOf('Disclaimer.aspx') || pagename.indexOf('ViewServiceProvider.aspx'))
   {
        window.open(pagename, windowname, "menubar=no,toolbar=no,location=no,scrollbars=yes,left=50,top=100,width=950,height=550"); 
   }
   else
   {
        window.open(pagename, windowname, "menubar=no,toolbar=no,location=no,scrollbars=no,left=100,top=100,width=950,height=350"); 
   }
 }
 function openWindow(page)
{
    window.open (page,"PasswordRule","location=0,status=0,scrollbars=0,width=400,height=280,resizable=0"); 
    return false;
}

function openVideo(PAGE)
{
	makePopup(PAGE);
}

function makePopup(PAGE)
{
	window.open (PAGE, "Video",	"location=0,resizable=0,directories=0,status=0,scrollbars=0,toolbar=0,width=640,height=500");
	
//	
//	 var winInstruction = new Ext.Window({
//        autoLoad    : PAGE,
//		layout      :'fit',
//		title       :'Video',
//        width       : 620,
//        height      : 510,
//        bodyStyle   :"margin-top:-20px",
//        resizable   :false   
//    });
//    winInstruction.show();
}

 function Disclaimer(siteurl)
{
    if(siteurl.indexOf('HTTPS://')<0 && siteurl.indexOf('https://')<0 && siteurl.indexOf('HTTP://')<0 && siteurl.indexOf('http://')<0)
    {
        siteurl='http://'+siteurl;
    }
    
    var msgmatter='This information is provided as a public service. The Texas Health and Human Services Commission, and the State of Texas do not endorse any commercial enterprises which may be listed <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do you want to continue...';
    url=siteurl;
       Ext.MessageBox.show({
           title:'Disclaimer',
           msg: msgmatter,
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){	if(btn=='yes'){	window.open (url,'Texas');}	},
           icon: Ext.MessageBox.WARNING
       });
       return false;
}

 function DisclaimerServiceProvider(siteurl)
{
    if(siteurl.indexOf('HTTPS://')<0 && siteurl.indexOf('https://')<0 && siteurl.indexOf('HTTP://')<0 && siteurl.indexOf('http://')<0)
    {
        siteurl='http://'+siteurl;
    }
    
    var msgmatter='HHSC provides information on Twogether service providers as a public service for informational purposes only. HHSC does not endorse any of the products, vendors or consultants referenced. All of the information provided is believed to be accurate and reliable; however,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HHSC assumes no responsibility for any errors appearing in rules or otherwise. Please contact <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the Regional Intermediary or service provider directly for additional information regarding <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; upcoming marriage education classes. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do you want to continue...';
    url=siteurl;
       Ext.MessageBox.show({
           title:'Disclaimer',
           msg: msgmatter,
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){	if(btn=='yes'){	window.open (url,'Texas');}	},
           icon: Ext.MessageBox.WARNING
       });
       return false;
}


function EncryptMail(params)
{
    var encryptedemail_id29='' //variable to contain encrypted email 
    for (var i=0; i<params.length; i++)
    encryptedemail_id29+=String.fromCharCode(params[i])
    return encryptedemail_id29;
}

function SetRegionShow()
{
   
//  http://www.dynamicdrive.com/emailriddler/
   
    var emailriddlerarray,stremail;
//   emailriddlerarray=[115,117,122,97,110,110,101,64,97,98,105,108,101,110,101,99,111,117,110,115,101,108,105,110,103,46,99,111,109];
//   d.getElementById('lnkregion2').href='mailto:' + EncryptMail(emailriddlerarray) + ';';
//   emailriddlerarray=[115,97,114,97,104,46,97,114,110,111,108,100,64,97,110,116,104,101,109,110,111,114,116,104,116,101,120,97,115,46,111,114,103];
//   d.getElementById('lnkregion3E').href='mailto:' + EncryptMail(emailriddlerarray) + ';';
//   
//   emailriddlerarray=[103,105,108,101,115,64,102,97,109,105,108,121,115,101,114,118,105,99,101,115,115,101,116,120,46,111,114,103];
//   d.getElementById('lnkregion5').href='mailto:' + EncryptMail(emailriddlerarray) + ';';
//   
//   emailriddlerarray=[100,98,108,101,103,101,110,64,102,97,109,105,108,121,45,115,101,114,118,105,99,101,46,111,114,103];
//   d.getElementById('lnkregion8').href='mailto:' + EncryptMail(emailriddlerarray) + ';';
   emailriddlerarray=[112,114,101,115,116,111,110,64,97,109,103,114,97,110,116,46,99,111,109];
   d.getElementById('lnkregion9').href='mailto:' + EncryptMail(emailriddlerarray) ;
//   emailriddlerarray=[114,111,103,101,114,116,104,97,116,64,97,111,108,46,99,111,109];
//   d.getElementById('lnkregion10').href='mailto:' + EncryptMail(emailriddlerarray) + ';';
//   
   emailriddlerarray=[106,109,97,99,105,110,110,105,115,64,108,101,103,97,99,121,97,116,119,111,114,107,46,99,111,109];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk1').href='mailto:' + stremail;
   d.getElementById('lnk1').title=stremail;
   d.getElementById('lbllnk1').innerHTML=stremail;
   
   emailriddlerarray=[115,117,122,97,110,110,101,64,97,98,105,108,101,110,101,99,111,117,110,115,101,108,105,110,103,46,99,111,109];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk2').href='mailto:' + stremail;
   d.getElementById('lnk2').title=stremail;
   d.getElementById('lbllnk2').innerHTML=stremail;
   
   
   emailriddlerarray=[115,97,114,97,104,46,97,114,110,111,108,100,64,97,110,116,104,101,109,110,111,114,116,104,116,101,120,97,115,46,111,114,103];   
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk3').href='mailto:' + stremail;
   d.getElementById('lnk3').title=stremail;
   d.getElementById('lbllnk3').innerHTML=stremail;
   
   emailriddlerarray=[106,97,99,107,101,114,64,116,104,101,112,97,114,101,110,116,105,110,103,99,101,110,116,101,114,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk4').href='mailto:' + stremail;
   d.getElementById('lnk4').title=stremail;
   d.getElementById('lbllnk4').innerHTML=stremail;
   
   emailriddlerarray=[74,97,115,111,110,46,71,114,101,101,110,101,64,119,101,108,108,110,101,115,115,112,111,105,110,116,101,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk5').href='mailto:' + stremail;
   d.getElementById('lnk5').title=stremail;
   d.getElementById('lbllnk5').innerHTML=stremail;
   
   emailriddlerarray=[103,105,108,101,115,64,87,101,83,116,114,101,110,103,116,104,101,110,70,97,109,105,108,105,101,115,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk6').href='mailto:' + stremail;
   d.getElementById('lnk6').title=stremail;
   d.getElementById('lbllnk6').innerHTML=stremail;
   
   emailriddlerarray=[109,114,117,115,115,101,108,108,64,102,97,109,105,108,121,115,101,114,118,105,99,101,115,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk7').href='mailto:' + stremail;
   d.getElementById('lnk7').title=stremail;
   d.getElementById('lbllnk7').innerHTML=stremail;
   
   emailriddlerarray=[108,97,108,101,120,97,110,100,101,114,64,108,101,103,97,99,121,97,116,119,111,114,107,46,99,111,109];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk8').href='mailto:' + stremail;
   d.getElementById('lnk8').title=stremail;
   d.getElementById('lbllnk8').innerHTML=stremail;
   
   emailriddlerarray=[106,99,97,109,97,99,104,111,64,102,97,109,105,108,121,45,115,101,114,118,105,99,101,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk9').href='mailto:' + stremail;
   d.getElementById('lnk9').title=stremail;
   d.getElementById('lbllnk9').innerHTML=stremail;
   
   emailriddlerarray=[112,114,101,115,116,111,110,64,97,109,103,114,97,110,116,46,99,111,109];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk10').href='mailto:' + stremail;
   d.getElementById('lnk10').title=stremail;
   d.getElementById('lbllnk10').innerHTML=stremail;
   
   emailriddlerarray=[114,111,103,101,114,116,104,97,116,64,97,111,108,46,99,111,109];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk11').href='mailto:' + stremail;
   d.getElementById('lnk11').title=stremail;
   d.getElementById('lbllnk11').innerHTML=stremail;
   
   emailriddlerarray=[115,98,97,114,110,101,116,116,64,110,99,99,97,97,116,120,46,111,114,103];
   stremail=EncryptMail(emailriddlerarray);
   d.getElementById('lnk12').href='mailto:' + stremail;
   d.getElementById('lnk12').title=stremail;
   d.getElementById('lbllnk12').innerHTML=stremail;
   
}

function CheckDate(input)
{
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	var returnval=false;
	if (!validformat.test(input.value))
		return false;// alert("Invalid Date Format. Please correct and submit again.")
	else
	{ //Detailed check for valid date ranges
		var monthfield=input.value.split("/")[0]
		var dayfield=input.value.split("/")[1]
		var yearfield=input.value.split("/")[2]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)
	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			return false;// alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
	else
		return true;
	}
	if (returnval==false) input.select()
		return returnval
}
function CompareDates(date1,date2)
{
   var mon1   = parseInt(date1.substring(0,2),10);
   var dt1  = parseInt(date1.substring(3,5),10);
   var yr1   = parseInt(date1.substring(6,10),10);
   var mon2   = parseInt(date2.substring(0,2),10);
   var dt2  = parseInt(date2.substring(3,5),10);
   var yr2   = parseInt(date2.substring(6,10),10); 
   var d1 = new Date(yr1, mon1, dt1);
   var d2 = new Date(yr2, mon2, dt2);

   if(d1 > d2)
   {     
      return 1;
   }
   if(d1 < d2)
   {     
      return -1;
   }
   else
   {
     return 0;
   }
} 
function IsEmailValid(email)
{	
   // var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    var pattern = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
    if(pattern.test(email)){         
		return true;
    }else{   
		return false;
    }
}
function IsUrlValid(url)
{	
   //var pattern = /(((https?)|(ftp) |(www)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
   var pattern = /(([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
    if(pattern.test(url))
    {         
		return true;
    }
    else
    {   
		return false;
    }
}

function MoveItems(Direction, All,ListType)
        {
            var LstLeft;
            var LstRight;
            var LstLeft1;
            var LstRight1;
            var hiddenobject;
            var Removed = '';
            var i;
            var objhiddenorgtype;
            var objtextboxother;
            var hdnother;
            var objhdnother,hdnfld='',hdnfldarr;
            var dv1=null,dv2=null,flagre;
            var role,accessresource,accessresourceArr;
            
            if(ListType=='ByRole')
            {
                LstLeft1="together_togetherContent_lstSecurityProcess";
                LstRight1="together_togetherContent_lstAccessSecurityProcess";    
                hiddenobject="together_togetherContent_TxtSelectedSecurityProcess";
                objtextboxother=null;
                hdnother=null;
                hdnfld=document.getElementById('together_togetherContent_HdnREvolation').value;
                role=document.getElementById('together_togetherContent_hdnRole').value;
                accessresource=document.getElementById('together_togetherContent_hdnAccessResources').value;
                
                if(hdnfld!='')
                    hdnfldarr=hdnfld.split(",");

                if(accessresource!='')
                     accessresourceArr=accessresource.split(",");
                
            }
            else if(ListType=='ByUser')
            {
                LstLeft1="together_togetherContent_lstRoles";
                LstRight1="together_togetherContent_lstAccessRoles";    
                hiddenobject="together_togetherContent_txtSelectedRoles";
                objtextboxother=null;
                hdnother=null;
                hdnfld=document.getElementById('together_togetherContent_HdnREvolation').value;
                role=document.getElementById('together_togetherContent_hdnRole').value;
                accessresource=document.getElementById('together_togetherContent_hdnAccessResources').value;
              
                if(hdnfld!='')
                    hdnfldarr=hdnfld.split(",");
                
                if(accessresource!='')
                     accessresourceArr=accessresource.split(",");
               
            }
            if(ListType=='OrgType')
            {
                LstLeft1="together_togetherContent_listboxOrgType";
                LstRight1="together_togetherContent_listboxOrgTypeSelect";    
                hiddenobject="together_togetherContent_TxtOrgTypeSelect";
                objtextboxother="together_togetherContent_TxtOrgTypeOther";
                hdnother="together_togetherContent_HdnOrgTypeOther";
                dv1=document.getElementById('dv1');
				dv2=document.getElementById('dv2');
            }
            else if(ListType=='CurriculumType')
            {
                LstLeft1="together_togetherContent_Curriculum_LstCurriculumType";
                LstRight1="together_togetherContent_Curriculum_LstCurriculumTypeSelected";    
                hiddenobject="together_togetherContent_TxtCurriculumTypeSelected";
                objtextboxother="together_togetherContent_TxtCurriculumTypeOther";
                hdnother="together_togetherContent_HdnCurriculumTypeOther";
                dv1=document.getElementById('dv3');
				dv2=document.getElementById('dv4');
                
            }
            else if(ListType=='LocationServed')
            {
                LstLeft1="together_togetherContent_Curriculum_LBLocationServed";
                LstRight1="together_togetherContent_Curriculum_LBLocationServedSelected";    
                hiddenobject="together_togetherContent_TxtLocationServedSelected";
                objtextboxother="together_togetherContent_TxtLocationServedOther";
                hdnother="together_togetherContent_HdnLocationServedOther";
                dv1=document.getElementById('dv5');
				dv2=document.getElementById('dv6');
            }
            if (Direction == 'R')
            {
                var LstRight = document.getElementById(LstRight1);                
                var LstLeft = document.getElementById(LstLeft1);
                var temp1= document.getElementById(LstLeft1);
            }
            else
            {
                var LstLeft = document.getElementById(LstRight1);
                var LstRight = document.getElementById(LstLeft1);              
                var temp1= document.getElementById(LstLeft1);
            }   
            
            objhiddenorgtype=document.getElementById(hiddenobject);
            
            for (i=0; i<LstLeft.length; i++)
            {
                if (LstLeft.options[i].selected || All == 1) 
                {
                    if(ItemExists(LstRight, LstLeft.options[i].value) == 0)
                    {
                      if(hdnfld!='')
                      {  
                       if(ListType=='ByRole' || ListType=='ByUser')
                       {
                        //only access for Research and Evaluation   
                         if(hdnfldarr.length>0)
                         {
                            flagre=Exists(hdnfldarr,LstLeft.options[i].value);   
                            if(flagre==false)
                            {
                                alert('Selected process can not be given to this user type!');
                                return false;
                            }    
                         }  
                       }
                      } 
                      
                      if(accessresource!='')
                      {  
                       if(ListType=='ByRole' || ListType=='ByUser')
                       {                       
                         //only access for RI
                         if(accessresourceArr.length>0 && role !='4' && role !='8' && role !='1' && role !='2' && role !='3' )
                         {
                            var flag=Exists(accessresourceArr,LstLeft.options[i].value);   
                            if(flag)
                            {
                                alert('Selected process can not be given to this user type!');
                                return false;
                            }    
                         }  
                         
                       }
                      }
                      LstRight[LstRight.length] = new Option(LstLeft.options[i].text, LstLeft.options[i].value, true);
                      Removed = Removed + LstLeft.options[i].value + ',';
                    }
                 }   
            }
            
            RemoveFromList(LstLeft, Removed);
            
            var hght;
            if(dv1!=null)
            {
				hght=dv1.style.height;
				hght=parseInt(hght.substring(0,3));
				if(((parseInt(LstRight.length)+1)*17)>hght)	
					hght=(parseInt(LstRight.length)+1)*17;

				var flag=1;
				for (i=0; i<LstRight.length; i++)
				{
					if(LstRight.options[i].text.length>=35)
					{
						flag=0;
						hght-=17;
						break;
					}
				}
				if(flag==1)
					LstRight.style.width='234px';
				else
					LstRight.style.width=null;	
				
				LstRight.style.height=hght+'px';
				
				flag=1;
				
				hght=dv2.style.height;
				hght=parseInt(hght.substring(0,3));
				if(((parseInt(LstLeft.length)+1)*17)>hght)	
					hght=(parseInt(LstLeft.length)+1)*17;

				for (i=0; i<LstLeft.length; i++)
				{
					if(LstLeft.options[i].text.length>=35)
					{
						flag=0;
						hght-=17;
						break;
					}
				}
				if(flag==1)
					LstLeft.style.width='234px';
				else
					LstLeft.style.width=null;	

				LstLeft.style.height=hght+'px';	
			}              
			
            if(hdnother!=null)
                objhdnother=document.getElementById(hdnother).value;
                
            var LstRight = document.getElementById(LstRight1);
            var isotherexists=false;
            objhiddenorgtype.value='';
            for (i=0; i<LstRight.length; i++)
            {
                if(i==0)
                    objhiddenorgtype.value=LstRight.options[i].value;
                else
                    objhiddenorgtype.value+=','+LstRight.options[i].value;
                
                if(hdnother!=null)
                {
                    if(LstRight.options[i].text.toUpperCase()==objhdnother.toUpperCase())
                        isotherexists=true;
                }
            }
            if(objtextboxother!=null)
            {
                obj=document.getElementById(objtextboxother);
                if(isotherexists==true)
                {
                    obj.disabled=false;
                    if(ListType=='OrgType')
                        listboxOrgType=true;
                    else if(ListType=='CurriculumType')
                        LstCurriculumTypeSelected=true;
                    else if(ListType=='LocationServed')
                        LBLocationServedSelected=true;
                    
                }
                else
                {
                    obj.value='';
                    obj.disabled=true;
                    
                    if(ListType=='OrgType')
                        listboxOrgType=false;
                    else if(ListType=='CurriculumType')
                        LstCurriculumTypeSelected=false;
                    else if(ListType=='LocationServed')
                        LBLocationServedSelected=false;                    
               }
            }
            return false;            
        }
    
        
        var Exists = function(arr,value) 
        {
            var i;
            for (var i = 0, loopCnt = arr.length; i < loopCnt; i++) 
            {
                if (arr[i] == value) 
                {
                    return true;
                    break;
                }
            }
            return false;
       };

      function RemoveFromList (Lst, Items)
      {
            var Removed = Items.split(',');
            var j;
            var x;
            for (j=0; j<Removed.length; j++)
            {
                for (x=0; x<Lst.length; x++)
                {
                    if (Lst.options[x] != null && Lst.options[x].value == Removed[j])
                    {
                        Lst.options[x] = null;
                    }
                }
            }
        }
        
        function ItemExists(Lst, value)
        {
            var Flag = 0;
            var i = 0;
            for (i=0; i<Lst.length; i++)
            {
                if (Lst.options[i].value == value)
                {
                    Flag = 1;
                    break;
                }
            }
            return Flag;
        }
function getSession(data)
{
	var str='';
	Ext.Ajax.request({
	url: '../Handlers/twogetherhit.ashx',
	params: {data:data},
	success: function(xhr, options){    
	try{
			str=xhr.responseText;			
		}catch(e){
			//ErrorMsg('Error Info.....',e,'ERROR');
		}								  
	},
	failure:  function(){  
		//ErrorMsg('Twogether','Server communication failure','ERROR');     							   
	},
	scope: this
	});  
	
	return str;
}

function changeFontSize(size) 
{ 
     document.getElementsByTagName('body')[0].style.fontSize = size; 
}

function XMLDomObject(response)
{
        try
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(response);
        }
        catch(e)
        {
        try
        {
            var parser=new DOMParser();
            var xmlDoc=parser.parseFromString(response,"text/xml");
        }
        catch(e){}
        }
        finally
        {
                return xmlDoc;
        }
}


