
        function bodyload(){
            var ContactID = '';
            var FaceBookVal = '';
            var ContactIDVal = '';
            if(readCookie('ContactID')!=null){
                ContactID = readCookie('ContactID'); 
                document.getElementById('ClientsBgNew').style.display = "None";
                document.getElementById('ClientsLogoutBgNew').style.display = "block"; 
            }    
            //alert(ContactID);  
            //var OPCompanyID = readCookie('OPCompanyID');
            //alert(OPCompanyID);
            var url = document.URL; //document.URL;
            //alert(url);
            var FinalURL;
            var url1 = url.split('//');
            var part = url1[1].split('/');
            var urlinLowerCase = part[0].toLowerCase();
            //alert(urlinLowerCase);
            var trimWWW = urlinLowerCase.indexOf('www');

            if (trimWWW <= 0) {
                //alert('sasasa');
                var CheckForDomine = part[0].split('.');
                if (CheckForDomine.length > 2) {
                    FinalURL = part[0];
                    //alert(FinalURL);
                }
                else {
                    FinalURL = 'www.' + part[0];
                }
            }
            else {
                FinalURL = part[0];
            }

            var url = document.URL;
            url = url + '';
            if (url.indexOf('?') > -1) {
                //alert(url);
                var values = url.split('?');
                if (values.length > 1) {                
                    if(ContactID==''){
                        if (values[1].indexOf('ContactID=') > -1) {
                            var Contactforcookie = values[1].split('ContactID=');
                            //alert(Contactforcookie);
                            if(Contactforcookie.length>1){
                                var ContactID = Contactforcookie[1].substring(0,Contactforcookie[1].indexOf('&'));
                                //alert(ContactID);
                                createCookie("ContactID",ContactID,"30");
                                changetoLogout();
                            }    
                        }
                    }
                    //alert(values[1]);
                    if (ContactID != '') {
                        if (values[1].indexOf('ContactID=') < 0) {
                            ContactIDVal = "&ContactID=" + ContactID;
                        }
                        document.getElementById('frame').src = 'http://client-connect.force.com/Scheduling?PortalUrl=' + 'www.thornfinancialgroup.com' + '&' + values[1] + '&ParentURL=' + values[0] + ContactIDVal; //+'&ContactID='+ContactID;
                    } else {
                        if (readCookie('FaceBookVal') != null) {
                            if (values[1].indexOf('FB=1') < 0) {
                                FaceBookVal = "&FB=1";
                            }
                        }
                        document.getElementById('frame').src = 'http://www.thornfinancialgroup.com/webaccountmgt/Login.aspx?PortalUrl=' + 'www.thornfinancialgroup.com' + '&' + values[1] + '&ParentURL=' + values[0] + FaceBookVal;
                    }    
                    //alert(document.getElementById('frame').src);
                }
            }
            else {
                if(ContactID!=''){
                        document.getElementById('frame').src = 'http://client-connect.force.com/Scheduling?PortalUrl=' + 'www.thornfinancialgroup.com' +'&ContactID='+ContactID+'&ParentURL='+url;
                    } else {
                    if (readCookie('FaceBookVal') != null) {
                        if (url.indexOf('FB=1') < 0) {
                            FaceBookVal = "&FB=1";
                        }
                        }
                        document.getElementById('frame').src = 'http://www.thornfinancialgroup.com/webaccountmgt/Login.aspx?PortalUrl=' + 'www.thornfinancialgroup.com' + '&ParentURL=' + url + FaceBookVal;
                }        
                //alert(document.getElementById('frame').src);
            }
            
            /*if(ContactID != null){
                document.getElementById("<%=txtEmail.clientID%>").value = userID;
            }
            if(OPCompanyID != null){
                //alert(Password);
                document.getElementById("<%=txtPwd.clientID%>").value = Password;
            }*/        
        }        
        
        function createCookie(name,value,days) {
            if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
            }
            else var expires = "";
            document.cookie = name+"="+value+expires+"; path=/";
            
            //alert(document.cookie);
            //document.cookie.
            
        }

        function readCookie(name) {
            var nameEQ = name + "=";
            //alert(document.cookie);
            var ca = document.cookie.split(';');
            //alert(document.cookie);
            //alert(ca);
            for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
            }
            return null;
        }      
        
        function CreateCookie(){                        
            //alert(document.getElementById("<%=txtEmail.clientID%>").value);
            //alert(document.getElementById("<%=txtPwd.clientID%>").value);          
            
            if(document.getElementById("rememberme").checked){                
                    //alert("hi+"+document.getElementById("<% =txtEmail.clientID%>").value);
                    createCookie("userid",document.getElementById("<%=txtEmail.clientID%>").value,"");
                    createCookie("password",document.getElementById("<%=txtPwd.clientID%>").value,"");
            }
            if(document.getElementById("<%=txtEmail.clientID%>").value==""){
                //alert(document.getElementById("<%=txtEmail.clientID%>").value);
                document.getElementById("ErrorDiv").innerHTML = "Please Enter LoginID";
                return false;
            }
            else if(document.getElementById("<%=txtPwd.clientID%>").value==""){
                //alert(document.getElementById("<%=txtPwd.clientID%>").value);
                document.getElementById("ErrorDiv").innerHTML = "Please Enter Password";
                return false;
            }
            else{
                //document.getElementById("<%=btnLogin.clientID%>").click();
                return true;
            }
        }
    function changetoLogout(){
            if(document.getElementById('ClientsLogoutBgNew')!=null)
                document.getElementById('ClientsLogoutBgNew').style.display = 'block';
            if(document.getElementById('ClientsBgNew')!=null)    
                document.getElementById('ClientsBgNew').style.display = 'none';
            
        }
