﻿$(document).ready(function(){

	$(".btn_login_slide").click(function(){
		$("#login_panel").slideToggle("slow");
		$(this).toggleClass("btn_login_active"); return false;
	});
	
	 
});


function checkLogin() {
	var loginID = $("input#CLSLogin").val();
	var password = $("input#CLSPassword").val();
	var loginsuccess = '';
	
	//remove all the class add the messagebox classes and start fading
	$("#CLSLoginMsgTitle").text('').fadeIn("slow");
	$("#CLSLoginMsg").text('Checking...').fadeIn("slow");
	//check the username exists or not from ajax
	$.post("/user_loginCheck.php",{ id:$("input#CLSLogin").val(), pwd:$("input#CLSPassword").val() } ,function(data) {
	//$.post(commonPortal+"user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
	//$.post(domain + "Software/Common/Portal/user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
		loginSuccess = data.substring(0,3);
		if(loginSuccess=='yes') { // login success
			//document.getElementById("logout_panel_area").style.display = "block";
			//document.getElementById("login_panel_area").style.display = "none";
			window.location='/members/index.php';
		} else { //login failed
			$("#CLSLoginMsgTitle").fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html('Sorry...').fadeTo(900,1);
			});
			$("#CLSLoginMsg").fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html('Login name and/or password is not correct.').fadeTo(900,1);
			});
		}
	});
}

function checkLogin2() {
	var loginID = $("input#CLSLogin2").val();
	var password = $("input#CLSPassword2").val();
	var loginsuccess = '';
	//remove all the class add the messagebox classes and start fading
	$("#CLSLoginMsgTitle2").text('').fadeIn("slow");
	$("#CLSLoginMsg2").text('Checking...').fadeIn("slow");
	//check the username exists or not from ajax
	$.post("/user_loginCheck.php",{ id:$("input#CLSLogin2").val(), pwd:$("input#CLSPassword2").val() } ,function(data) {
	//$.post(commonPortal+"user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
	//$.post(domain + "Software/Common/Portal/user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
		loginSuccess = data.substring(0,3);
		if(loginSuccess=='yes') { // login success
			//document.getElementById("logout_panel_area").style.display = "block";
			//document.getElementById("login_panel_area").style.display = "none";
			window.location='/members/index.php';
		} else { //login failed
			$("#CLSLoginMsgTitle2").fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html('Sorry,').fadeTo(900,1);
			});
			$("#CLSLoginMsg2").fadeTo(200,0.1,function() { //start fading the messagebox
				//add message and change the class of the box and start fading
				$(this).html('Login name and/or password is not correct.').fadeTo(900,1);
			});
		}
	});
}

function checkLogin3() {
	var loginID = $("input#CLSLogin3").val();
	var password = $("input#CLSPassword3").val();
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if (!pattern.test(loginID)) {
		$("#CLSLogin3Note").fadeTo(200,0.1,function() { //start fading the messagebox
			//add message and change the class of the box and start fading
			$(this).html('Please input your email').removeClass().addClass('field_msgRed').fadeTo(900,1);
		});
	}
	if (password == "") {
		$("#CLSPassword3Note").fadeTo(200,0.1,function() { //start fading the messagebox
			//add message and change the class of the box and start fading
			$(this).html('Please input your password.').fadeTo(900,1);
		});
		//$("input#userFullName").focus();
	}
	
	if (pattern.test(loginID)&&(password!="")) {
		//remove all the class add the messagebox classes and start fading
		$("#CLSLoginMsg").text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("/user_loginCheck.php",{ id:$("input#CLSLogin3").val(), pwd:$("input#CLSPassword3").val() } ,function(data) {
		//$.post(commonPortal+"user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
		//$.post(domain + "Software/Common/Portal/user_loginCheck.php",{ id:loginID, pwd:password } ,function(data) {
			var dataInfo = data.split('+');
			if(dataInfo[0]=='yes') { // login success
				//window.location='/members/index.php';
				joinUsFormObject.name=dataInfo[1];
				joinUsFormObject.email=dataInfo[2];
				joinUsFormObject.country=dataInfo[3];
				joinUsFormObject.language=dataInfo[4];
				joinUsFormObject.expiryDate=dataInfo[5];
				nextStep('3');
				ListData('3');
			} else { //login failed
				$("#CLSLoginMsg3").fadeTo(200,0.1,function() { //start fading the messagebox
					//add message and change the class of the box and start fading
					$(this).html('Login name and/or password is not correct. <br> Please register below if you are a new customer.').fadeTo(900,1);
				});
			}
		});
	}
}

function subscribeEmail() {
	//remove all the class add the messagebox classes and start fading
	$("#sc_email_Note").removeClass().addClass('field_msgBlack').text('Please wait...').fadeIn("slow");
	$.post("newsletter/subscribe.php",{ news_header_subscribe_field:$("input#news_header_subscribe_field").val() } ,function(data) {
		$("#sc_email_Note").fadeTo(200,0.1,function() { //start fading the messagebox
		//add message and change the class of the box and start fading
			$(this).html(data).removeClass().addClass('field_msgRed').fadeTo(900,1);
		});
	});
}
