function ClientServer() { }
        ClientServer.Alerts = "http://hosting.gmodules.com/ig/gadgets/file/110150743243257692528/Versions.xml";
        ClientServer.UserURL = "http://www.sharpra.com/login/userurl.aspx";
        ClientServer.NotesURL = "http://www.sharpra.com/ServerNotes/NotesURL.aspx";
        ClientServer.NotesService = "http://www.sharpra.com/servernotes/services/notes.asmx";
          
        var onInfo = new YAHOO.util.CustomEvent("onInfo");
        ClientServer.GetInfo = function() {
            var url = ClientServer.Alerts + "?timestamp=" + new Date();
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("GET", url, true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            onInfo.fire({ Code: "1", Text: request.responseXML });
                        }
                    }
                };
                request.send(null);
            }
        }

        //SERVER NOTES COUNT
        var onServerNotesCount = new YAHOO.util.CustomEvent("onServerNotesCount");
        ClientServer.GetServerNoteCount = function(client, guid) {
            var url = ClientServer.NotesURL + "?type=count&client=" + client + "&guid=" + guid + "&timestamp=" + new Date();
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("GET", url, true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            onServerNotesCount.fire({ Code: "1", Text: request.responseText });
                            return;
                        }
                        else {
                            onServerNotesCount.fire({ Code: "-1", Text: Strings.GetServerErr() });
                            return;
                        }
                    }
                };
                request.send(null);
            }
        }
        //END SERVER NOTES COUNT

        //SERVER NOTES RECEIVED
        var onServerNotesReceived = new YAHOO.util.CustomEvent("onServerNotesReceived");
        ClientServer.GetServerVals = function(guid, client) {
            var url = ClientServer.NotesService + "?op=GetNotesToSec&timestamp=" + new Date();
            var sreq = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetNotesToSec xmlns=\"http://sharpra.com/webservices\"><guid>" + guid + "</guid><client>" + client + "</client></GetNotesToSec></soap:Body></soap:Envelope>";
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("POST", url, true);
                request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                request.setRequestHeader("Cache-Control", "no-cache");
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            onServerNotesReceived.fire({ Code: "1", Text: request.responseText });
                            return;
                        }
                        else {
                            onServerNotesReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
                            return;
                        }
                    }

                };
                request.send(sreq);
            }

        }
        //END SERVER NOTES RECEIVED

        //GET QUESTION BY EMAIL
        var onForgotPassReceived = new YAHOO.util.CustomEvent("onForgotPassReceived");
        ClientServer.GetQuestion = function(email) {
            var url = ClientServer.ServerConnect("type", "questionbyemail", "email", email, "timestamp", new Date());
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("GET", url, true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            if (request.responseText.indexOf("<op>") > -1) {
                                var msg = request.responseText.replace("<op>", "").replace("</op>", "");
                                if (msg.trim().length == 0 || msg == "-1" || msg == "-2") {
                                    onForgotPassReceived.fire({ Code: "-1", Text: Strings.GetnoEmail() });
                                    return;
                                }
                                else {
                                    onForgotPassReceived.fire({ Code: "1", Text: msg });
                                    return;
                                }
                            }
                            else {
                                onForgotPassReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
                                return;
                            }
                        }
                        else {
                            onForgotPassReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
                            return;
                        }
                    }
                };
                request.send(null);
            }
        }
        //END



        //GET PASSWORD BY EMAIL
        var onForgotPassMailed = new YAHOO.util.CustomEvent("onForgotPassMailed");
        ClientServer.GetPassword = function(email, answer) {
            var url = ClientServer.ServerConnect("type", "mailpassbyemail", "email", email, "answer", answer, "timestamp", new Date());
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("GET", url, true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            if (request.responseText.indexOf("<op>") > -1) {
                                var msg = request.responseText.replace("<op>", "").replace("</op>", "");

                                if (msg.trim().length == 0 || msg == "0" || msg == "-1" || msg == "-2") {
                                    onForgotPassMailed.fire({ Code: "1", Text: Strings.GetincAns() });
                                    return;
                                }
                                else {
                                    onForgotPassMailed.fire({ Code: "1", Text: Strings.GetemailSent() });
                                    return;
                                }
                            }
                            else {
                                onForgotPassMailed.fire({ Code: "-1", Text: Strings.GetServerErr() });
                                return;
                            }
                        }
                        else {
                            onForgotPassMailed.fire({ Code: "-1", Text: Strings.GetServerErr() });
                            return;
                        }
                    }
                };
                request.send(null);
            }

        }
        //END
        
        
        

        //LOGIN
        var onLoginReceived = new YAHOO.util.CustomEvent("onLoginReceived");
        ClientServer.Login = function(user, pass)//4
        {
            var url = ClientServer.ServerConnect("type", "login", "user", user, "pass", pass, "timestamp", new Date());
            var request = null;
            try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
                try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
            }
            if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
            if (request != null) {
                request.open("GET", url, true);
                request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                        if (request.status == 200) {
                            
                            if (request.responseText.indexOf("<op>") > -1) {
                                var msg = request.responseText.replace("<op>", "").replace("</op>", "");
                                if (msg.indexOf(" ") > -1) {
                                    onLoginReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                                    return;
                                }
                                if (msg == "-1") {
                                    onLoginReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                                    return;
                                }
                                if (msg.trim().length == 0) {
                                    onLoginReceived.fire({ Code: "-1", Text: Strings.GetincorrectLogin() });
                                    return;
                                }
                                else {
                                    onLoginReceived.fire({ Code: "1", Text: msg });
                                    return;
                                }
                            }
                            else {
                                onLoginReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
                            }
                        }
                        else {
                            onLoginReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
                        }
                    }
                };
                request.send(null);
            }
        }


var onSync = new YAHOO.util.CustomEvent("onSync");
ClientServer.CheckSync = function(guid)//8
{
    var url = ClientServer.ServerConnect("type", "lastupdatetosec", "guid", guid, "timestamp", new Date());
    var request = null;
    try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
        try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
    }
    if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
    if (request != null) {
        request.open("GET", url, true);
        request.onreadystatechange = function() {
            //request.responseText
            if (request.readyState == 4) {
                if (request.status == 200) {
                    if (request.responseText.indexOf("<op>") > -1) {
                        var msg = request.responseText.replace("<op>", "").replace("</op>", "");
                        if (msg.trim().length == 0 || msg == "-1" || msg == "-2") {
                            onSync.fire({ Code: "-1", Text: Strings.GetServerErr() });
                        }
                        else {
                            onSync.fire({ Code: "1", Text: msg })
                        }
                    }
                    else {
                        
                        onSync.fire({ Code: "-1", Text: Strings.GetServerErr() });
                    }
                }
                else {
                    onSync.fire({ Code: "-1", Text: Strings.GetServerErr() });
                    return;
                }
            }
        };
        request.send(null);
    }
}

 var onEmailNotes = new YAHOO.util.CustomEvent("onEmailNotes");
 ClientServer.EmailNotes = function(guid, email) {//10
     var url = ClientServer.ServerConnect("type", "mailnotes", "guid", guid, "otheremail", email, "timestamp", new Date());
     var request = null;
     try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
         try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
     }
     if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
     if (request != null) {
         request.open("GET", url, true);
         request.onreadystatechange = function() {
             //request.responseText
             if (request.readyState == 4) {
                 if (request.status == 200) {
                     if (request.responseText.indexOf("<op>") > -1) {
                         var msg = request.responseText.replace("<op>", "").replace("</op>", "");
                         if (!msg == "1") {
                             onEmailNotes.fire({ Code: "-1", Text: Strings.GetintServer() });
                         }
                         else {
                             onEmailNotes.fire({ Code: "1", Text: Strings.GetemailNotesSent() });
                         }
                     }
                     else {
                         onEmailNotes.fire({ Code: "-1", Text: Strings.GetServerErr() });
                     }
                 }
                 else {
                     onEmailNotes.fire({ Code: "-1", Text: Strings.GetServerErr() });
                     return;
                 }
             }
         };
         request.send(null);
     }
 }

 var onClientNotesUpdated = new YAHOO.util.CustomEvent("onClientNotesUpdated");
 ClientServer.ClientUpdateNotes = function(guid, note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, notesArray, notesPosition) {
     var url = ClientServer.NotesService + "?op=UpdateAllNotes&timestamp=" + new Date();
     var sreq = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><UpdateAllNotes xmlns=\"http://sharpra.com/webservices\"><guid>" + guid + "</guid><note1>"
                + ClientServer.EncodeString(note1) + "</note1><note2>"
                + ClientServer.EncodeString(note2) + "</note2><note3>"
                + ClientServer.EncodeString(note3) + "</note3><note4>"
                + ClientServer.EncodeString(note4) + "</note4><note5>"
                + ClientServer.EncodeString(note5) + "</note5><note6>"
                + ClientServer.EncodeString(note6) + "</note6><note7>"
                + ClientServer.EncodeString(note7) + "</note7><note8>"
                + ClientServer.EncodeString(note8) + "</note8><note9>"
                + ClientServer.EncodeString(note9) + "</note9><note10>"
                + ClientServer.EncodeString(note10) + "</note10><notecount>"
                + notesArray + "</notecount><noteCurrent>" + notesPosition + "</noteCurrent></UpdateAllNotes> </soap:Body></soap:Envelope>";
     var request = null;
     try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
         try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
     }
     if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
     if (request != null) {
         request.open("POST", url, true);
         request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
         request.setRequestHeader("Cache-Control", "no-cache");
         request.onreadystatechange = function() {
             if (request.readyState == 4) {
                 if (request.status == 200) {
                     onClientNotesUpdated.fire({ Code: "1", Text: request.responseText });
                     return;
                 }
                 else {
                     onClientNotesUpdated.fire({ Code: "-1", Text: Strings.GetServerErr() });
                     return;
                 }
             }

         };
         request.send(sreq);
     }


 }

 var onClientSelectedNotesUpdated = new YAHOO.util.CustomEvent("onClientSelectedNotesUpdated");
 ClientServer.ClientUpdateSelectedNotes = function(guid, note1, note2, note3, note4, note5, note6, note7, note8, note9, note10, notesArray, notesPosition, SelectedNotesArray) {
 var url = ClientServer.NotesService + "?op=UpdateSelectedNotes&timestamp=" + new Date();
     var sreq = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><UpdateSelectedNotes xmlns=\"http://sharpra.com/webservices\"><guid>" + guid + "</guid><note1>"
                + ClientServer.EncodeString(note1) + "</note1><note2>"
                + ClientServer.EncodeString(note2) + "</note2><note3>"
                + ClientServer.EncodeString(note3) + "</note3><note4>"
                + ClientServer.EncodeString(note4) + "</note4><note5>"
                + ClientServer.EncodeString(note5) + "</note5><note6>"
                + ClientServer.EncodeString(note6) + "</note6><note7>"
                + ClientServer.EncodeString(note7) + "</note7><note8>"
                + ClientServer.EncodeString(note8) + "</note8><note9>"
                + ClientServer.EncodeString(note9) + "</note9><note10>"
                + ClientServer.EncodeString(note10) + "</note10><notecount>" + notesArray + "</notecount><noteCurrent>" + notesPosition + "</noteCurrent><selctedNotesIndexes>" + SelectedNotesArray + "</selctedNotesIndexes></UpdateSelectedNotes> </soap:Body></soap:Envelope>";
    
     var request = null;
     try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
         try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { request = null; }
     }
     if (!request && typeof XMLHttpRequest != "undefined") { request = new XMLHttpRequest(); }
     if (request != null) {
         request.open("POST", url, true);
         request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
         request.setRequestHeader("Cache-Control", "no-cache");
         request.onreadystatechange = function() {
             if (request.readyState == 4) {
                 if (request.status == 200) {
                     onClientSelectedNotesUpdated.fire({ Code: "1", Text: request.responseText });
                     return;
                 }
                 else {
                     onClientSelectedNotesUpdated.fire({ Code: "-1", Text: Strings.GetServerErr() });
                     return;
                 }
             }

         };
         request.send(sreq);
     }


 }

 ClientServer.ServerConnect = function() {
     var url = ClientServer.UserURL;
     for (var i = 0; i < ClientServer.ServerConnect.arguments.length; i++) {
         if (i == 0) {
             url += "?";
         }
         if (i > 0 && i % 2 == 0) {
             url += "&";
         }
         if (i % 2 == 1) {
             url += "=";
         }
         url += ClientServer.ServerConnect.arguments[i];
     }
     return url;
 }

 ClientServer.EncodeString = function(srcString) {
    if (srcString == null) {
         return "";
     }
     return srcString.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\\/g, "&quot;").replace(/\'/g, "&apos;");
 }



 //REGISTER
 ClientServer.RegisterReq = null;
 ClientServer.InitRegister = function() {
    try { 
        ClientServer.RegisterReq = new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    catch (e) {
        try { 
            ClientServer.RegisterReq = new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        catch (oc) { 
            ClientServer.RegisterReq = null; 
         }
    }
    if (!ClientServer.RegisterReq && typeof XMLHttpClientServer.RegisterReq != "undefined") { 
        ClientServer.RegisterReq = new XMLHttpClientServer.RegisterReq(); 
    }
 }
 
 var onRegisterReceived = new YAHOO.util.CustomEvent("onRegisterReceived");

 ClientServer.Register = function(user, password, confpass, email, question, answer)//5
 {
     ClientServer.InitRegister();
     var url = ClientServer.ServerConnect("type", "user", "user", user, "timestamp", new Date());
     ClientServer.InitRegister();

     if (ClientServer.RegisterReq != null) {
         ClientServer.RegisterReq.open("GET", url, true);
         ClientServer.RegisterReq.onreadystatechange = function() { ClientServer.ValidateUserExists(user, password, confpass, email, question, answer); };
         ClientServer.RegisterReq.send(null);
     }
 }



 ClientServer.ValidateUserExists = function(user, pass, confPass, email, question, answer) {
     if (ClientServer.RegisterReq.readyState == 4) {
         if (ClientServer.RegisterReq.status == 200) {
             if (ClientServer.RegisterReq.responseText.indexOf("<op>") > -1) {
                 var msg = ClientServer.RegisterReq.responseText.replace("<op>", "").replace("</op>", "").trim();
                 if (msg.indexOf(" ") > -1) {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                     return;
                 }
                 if (msg != "0") {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetuserExists() });
                     return;
                 }
                 else {
                     var url = ClientServer.ServerConnect("type", "email", "email", email, "timestamp", new Date());
                     ClientServer.InitRegister();
                     if (ClientServer.RegisterReq != null) {
                         ClientServer.RegisterReq.open("GET", url, true);
                         ClientServer.RegisterReq.onreadystatechange = function() { ClientServer.ValidateEmailExists(user, pass, confPass, email, question, answer); };
                         ClientServer.RegisterReq.send(null);
                     }
                 }
             }
             else {
                 onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
             }
         }
         else {
             onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
         }
     }
 }



 ClientServer.ValidateEmailExists = function(user, pass, confPass, email, question, answer) {
     if (ClientServer.RegisterReq.readyState == 4) {
         if (ClientServer.RegisterReq.status == 200) {
             if (ClientServer.RegisterReq.responseText.indexOf("<op>") > -1) {
                 var msg = ClientServer.RegisterReq.responseText.replace("<op>", "").replace("</op>", "").trim();
                 if (msg.indexOf(" ") > -1) {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                     return;
                 }
                 if (msg != "0") {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetemailExists() });
                     return;
                 }
                 else {
                     var url = ClientServer.ServerConnect("type", "register", "user", user, "email", email, "question", question, "password", pass, "answer", answer, "timestamp", new Date());
                     ClientServer.InitRegister();
                     if (ClientServer.RegisterReq != null) {
                         ClientServer.RegisterReq.open("GET", url, true);
                         ClientServer.RegisterReq.onreadystatechange = function() { ClientServer.ValidateUser(user, pass, confPass, email, question, answer); };
                         ClientServer.RegisterReq.send(null);
                     }
                 }
             }
             else {
                 onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
             }
         }
         else {
             onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
         }
     }
 }

 ClientServer.ValidateUser = function(user, pass, confPass, email, question, answer) {
     if (ClientServer.RegisterReq.readyState == 4) {
         if (ClientServer.RegisterReq.status == 200) {
             if (ClientServer.RegisterReq.responseText.indexOf("<op>") > -1) {
                 var msg = ClientServer.RegisterReq.responseText.replace("<op>", "").replace("</op>", "").trim();
                 if (msg.indexOf(" ") > -1) {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                     return;
                 }
                 if (msg == "0") {
                     onRegisterReceived.fire({ Code: "-1", Text: Strings.GetintServer() });
                     return;
                 }
                 else {
                     onRegisterReceived.fire({ Code: "1", Text: msg });
                     return;
                 }
             }
             else {
                 onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
             }
         }
         else {
             onRegisterReceived.fire({ Code: "-1", Text: Strings.GetServerErr() });
         }
     }
 }



