
$(document).ready(function(){
  
    verifySession();
});
function loginVerify()
{
	jQuery(function ($) {
	
	var OSX = {
		container: null,
		init: function () {
			$("input.osx, a.osx").click(function (e) {
				e.preventDefault();	

				$("#osx-modal-content").modal({
					overlayId: 'osx-overlay',
					containerId: 'osx-container',
					closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: ['0',],
					overlayClose: true,
					onOpen: OSX.open,
					onClose: OSX.close
				});
			});
		},
		open: function (d) {
			var self = this;
			self.container = d.container[0];
			d.overlay.fadeIn('slow', function () {
				$("#osx-modal-content", self.container).show();
				var title = $("#osx-modal-title", self.container);
				title.show();
				d.container.slideDown('slow', function () {
					setTimeout(function () {
						var h = $("#osx-modal-data", self.container).height()
							+ title.height()
							+ 20; // padding
						d.container.animate(
							{height: h}, 
							200,
							function () {
								$("div.close", self.container).show();
								$("#osx-modal-data", self.container).show();
							}
						);
					}, 300);
				});
			})
		},
		close: function (d) {
			var self = this; // this = SimpleModal object
			d.container.animate(
				{top:"-" + (d.container.height() + 20)},
				500,
				function () {
					self.close(); // or $.modal.close();
				}
			);
		}
	};

	OSX.init();

});
}

function  cookieEvents(email,psw,page){
}
function init(){
	cookieEvents("","","");
}

init();

function verifySession(){
    $.ajax({
        url:"top.php",
        type:"GET",
        success:function(msg){
            if(msg == 0){
                $("#memberHome").css("display","block");
            }else{
                $("#memberHome").html(msg);
				$("div#osx-modal-content").css("display","none");
            }
        }
    });
}


function checkAvlbl(d){
    $.post("checkAvlbl.php",
    {
        "email":d.value
    },
    function(msg){
        if(msg == 1){
            alert("Email address is not available.Please change the email address");
        }
    },
    "json");
}

function validate_register() {
	var empty_reg = /^\s+$/;
	var email_reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var email = document.getElementById("email");
	var password = document.getElementById("psw");
	var cpassword = document.getElementById("cpsw");
    if(email.value==""||email.value.match(empty_reg) || checkAvlbl(this)) {
		alert("Email is required");
		email.focus();
		return false;
	}
	else if(!email.value.match(email_reg)) {
		alert("Please enter a valid Email");
		email.focus();
		return false;
	}
	if(password.value==""||password.value.match(empty_reg)) {
		alert("Please choose a Password");
		password.focus();
		return false;
	}

	if((password.value).length < 8){
		alert("Password length must be minimum 8 characters");
		password.focus();
		return false;
	}
	if(cpassword.value==""||cpassword.value.match(empty_reg)) {
		alert("Please retype the Password");
		cpassword.focus();
		return false;
	}
	if(cpassword.value!=password.value) {
		alert("Passwords mismatched");
		cpassword.focus();
		return false;
	}
	
return true;
}

function registerUser(){
    if(validate_register()){
        $.post("register.php",
        {
			"name":$("#name").val(),
            "email":$("#email").val(),
            "psw":$("#psw").val(),
			
        },
        function(msg){
            if(msg == "1"){
                $("form input:text").val("");
                $("form input:password").val("");
            }
			
            $.ajax({
                url:"top.php",
                type:"GET",
                success:function(msg){
                    alert("Thank you for Registering with us");
					$("#memberHome").html(msg);
					$("div#osx-modal-content").css("display","none");
					location.reload(true);	
					}
            });
        },
        "json"
        );
    }
}
function validate_login() {
	var empty_reg = /^\s+$/;
	var username = document.getElementById("log");
	var password = document.getElementById("pwd");
	if(username.value==""||username.value.match(empty_reg)) {
		alert("Email is required");
		username.focus();
		return false;
	}
	if(password.value==""||password.value.match(empty_reg)) {
		alert("Password is required");
		password.focus();
		return false;
	}	
return true;
}
function loginValidate(){
    if(validate_login()){
        $.post("loginValidate.php",
        {
            "log":$("#log").val(),
            "pwd":$("#pwd").val()
        },
        function(msg){

            if(msg == 1){
                $.ajax({
                    url:"top.php",
                    type:"GET",
                    success:function(msg){
                      alert("Login Successful");
					$("#memberHome").html(msg);
					$("div#osx-modal-content").css("display","none");
					location.reload(true);			
                    }
                });
            }else{
                alert("Invalid Username/Password");
            }
        },
        "json"
        );
    }
}


function verifyLoginsession(){	
    cookieEvents("", "", "","verify");
    $.ajax({
        url:"verify.php",
        type:"GET",
        success:function(msg){
            if(msg == "0"){
               loginVerify();
            }else if(msg == "1"){	
			location.reload(true);
            }
        }
    });
}


/***************Upload Resume**********/
function validate_UploadResume() {
	var empty_reg = /^\s+$/;
	var titlemanu = document.getElementById("titlemanu");
	var actualPath = document.getElementById("actualPath");
	if(titlemanu.value==""||titlemanu.value.match(empty_reg)) {
		alert("Manuscript is required");
		titlemanu.focus();
		return false;
	}
	if(actualPath.value==""||actualPath.value.match(empty_reg)) {
		alert("FilePath is required");
		actualPath.focus();
		return false;
	}	
return true;
}
function addUploadResume(){
	if(validate_UploadResume())
	{
        $.post("saveResume.php",
        {
            "titlemanu":$("#titlemanu").val(),
            "actualPath":$("#actualPath").val()
        },
        function(resp){
            $("input:text").val("");
            $("#messageProduct").html("<font color='green'>Your Resume Added Succesfully</font>");
        },
        "json");
	}
}
function getActual4mChild(val){
 $("#actualPath").val(val);
}
function getActual4mChild2(val,id){
 $("#actualPath"+id).val(val);
}
function openActualFile(){    
        var actual = window.open("actualfileUpload.php","ActualFile","width=300, height=200,resizable=yes,scrollbars=yes");
}

/***********************End***********************/
