﻿
var thisUA;
				
				function getQueryString(variable) 
				{
					var query = window.location.search.substring(1);
				
					if (query.indexOf("&") != -1)
					{
						var vars = query.split("&");
						for (var i=0;i<vars.length;i++) 
						{
							var pair = vars[i].split("=");
								if (pair[0] == variable) 
								{
								return pair[1];
								}
							 
						}
					}
					else
					{
						var pair = query.split("=");
								if (pair[0] == variable) 
								{
								return pair[1];
								}
							
					}
				}
				function chkError(response)
                {
	                if (response.error != null){
                	
	                    alert(response.error.Message);
	                    return;
	                }
                }
				function showVer()
				{
				/* secure stuff disable for now too many IE errors
					var sPage = window.location.href
				    //first make sure not local
				    if( sPage.indexOf("localhost") == -1 ){
				        //check if no https
					    if( sPage.indexOf("https") == -1 ){
					     //check if www
					        if( sPage.indexOf("www") == -1 ){
                            //alert("https://secure." + sPage.substr(7))
                            document.location.href="https://secure." + sPage.substr(7);
                            }
                            else
                            {
                           
                            document.location.href="https://secure." + sPage.substr(11);
                            }   
                        }
                    }
                    */
					if(getQueryString("type") == "demo")
					{
						Bizzvo.AjaxMod.loginUser(
						"DemoUser", 
						"bizzvo", 
						false, 
						ValLogin_CallBack
						);
					}
					
					thisUA = navigator.userAgent;
					
				}
				function emailActivation(cid, email)
				{
				    Bizzvo.AjaxMod.resendEmailActivation(cid, email, emailActivation_callback);
				}
				function emailActivation_callback(res)
				{
				    chkError(res);
				   document.getElementById("divRes").innerHTML = "Activation has been emailed to you";
				}
				
				function activateAccount(code)
				{
				    document.getElementById("divRes2").innerHTML = "Please wait activating your account <img src='images/wait1.gif' />";
				    Bizzvo.AjaxMod.activate(code, activateAccount_callback);
				}
				function activateAccount_callback(res)
				{
				    chkError(res);
				    if(res.value == "Done")
				    {
				       document.getElementById("divRes2").innerHTML = "<h4><img src='images/check.gif' />Activation Successful!</h4><p>You can now login using the username and password you set up.</p>" 
				    }
				    else
				    {
				       document.getElementById("divRes2").innerHTML = res.value;
				    }
				}
				function login(user,pass) {
				Bizzvo.AjaxMod.loginUser(
					user, 
					pass, 
					true, 
					ValLogin_CallBack
					);
			
				}
				function ValLogin() {
				var saveMe = true;
				
				if (document.getElementById("saveUsr"))
				{ saveMe = document.getElementById("saveUsr").checked}
				Bizzvo.AjaxMod.loginUser(
					document.getElementById("usrName").value, 
					document.getElementById("usrPwd").value, 
					saveMe, 
					ValLogin_CallBack
					);
				}
				function ValLogin2() {
				var saveMe = true;
				
				if (document.getElementById("saveUsr"))
				{ saveMe = document.getElementById("saveUsr").checked}
				Bizzvo.AjaxMod.loginUser(
					document.getElementById("usrName2").value, 
					document.getElementById("usrPwd2").value, 
					saveMe, 
					ValLogin_CallBack
					);
				}
				function ValLogin_CallBack(response){
					if (response.error != null){
					alert(response.error.Message);
					return;
					}
					
					if (response.value == "DoneUser") 
					{
						if (thisUA.indexOf("PPC") != -1)
						{
							//found pocket pc redirect to PPC Menu
							document.location = "/BizzvoCM/modules/mobile/"
							
						}
						else
						{
						    
							if(getQueryString("ReturnUrl") != "" && getQueryString("ReturnUrl") != null && getQueryString("ReturnUrl") != "undefined")
							{
							    var goUrl =  getQueryString("ReturnUrl");
							    goUrl = goUrl.replace(/%2f/gi, "/");
							    document.location = goUrl;
							}
							else
							{
							document.location = "/BizzvoCM/";
							}
						}
						return;
					}
					if (response.value.substr(0,9) == "NotActive")
					{
					    var tmpSp = response.value.split("_");
					    
					    if(confirm("This account has not yet been activated. An email was sent to the address specified, please check your email for the activation link. To have your activation mailed to you again click OK, or to ignore click cancel."))
					    {   
					        emailActivation(tmpSp[1], tmpSp[2]);
					    }
					        
					return;
					}
					
						
						alert(response.value);
					
					 
			 
				}
				function notify()
				{
					if(document.getElementById("txtEmail").value != "")
					{
					Bizzvo.AjaxMod.notify(document.getElementById("txtEmail").value, notify_callback);
					document.getElementById("txtEmail").value = "";
					}
				}
				function notify_callback(res)
				{
					
						//document.getElementById("divRes").style.display = "block";
						alert(res.value);
							
				}
				
				function onEnter( evt, frm ) { 
					var keyCode = null; 


					if( evt.which ) { 
					keyCode = evt.which; 
					} else if( evt.keyCode ) { 
					keyCode = evt.keyCode; 
					} 
					if( 13 == keyCode ) { 
					
					ValLogin(); 
					return false; 
					} 
					return true; 
				} 
				function onEnter2( evt, frm ) { 
					var keyCode = null; 


					if( evt.which ) { 
					keyCode = evt.which; 
					} else if( evt.keyCode ) { 
					keyCode = evt.keyCode; 
					} 
					if( 13 == keyCode ) { 
					
					ValLogin2(); 
					return false; 
					} 
					return true; 
				} 
