var msg;	
var isChange=true;
var testomonialText=[];
testomonialText[0]="I've been very impressed by the support provided by Monitis. They are open to our suggested feature enhancements and have delivered many of them in a timely manor. We depend on this service to verify SLA for our clients and this is by far one of the best monitoring services out there. Keep up the great work!<br><br><i >Rick Stivers  </i>Schoolwires Inc.";
testomonialText[1]="Keeping track of the status of your servers can be a something which keeps you up worrying at night. However with the great solution Monitis provides us, we know that our servers are running fine. We have used other services in the past which were also working nice, however when you do the math you know Monitis is providing the best service for the money. Great reporting features & alert features. I highly recommend them<br><br><i > Marco Beijen</i>  Beijen Web Hosting";
testomonialText[2]=" Love the Monitis service and love the way you keep improving it. Monitis allows us to ensure that every aspect of the G.ho.st Virtual Computer is always live and always responding quickly all via a really powerful and easy-to-use dashboard and at a very attractive price. Keep up the great work! <br><br><i '> Zvi Schreiber</i>  G.ho.st Inc";
testomonialText[3]="We have been using Monitis now for 6 months. It has many useful functions and is continually further developed. The support is great for new customers- ongoing inquiries are also worked upon quickly, which is why we continue to use this service.<br><br><i > Sarah Bollman</i>  Trade Haven GmbH ";
testomonialText[4]="Monitis offers a unique and easy to use monitoring system. Extra value is added by Monitis support team, and we get quick response to questions and reports. The unique interface is easy to use and informative at the same time making setting up monitoring in a browser anywhere a breeze.<br><br><i >Egil Rausner </i> DCMedia Hosting ";
testomonialText[5]="This service is great for the price! With the good customer service and increasing number of features offered every month, I've been recommending Monitis to everyone who asks how I monitor all the sites I maintain. I wish all vendors would be as good to work with as Monitis.<br><br><i > Ann Copeland </i> Southern Porch ";
fillValues={"email":"email", "password":"password"};
function fillInput(obj){
	if(obj.value==""){
		obj.value=fillValues[obj.name];
	}
	
}
function fillTestomonial(){
	var index=Math.round(5 * Math.random());
	document.getElementById("citation").innerHTML=testomonialText[index];
}
function clearInput(obj){
	if(obj.value==fillValues[obj.name]){
		obj.value="";
	}
}

function stopChangeInputs(obj){
	if(isChange){
		if(obj.name=='email'){
			$id('password').value='';
		}
		else{
			$id('email').value='';
		}
		isChange=false;
	}
	
}

function start(){
	var dialogConteiner = document.createElement('div');
	dialogConteiner.id = 'dialogContainer';
	dialogConteiner.className="flora";
	msg = $id("signInMsg");
	$id("login_signup").innerHTML = '<table><tr>'+
	                                         	'<td><a href="http://monitis.com/login.jsp"><div class=login  style="margin-left:0px"></div></a></td>'+ 
											 	'<td><a href="https://www.monitis.com/free_signup.jsp"><div class=signup  style="margin-left:0px"></div></a></td>'+ 
											 '</tr></table>';
	
	
}

function login(){
	var email = $id("email").value;
	var password = encode($id("password").value);
	if (email !="" && password != "") {
		var data = "type=signIn&email="+email+"&password="+password+"&timezone="+(-new Date().getTimezoneOffset());
		Request.sendPOST(Framework.userURL+'?nocache='+Math.random(), data, signResponse);
		msg.innerHTML = "Verifying...";
	}
	else{
		msg.innerHTML = "Input your email and password";
	}
	return false;
}


function signResponse(response){
	try{
		var resp=eval("("+response.responseText+")");
		var key = resp.status;
		if(key == STATUS_OK){
			showMainPage();
		}else if(key == "waiting4Start"){
			msg.innerHTML = "Please,confirm Your PayPal subscription";
		}
		else if(key == "confirm"){
			msg.innerHTML = "Confirm your account and try again.";
		}else if( key == "mismatch" || key == "error"){
			msg.innerHTML = Framework.Lang.signinNoMatch;
		}else if( key == "redirect"){
			msg.innerHTML = Framework.Lang.signinNoMatch;
			//window.location.href = resp.data;
		}else{
			msg.innerHTML = key;
		}
	}catch(ex){
		console.log(ex);
	}
}

function showMainPage(){
	$id("main-page-loading").style.display = "block";
	$id("homePageContainer").style.display = "none";
	$id("jqB1").style.display = "none";
	$id("jqB2").style.display = "none";
	

	Controller.init();
}

function showSignUp(){
				Request.sendPOST(Framework.userURL, "type=signUp", signupResponse);
	/*var signUpDiv = document.createElement('div');
	signUpDiv.id = "signUpDivId";
	signUpDiv.className = "flora";
	signUpDiv.innerHTML= '<div style="margin-bottom:10px;">To register for an account, please fill out the form below. You will receive a registration email within a few minutes with details about activating your account</div>' +
						 '<table><tbody><tr><td> First Name : </td> <td> <input type="text" name="fname" class="input">*</td></tr>' +
						 '<tr><td> Last Name : </td> <td> <input type="text" name="lname" class="input">*</td></tr>' +
						 '<tr><td> Email : </td> <td> <input type="text" name="email" class="input">*</td></tr>' +
						 '<tr><td> Password : </td> <td> <input type="password" name="password" class="input">*</td></tr>' +
						 '<tr><td> Retype Password : </td> <td> <input type="password" name="rpassword" class="input">*</td></tr>' +
						  '<tr><td colspan=2 id=signuperror class=error></td></tr>' +
						 '</tbody></table>';
	var signUpDialog = new Dialog();//{"Ok":dialogCallback ,"Cancel": function(){self.closeDialog()}
	signUpDialog.openDialog(signUpDiv, null, {"Submit": dialogCallback}, "Sign up", 350, 310);
	var email;
	var password;
	
	function dialogCallback(){
		var elems = signUpDialog.getDialogElements();
		signUpDialog.disableDialogButton("Submit");
		email = elems['email'];
		password = elems['password'];
		var rpassword = elems['rpassword'];
		var fname = elems['fname'];
		var lname = elems['lname'];
		var validate = validateContact(fname, lname, email, "", "key", "", "Email");
		if (validate == "success"){
			if(password != rpassword){
				showSignUperror('Passwords do not match.');
			}else if (password.length < 6 ){	
				showSignUperror('Password must be more than 6 characters.');
			}else{
				var data = "type=signUp&email="+email+"&password="+password+
				"&timezone="+(-new Date().getTimezoneOffset())+
				"&fname="+fname+"&lname="+lname+
				"&im=&mobphone=&imtype=1&accounttype=3&cycle=Y";
				Request.sendPOST(Framework.userURL, data, signupResponse);
			}
		}else{
			showSignUperror(validate);
		}
	}*/
	
	/*function signupResponse(response){
		signUpDialog.enableDialogButton("Submit");
		var responseChildNodes = response.responseXML.documentElement.childNodes;
		var res = responseChildNodes[0].firstChild.nodeValue;
		switch(res) {
			case "success":
				signUpDialog.closeDialog();
				showHelp('Successfull registration');
				break;
			case "error":
				showSignUperror(Framework.Lang.error);
			case "inuse" : case "user exists":
				showSignUperror(Framework.Lang.signupEmailInUse);
				break;
			case "invalidkey":
				showSignUperror("Invalid Image Code");
				break;
			default:
				showSignUperror(res);
	   			break;
		}

	}
	
	function showSignUperror(msg){
		$id("signuperror").innerHTML = msg;
	}*/
	function signupResponse(response){
	try{
		var resp=eval("("+response.responseText+")");
		var key = resp.status;
		if( key == "redirect"){
			window.location.href = resp.data;
		}else{
			msg.innerHTML = key;
		}
	}catch(ex){
	}
}

}
function sendPasswdReq(){
	var email = $id("email").value;
	if(email != ""){
		Request.sendGET(Framework.serverPath+"/ChangePassword?email="+email, sendPasswdMailReq);
		msg.innerHTML = "Sending mail...";
	}
	else{
		msg.innerHTML = "Please input your e-mail address";
	}
}

function sendPasswdMailReq(response){
	if(response.responseText == 'OK'){
		msg.innerHTML = "Your password is sent to your email";
		setTimeout("refreshloginframe()", 60*1000);
	}
	else if(response.responseText == 'notExist'){
		msg.innerHTML = Framework.Lang.signinNoMatch;
	}else if(response.responseText == 'ERROR'){
		msg.innerHTML = "error during mail sending";
	}
	else{
		msg.innerHTML = "error";
	}
}








function showHelp(topic){
	var txt;
	var width = 340;
	var height = 140;
	switch(topic){
		case 'Monitoring Frequency' :
					txt = 'An interval between consecutive checks.';
					break;
		case 'SMS' : 
					txt = 'In case of any issue with your server an SMS can be sent to your mobile phone informing you regarding that immediately. This service will be activated after your 30-day trial period. You will get a bunch of FREE SMSs included with corresponding plan. In case you will need additional number of SMSs please contact us.';
					break;
		case 'Weekly Summary Reports' :
					txt = 'Each week you will receive an e-mail with report regarding weekly uptimes of your servers.';
					break;
		case 'History' : 
					txt = 'Allows to access all the previous data regarding any monitored server.';
					break; 
		case 'Phone number format' :
					txt = 'Mobile number need to be set in the standard international format, with country code followed by number. No leading zero to the number and no special characters such as "+" or spaces must be used. For example, a number in the UK being 07901231234 should be changed to 447901231234.';
					break;
		case 'Email contact' : 
					txt = 'You will get a confirmation e-mail on this account within several minutes. In order to receive alerts you will need to confirm your e-mail address. If your added contact highlighted with a red color in a contacts table that means that you didn`t confirm your account yet.';
					width = 360;
					height = 180;
					break;
		case 'IM contact' : 
					txt = 'You will get a confirmation message on this account within several minutes. In order to receive alerts you will need to confirm your IM. If your added contact highlighted with a red color in a contacts table that means that you didn`t confirm your account yet.';
					height = 180;
					break;
		case 'Successfull registration': 
					txt = 'Congratulations, you have successfully registered in Monitis. Confirmation email was sent to you. Plaese Confirm your contact and use your username and password to login into your Monitis account.';
					break;
		case 'SMS activation' :
					txt = 'Once you have added your phone number, you should have received an activation code on your mobile phone. Please enter that code in Activation code field and enter Apply button in order to receive SMS notifications.';
					height = 170;
					break;
		case "Confirm Email":
					txt = "You will receive confirmation email within few minutes.";
					break;
		case "Confirm IM":
					txt = "You will receive confirmation message within few minutes.";
					break;
		case "Confirm mobile number":
					txt = "You will receive confirmation message within few minutes.";
					break;
		case 'Confirmation is sent':
					txt = "Confirmation msg is already sent. Please check your contact.";
					break;
		case 'Portable phone number' :
						txt = 'The number which is moved from one operator to another under the \'number portability\' system. Currently we support portable numbers only in Australia.';
						break;
	}
	var dialog = new Dialog();
	var cont = document.createElement("div");
	cont.className = "text";
	cont.innerHTML = txt;
	dialog.openDialog(cont, null, "ok", topic, width, height);
	
}

