// JavaScript Document
var ob;
var Chgid;
var Chngp;
$(document).ready(function() {
    ob = new Checking('gropFrm');
    $('#Bttnadd').click(function() {
        ob.CheckAdd();
    });
    $('#BttnUpdate').click(function() {
        ob.CheckEdit($(this).attr('title'));
    });
    $('#Chguser').click(function() {

        $.blockUI($("#divImg"), { width: "400px" });
        Chgid = $(this).attr('rel');
        $.ajax({
            type: "POST",
            url: "ajax/user.php",
            data: "mode=ChangeVal&id=" + Chgid,
            success: function(msg) {
                //alert(msg);
                $('#divImg').html(msg);
            }
        });
        return false;
    });
    $('#Chgpass').click(function() {
        $.blockUI($("#divImg"), { width: "400px" });
        Chngp = $(this).attr('rel');
        $.ajax({
            type: "POST",
            url: "ajax/user.php",
            data: "mode=ChangePass&id=" + Chngp,
            success: function(msg) {
                $('#divImg').html(msg);
            }
        });
        return false;
    });
    $('#date_paid').datepicker({

        dateFormat: 'dd-mm-yy'
    });

    $('#boardYes').click(function() {
        $('#board_text').show();
    });
    $('#boardNo').click(function() {
        $('#board_text').hide();
    });

    $('#board_text').hide();

    $('#otherNetworkYes').click(function() {
        $('#networks_text').show();
    });
    $('#otherNetworkNo').click(function() {
        $('#networks_text').hide();
    });

    $('#networks_text').hide();
    
    
    
    
    

});

function Checking(form)
{
	this._form=$('#'+form);
	this._mode=$('<input type="hidden" name="hmode"/>').prependTo(this._form);
	this._hid=$('<input type="hidden" name="hid"/>').prependTo(this._form);
	this._status=$('<input type="hidden" name="status"/>').prependTo(this._form);
}
Checking.prototype.ShowMssg=function(text)
{
	var msg=$('#fname').parent().parent();
	return msg.before('<tr id="Error"><td colspan="2" align="center" valign="middle" class="errMsg">'+text+'</td></tr>');
}
Checking.prototype.ShowMssgAjax=function(id,text)
{
	var msg=id.parent().parent();
	return msg.before('<tr id="Error"><td colspan="2" align="center" valign="middle" class="errMsg">'+text+'</td></tr>');
}
Checking.prototype.CheckAdd=function()
{
	var my;
	my=new MyFunctions();
    $('#Error').remove();
	 
	if(jQuery.trim($('#date_paid').val()).length==0)
	{
		ob.ShowMssg('- Enter Paid Date.');
		$('#date_paid').focus();
	}
	else if(jQuery.trim($('#fname').val()).length==0)
	{
		ob.ShowMssg('- Enter Your First name.');
		$('#fname').focus();
	}
	else if(jQuery.trim($('#lname').val()).length==0)
	{
		ob.ShowMssg('- Enter Your Last name.');
		$('#lname').focus();
	}
	
	/*
	else if(jQuery.trim($('#paid_amount').val()).length==0)
	{	
		ob.ShowMssg('-Please enter Paid Amount.');
		$('#paid_amount').focus();			
	}
	
	else if(jQuery.trim($('#SequenceNb').val()).length==0)
	{
		ob.ShowMssg('-Enter Sequence Number');
		$('#SequenceNb').focus();
	}
	else if(jQuery.trim($('#PWI_MembershipNb').val()).length==0)
	{
		ob.ShowMssg('- Enter PWI Membership Number.');
		$('#PWI_MembershipNb').focus();
	}*/
	else if(!my.isvalidemail($('#email').val()))
	{	
		ob.ShowMssg('-Please enter your valid email ID.');
		$('#email').focus();			
	}
	
	else if(jQuery.trim($('#address').val()).length==0)
	{
		ob.ShowMssg('-Enter your Address');
		$('#address').focus();
	}
	else if(jQuery.trim($('#zip').val()).length==0)
	{
		ob.ShowMssg('- Enter your Postal Code.');
		$('#zip').focus();
	}
	else if(jQuery.trim($('#city').val()).length==0)
	{
		ob.ShowMssg('- Enter your City.');
		$('#city').focus();
	}
	else if($('#country').val()==0)
	{
		ob.ShowMssg('- Select Your Country .');
		$('#country').focus();
	}
	
	else if(jQuery.trim($('#mobile').val()).length==0)
	{
		ob.ShowMssg('- Enter your Mobile number.');
		$('#mobile').focus();
	}
	else if(jQuery.trim($('#phone').val()).length==0)
	{
		ob.ShowMssg('- Enter your Phone number.');
		$('#phone').focus();
    }
    else if (jQuery.trim($('#CompanyName').val()).length == 0) {
        ob.ShowMssg('- Enter Current Company Name.');
        $('#CompanyName').focus();
    }

	else if(jQuery.trim($('#Market').val()).length==0)
	{
		ob.ShowMssg('- Enter Current Company and Market Sector.');
		$('#Market').focus();
	}
	else if(jQuery.trim($('#jobtitle').val()).length==0)
	{
		ob.ShowMssg('- Enter your Job Title.');
		$('#jobtitle').focus();
	}
	else if(jQuery.trim($('#websit').val()).length==0)
	{
		ob.ShowMssg('- Enter your Website.');
		$('#websit').focus();
	}
	
	else if(jQuery.trim($('#Nationality').val()).length==0)
	{
		ob.ShowMssg('- Enter your Nationality.');
		$('#Nationality').focus();
	}
	
	else if(jQuery.trim($('#Education').val()).length==0)
	{
		ob.ShowMssg('- Enter Education.');
		$('#Education').focus();
	}
	else if(jQuery.trim($('#interest').val()).length==0)
	{
		ob.ShowMssg('- Enter Areas of interest.');
		$('#interest').focus();
    }
	/*
	else if(jQuery.trim($('#board_text').val()).length==0)
	{
		ob.ShowMssg('- Enter your board.');
		$('#board_text').focus();
	}
	*/
	/*else if(jQuery.trim($('#networks_text').val()).length==0)
	{
		ob.ShowMssg('Enter Networks Text.');
		$('#networks_text').focus();
	}
	*/
	else if(jQuery.trim($('#PWIreference').val()).length==0)
	{
		ob.ShowMssg('How did you hear of PWI.');
		$('#PWIreference').focus();
	}
	else
		ob.SetMode('SaveInfo',0);
}
Checking.prototype.CheckEdit=function(id)
{
	
	var my;
	my=new MyFunctions();
    $('#Error').remove();
	 if(jQuery.trim($('#fname').val()).length==0)
	{
		ob.ShowMssg('- Enter Your First name.');
		$('#fname').focus();
	}
	else if(jQuery.trim($('#lname').val()).length==0)
	{
		ob.ShowMssg('- Enter Your Last name.');
		$('#lname').focus();
	}
	else if(jQuery.trim($('#date_paid').val()).length==0)
	{
		ob.ShowMssg('- Enter Paid Date.');
		$('#date_paid').focus();
	}
	
	else if(jQuery.trim($('#paid_amount').val()).length==0)
	{	
		ob.ShowMssg('-Please enter Paid Amount.');
		$('#paid_amount').focus();			
	}
	
	else if(jQuery.trim($('#SequenceNb').val()).length==0)
	{
		ob.ShowMssg('-Enter Sequence Number');
		$('#SequenceNb').focus();
	}
	else if(jQuery.trim($('#PWI_MembershipNb').val()).length==0)
	{
		ob.ShowMssg('- Enter PWI Membership Number.');
		$('#PWI_MembershipNb').focus();
	}
	else if(!my.isvalidemail($('#email').val()))
	{	
		ob.ShowMssg('-Please enter your valid email ID.');
		$('#email').focus();			
	}
	
	else if(jQuery.trim($('#address').val()).length==0)
	{
		ob.ShowMssg('-Enter your Address');
		$('#address').focus();
	}
	else if(jQuery.trim($('#zip').val()).length==0)
	{
		ob.ShowMssg('- Enter your Postal Code.');
		$('#zip').focus();
	}
	else if(jQuery.trim($('#city').val()).length==0)
	{
		ob.ShowMssg('- Enter your City.');
		$('#city').focus();
	}
	else if($('#contry').val()==0)
	{
		ob.ShowMssg('- Select Your Country .');
		$('#contry').focus();
	}
	
	else if(jQuery.trim($('#fax').val()).length==0)
	{
		ob.ShowMssg('- Enter your Fax number.');
		$('#fax').focus();
	}
	else if(jQuery.trim($('#phone').val()).length==0)
	{
		ob.ShowMssg('- Enter your Phone number.');
		$('#phone').focus();
	}
	else if(jQuery.trim($('#mobile').val()).length==0)
	{
		ob.ShowMssg('- Enter your Mobile number.');
		$('#mobile').focus();
	}
	else if(jQuery.trim($('#Market').val()).length==0)
	{
		ob.ShowMssg('- Enter Current Company and Market Sector.');
		$('#Market').focus();
	}
	else if(jQuery.trim($('#jobtitle').val()).length==0)
	{
		ob.ShowMssg('- Enter your Job Title.');
		$('#jobtitle').focus();
	}
	else if(jQuery.trim($('#websit').val()).length==0)
	{
		ob.ShowMssg('- Enter your Website.');
		$('#websit').focus();
	}
	
	else if(jQuery.trim($('#Nationality').val()).length==0)
	{
		ob.ShowMssg('- Enter your Nationality.');
		$('#Nationality').focus();
	}
	
	else if(jQuery.trim($('#Education').val()).length==0)
	{
		ob.ShowMssg('- Enter Education.');
		$('#Education').focus();
	}
	else if(jQuery.trim($('#interest').val()).length==0)
	{
		ob.ShowMssg('- Enter Areas of interest.');
		$('#interest').focus();
	}
	else if(jQuery.trim($('#board_text').val()).length==0)
	{
		ob.ShowMssg('- Enter your board.');
		$('#board_text').focus();
	}
	else if(jQuery.trim($('#networks_text').val()).length==0)
	{
		ob.ShowMssg('Enter Networks Text.');
		$('#networks_text').focus();
	}
	else if(jQuery.trim($('#PWIraference').val()).length==0)
	{
		ob.ShowMssg('How did you hear of PWI.');
		$('#PWIraference').focus();
	}
	else
		ob.SetMode('SaveUpdate',id);
}

Checking.prototype.SetMode=function(mode,id)
{
	ob._mode.val(mode);
	ob._hid.val(id);
	ob._form.submit();
}
Checking.prototype.DelMode=function(mode,id)
{
	if(confirm('- Are you sure to delete?'))
	ob.SetMode(mode,id);
}
Checking.prototype.CancelMode=function()
{
	
}
Checking.prototype.ChangeStatus=function(mode,id,stat)
{
	ob._mode.val(mode);
	ob._hid.val(id);
	ob._status.val(stat);
	ob._form.submit();
}
Checking.prototype.UpdateUsername=function(id)
{
	var my;
	my=new MyFunctions();
	$('#Error').remove();
	var divID=$('#username');
	if(jQuery.trim($('#username').val()).length==0)
	{
		ob.ShowMssgAjax(divID,'- Enter Your Username.');
		$('#username').val('');
		$('#username').focus();
	}
	else if(!my.isvalidemail($('#username').val()))
	{	
		ob.ShowMssgAjax(divID,'-Please enter your valid email ID.');
		$('#username').select();			
	}
	else
	{
		$.ajax({
				type: "POST",
				url: "ajax/user.php",
				data: "mode=UpdateUsername&value="+$('#username').val()+"&id="+id,
				success: function(msg){
					if(msg=='done')
					{
						$.unblockUI();
						window.location.reload();
					}
					else
						alert(msg);
				}
		});
		return false;
	}
}
Checking.prototype.UpdatePassword=function(id)
{
	$('#Error').remove();
	var divID=$('#pass');
	if(jQuery.trim($('#pass').val()).length==0)
	{
		ob.ShowMssgAjax(divID,'- Enter Your Password.');
		$('#pass').val('');
		$('#pass').focus();
	}
	else if(jQuery.trim($('#confpass').val()).length==0)
	{
		ob.ShowMssgAjax(divID,'- Enter Confirm Password.');
		$('#confpass').val('');
		$('#confpass').focus();
	}
	else if($('#pass').val()!=$('#confpass').val())
	{
		ob.ShowMssgAjax(divID,'- Confirm Password Mismatched.');
		$('#confpass').select();
	}
	else
	{
		$.ajax({
				type: "POST",
				url: "ajax/user.php",
				data: "mode=Updatepassword&pass="+$('#pass').val()+"&id="+id,
				success: function(msg){
					if(msg=='done')
					{
						$.unblockUI();
						window.location.reload();
					}
				}
		});
		return false;
	}
}