jQuery(document).ready(function() 
{
	$.ajax({url: 'session_start.php', async: false});
	$.post("session_get.php", {lang:"--"}, function(data) { loadBundles(data); });

	mainEvents();
	
	createAnAccountEvents();
	
	loadingScreen();

});

function loadingScreen()
{
	$("#loadingScreen").dialog({
		autoOpen: false, // set this to false so we can manually open it 
		dialogClass: "loadingScreenWindow",
		overlay: { 
            opacity: 0.7, 
            background: "black" 
        },
		closeOnEscape: false, 
		draggable: false, 
		width: 220, 
		minHeight: 80,
		modal: true, 
		buttons: {}, 
		resizable: false, 
		open: function() { 
			// scrollbar fix for IE 
			$('body').css('overflow','hidden'); 
		}, 
		close: function() { 
			// reset overflow 
			$('body').css('overflow','auto'); 
		} 
	}); 	
}

function waitingDialog(waiting) { 
	// I choose to allow my loading screen dialog to be customizable, you don't have to 
/*	$("#loadingScreen").empty().html(waiting.message && 
			'' != waiting.message ? waiting.message : jQuery.i18n.prop('p_loadingScreen_please_wait'));*/ 
/*	$("#loadingScreen").dialog('option', 'title', waiting.title && 
			'' != waiting.title ? waiting.title : jQuery.i18n.prop('p_loadingScreen_loading'));*/ 
	$("#loadingScreen").dialog('open'); 
} 

function closeWaitingDialog() { 
	$("#loadingScreen").dialog('close'); 
}

function loadBundles(lang) 
{
	jQuery.i18n.properties({
	    name:'contents', 
	    path:'properties/', 
	    mode:'both',
	    language:lang, 
	    callback: function() {
			updateMenu();
		    updateUserField();
		    dispatchPage();
	    }
	});
}

function mainEvents() 
{
	$("#EN").click(function(event) {
		loadBundles('en');
		$.post("session_set.php", {lang:"en"} );
		event.preventDefault();
	});
	
	$("#TR").click(function(event) {
		loadBundles('tr');
		$.post("session_set.php", {lang:"tr"} );
		event.preventDefault();
	});
}

function dispatchPage()
{
	if ($.url.param("page") == 'createanaccount') {
	//	$("#bigBoxContent").trigger("createAnAccountEvent");
		createAnAccount($("#bigBoxContent"));
	}
	
	if ($.url.param("confirm") != '') {
		confirmAccount($.url.param("confirm"));
	}
	
	if ($.url.param("page") == 'myproducts') {
		myProducts();
	}
	
	if ($.url.param("page") == 'forgotpassword') {
		forgotPassword();
	}
	
	if ($.url.param("page") == 'personaldata') {
		personalData();
	}
	
	if ($.url.param("page") == 'changepassword') {
		changePassword();
	}
	
	if ($.url.param("page") == 'emailaddress') {
		changeEmail();
	}
	
	if ($.url.param("page") == 'subscriptions') {
		subscriptions();
	}
	
	if ($.url.param("page") == 'logout') {
		logout();
	}
	
	if ($.url.param("page") == '' && $.url.param("confirm") == '') {
		page_home();
	}
	
	if ($.url.param("page") == 'products') {
		page_products();
	}
	
	if ($.url.param("page") == 'product_volko_baglama') {
		page_product_volko_baglama();
	}
	
	if ($.url.param("page") == 'product_volko_vinyl_beats') {
		page_product_volko_vinyl_beats();
	}
	
	if ($.url.param("page") == 'support') {
		page_support();
	}
	
	if ($.url.param("page") == 'download') {
		page_download();
	}

	if ($.url.param("page") == 'company') {
		page_company();
	}
		
	if ($.url.param("page") == 'shop') {
		page_shop();
	}
	
	if ($.url.param("page") == 'purchase_success') {
		page_purchase_success();
	}
}

function updateMenu() 
{
	jQuery('.menu')
		.empty()
		.append('<a href="?"><img src="images/'+jQuery.i18n.prop('home')+'" border="0"></img></a>')
		.append('<a href="?page=products"><img src="images/'+jQuery.i18n.prop('products')+'" border="0"></img></a>')
		.append('<a href="?page=support"><img src="images/'+jQuery.i18n.prop('support')+'" border="0"></img></a>')
		.append('<a href="?page=download"><img src="images/'+jQuery.i18n.prop('downloads')+'" border="0"></img></a>')
		.append('<a href="?page=company"><img src="images/'+jQuery.i18n.prop('about')+'" border="0"></img></a>')
		.append('<a href="?page=shop"><img src="images/'+jQuery.i18n.prop('shop')+'" border="0"></img></a>')
		.append('<a href="http://www.facebook.com/sharer.php?u=http%3a%2f%2fwww.volkoaudio.com'+
				'&t=Virtual%20Instruments" target="_blank">'+
				'<img src="images/f_icon_t.png" border="0" alt="Add to facebook"/></a> '+
				'<a href="http://twitter.com/home?status=http%3a%2f%2fwww.volkoaudio.com" target="_blank" >'+
				'<img src="images/twitter.png" border="0" alt="Add to Twitter"/></a>');
/*		.append('<a href="#"><img src="images/'+jQuery.i18n.prop('partners')+'" border="0"></img></a>');*/
}

function fillDate()
{
	$('#f_caa_date_year').append('<option value="0" selected></option>');
	for (i = 1900; i < 2011; ++i)
		$('#f_caa_date_year').append('<option value="'+i+'">'+i+'</option>');
	
	$('#f_caa_date_month').append('<option value="0" selected></option>');
	for (i = 1; i < 10; ++i)
		$('#f_caa_date_month').append('<option value="0'+i+'">0'+i+'</option>');
	for (i = 10; i < 13; ++i)
		$('#f_caa_date_month').append('<option value="'+i+'">'+i+'</option>');
	
	$('#f_caa_date_day').append('<option value="0" selected></option>');
	for (i = 1; i < 10; ++i)
		$('#f_caa_date_day').append('<option value="0'+i+'">0'+i+'</option>');
	for (i = 10; i < 32; ++i)
		$('#f_caa_date_day').append('<option value="'+i+'">'+i+'</option>');
}

function fillCountry()
{
	$('#f_caa_country').append('<option value="">Please Select</option>');
	$.ajax({ url: 'countries.json', dataType: 'json',  
		success: function(data){  
			$.each(data, function(i, item){
				$('#f_caa_country').append('<option value="'+item.country[1]+'">'+item.country[1]+'</option>');
			});
		}, async: false
	});  
}

function showResult(header_key, content_key)
{
	var content;
	$.ajax({url: 'view_result.php', success: function(data) {
		content = data;
	}, async: false});
	$("#bigBoxContent").empty().append(content);
	jQuery('#view_result_header').empty().append(jQuery.i18n.prop(header_key));
	jQuery('#view_result_content').empty().append(jQuery.i18n.prop(content_key));
}

function showError(header_key, content_key)
{
	var h_key, c_key, content;
	
	if(header_key == null) {
		h_key = 'p_view_error_header';
		c_key = 'p_view_error_content';
	} else {
		h_key = header_key;
		c_key = content_key;
	}
	
	$.ajax({url: 'view_error.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#view_error_header').empty().append(jQuery.i18n.prop(h_key));
	$('#view_error_content').empty().append(jQuery.i18n.prop(c_key));
}

function logout()
{
	$.ajax({url: 'session_end.php', async: false});
    updateUserField();
    document.location='?';
}

function updateUserField() 
{
    $.post("session_get.php", {logged_in:"--"}, function(data) {
        if (data == "true") {
            $("#divLinkUser").css("visibility", "visible");
            $("#divFormUser").css("visibility", "hidden");
            $("#divLinkUser").show();
            $("#divFormUser").hide();
            
            var first_name;
            var last_name;
            
            $.ajax({type: 'POST', url: 'session_get.php', 
            	data: {first_name:"first_name"}, success: function(data) { first_name = data; }, async: false});
            
            $.ajax({type: 'POST', url: 'session_get.php', 
            	data: {last_name:"last_name"}, success: function(data) { last_name = data; }, async: false});

            $("#showName").empty().append(jQuery.i18n.prop('r_menu_hello')+" "+first_name+" "+last_name);
            $("#myProducts").empty().append(jQuery.i18n.prop('r_menu_my_products'));
            $("#personalData").empty().append(jQuery.i18n.prop('r_menu_personal_data'));
            $("#changePassword").empty().append(jQuery.i18n.prop('r_menu_change_password'));
            $("#emailAddress").empty().append(jQuery.i18n.prop('r_menu_email_address'));
            $("#subscriptions").empty().append(jQuery.i18n.prop('r_menu_subscriptions'));
            $("#logout").empty().append(jQuery.i18n.prop('r_menu_logout'));
        } else {
            $("#divLinkUser").css("visibility", "hidden");
            $("#divFormUser").css("visibility", "visible");
            $("#divFormUser").show();
            $("#divLinkUser").hide();
            
            $("#formUserPassword").val('');
            
        	$('#formUserEmailText').empty().append(jQuery.i18n.prop('r_login_email'));
        	$('#formUserPasswordText').empty().append(jQuery.i18n.prop('r_login_password'));
        	$('#formUserLogin').attr('value',jQuery.i18n.prop('r_login_login'));
            $('#formUserRememberMeText').empty().append(jQuery.i18n.prop('r_login_remember_me'));
        	$('#createAnAccount').empty().append(jQuery.i18n.prop('r_login_create_account'));
        	$('#forgotPassword').empty().append(jQuery.i18n.prop('r_login_forgot_password'));
        }
        var validator; 
        
        validator = $("#formUser").validate({
    		rules: {
    			formUserEmail: {
    				required: true,
    				email: true,
    				minlength: 6
    			}, 
    			formUserPassword: {
    				required: true,
    				minlength: 5
    			}
    		},
    		submitHandler: function(form) {
    			waitingDialog({});
    			$.ajax({type: 'POST', url: 'member_login.php', 
    	    		data: {
    					login: $('#formUserEmail').val(), 
    					password: $('#formUserPassword').val(), 
    					rememberme: $('#formUserRememberMe').is(':checked')
    				}, 
    	    		success: function(data) {
    	    			if (data == 'MEMBER_LOGIN_SUCCESS') {
    	    				updateUserField();
    	    				if ($.url.param("page") == 'shop') {
    	    					var custom;
    	    					$.ajax({type: 'POST', url: 'session_get.php', 
    	    				    	data: {custom:"custom"}, success: function(data) { custom = data; }, 
    	    				    		async: false});
    	    					$('#shop_1001_custom').val(custom);
    	    					$('#shop_1002_custom').val(custom);
    	    					$('#shop_1003_custom').val(custom);
    	    				}
    	    			} else if (data == 'MEMBER_LOGIN_ERROR_CONFIRM') {
    	    				$("#formUserMessages").empty().append(jQuery.i18n.prop('r_login_error_confirm'));
    	    				$("#formUserPassword").val('');
    	    			} else {
    	    				$("#formUserMessages").empty().append(jQuery.i18n.prop('r_login_error_authentication'));
    	    				$("#formUserPassword").val('');
    	    			}
    	    		}, async: false }
    	    	);
    			closeWaitingDialog();
    		}
    	});    	
    });
}

function createAnAccount(handle)
{
	jQuery(document).attr("title", "Volko Audio - Create An Account");
	
	$('.explain_box').empty()
		.append('<img src="images/'+jQuery.i18n.prop('eb_user_account')+'" border="0"></img>');
	
	$('#contents').css('height', '450px');
	
	var content;
	
	$.ajax({url: 'view_create_account.php', success: function(data) {
		content = data;
	}, async: false});

	$(handle).empty().append(content);

	fillDate();

	fillCountry();
	
	jQuery('#f_caa_header').empty().append(jQuery.i18n.prop('p_f_caa_header'));
	jQuery('#f_caa_explain').empty().append(jQuery.i18n.prop('p_f_caa_explain'));
	jQuery('#f_caa_email_text').empty().append(jQuery.i18n.prop('p_f_caa_email_text'));
	jQuery('#f_caa_password_text').empty().append(jQuery.i18n.prop('p_f_caa_password_text'));
	jQuery('#f_caa_password_again_text').empty().append(jQuery.i18n.prop('p_f_caa_password_again_text'));
	jQuery('#f_caa_first_name_text').empty().append(jQuery.i18n.prop('p_f_caa_first_name_text'));
	jQuery('#f_caa_last_name_text').empty().append(jQuery.i18n.prop('p_f_caa_last_name_text'));
	jQuery('#f_caa_gender_text').empty().append(jQuery.i18n.prop('p_f_caa_gender_text'));
	jQuery('#f_caa_gender1_text').empty().append(jQuery.i18n.prop('p_f_caa_gender1_text'));
	jQuery('#f_caa_gender2_text').empty().append(jQuery.i18n.prop('p_f_caa_gender2_text'));
	jQuery('#f_caa_phone_text').empty().append(jQuery.i18n.prop('p_f_caa_phone_text'));
	jQuery('#f_caa_date_text').empty().append(jQuery.i18n.prop('p_f_caa_date_text'));
	jQuery('#f_caa_country_text').empty().append(jQuery.i18n.prop('p_f_caa_country_text'));
	jQuery('#f_caa_verify_text').empty().append(jQuery.i18n.prop('p_f_caa_verify_text'));
	jQuery('#f_caa_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit'));
	
	$("#f_caa").validate({
		rules: {
			f_caa_email: { required: true, email: true, minlength: 6 }, 
			f_caa_password: {required: true, minlength: 6 },
			f_caa_password_again: { required: true, equalTo: "#f_caa_password" },
			f_caa_first_name: {required: true, minlength: 2 },
			f_caa_last_name: {required: true, minlength: 2 },
			f_caa_country: {required: true }, 
			f_caa_verify: {required: true }
		}, 
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_create.php', 
	    		data: {
					f_caa_email: $('#f_caa_email').val(), 
					f_caa_password: $('#f_caa_password').val(), 
					f_caa_first_name: $('#f_caa_first_name').val(), 
					f_caa_last_name: $('#f_caa_last_name').val(), 
					f_caa_gender: jQuery('input[name=f_caa_gender]:checked').val(),
					f_caa_phone: $('#f_caa_phone').val(),
					f_caa_date_year: $('#f_caa_date_year').val(),
					f_caa_date_month: $('#f_caa_date_month').val(),
					f_caa_date_day: $('#f_caa_date_day').val(),
					f_caa_country: $('#f_caa_country option:selected').text(),
					f_caa_verify: $('#f_caa_verify').val()
				}, 
	    		success: function(data) {
	    			updateUserField();
					if (data == 'MEMBER_CREATE_SUCCESS_ID_001') {
						showResult('p_view_member_create_header', 'p_view_member_create_content');
					} else if(data == 'MEMBER_CREATE_ERROR_ID_003') {
						$('#f_caa_error').empty().append(jQuery.i18n.prop('p_f_caa_error_already_exist'));
						$('#f_caa_email').val('');
						$('#f_caa_password').val('');
						$('#f_caa_password_again').val('');
					} else if(data == 'MEMBER_CREATE_ERROR_ID_011') {
						$('#f_caa_error').empty().append(jQuery.i18n.prop('p_f_caa_error_verify'));
						$('#f_caa_password').val('');
						$('#f_caa_password_again').val('');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});
}

function confirmAccount(param)
{
	$('.explain_box').empty()
		.append('<img src="images/'+jQuery.i18n.prop('eb_user_account')+'" border="0"></img>');
	
	if (param != '') {
		$.ajax({type: 'POST', url: 'member_confirm.php', 
    		data: { confirm: param }, 
    		success: function(data) {
    			updateUserField();
    			
    			var content;
    			$.ajax({url: 'view_confirm.php', success: function(data) {
    				content = data;
    			}, async: false});
    			
				if(data == 'MEMBER_CONFIRM_SUCCESS_ID_001') {
					$("#bigBoxContent").empty().append(content);
					$("#view_confirm_success").css("visibility", "visible");
					$("#view_confirm_success").show();
					$("#view_confirm_success_header").empty().append(jQuery.i18n.prop('p_view_confirm_header'));
					$("#view_confirm_success_content").empty()
						.append(jQuery.i18n.prop('p_view_confirm_success_content'));
				} else {
					// ERROR
					$("#bigBoxContent").empty().append(content);
					$("#view_confirm_error").css("visibility", "visible");
					$("#view_confirm_error").show();
					$("#view_confirm_error_header").empty().append(jQuery.i18n.prop('p_view_confirm_header'));
					$("#view_confirm_error_content").empty()
						.append(jQuery.i18n.prop('p_view_confirm_error_content'));					
				}
    		}, async: false }
    	);
	}	
}

function createAnAccountEvents()
{
	$('#f_caa_date_month').live('change', function(event) {
		createAnAccountManageDate(this, event);
	});
/*	
	$("#f_caa").live('submit', function(event) { 
		alert('submit'); 
		return false; 
	});
*/
}

function createAnAccountManageDate(handle) 
{
	var first = new Array(1, 3, 5, 7, 8, 10, 12 );
	var second = new Array(4, 6, 9, 11);
	for (fi = 0; fi < first.length; ++fi)
		if ($(handle).val() == first[fi]) {
			$('#f_caa_date_day').empty();
			$('#f_caa_date_day').append('<option value="0" selected></option>');
			for (fj = 1; fj < 10; ++fj)
				$('#f_caa_date_day').append('<option value="0'+fj+'">0'+fj+'</option>');				
			for (fj = 10; fj < 32; ++fj)
				$('#f_caa_date_day').append('<option value="'+fj+'">'+fj+'</option>');
		}
	for (si = 0; si < second.length; ++si)
		if ($(handle).val() == second[si]) {
			$('#f_caa_date_day').empty();
			$('#f_caa_date_day').append('<option value="0" selected></option>');
			for (sj = 1; sj < 10; ++sj)
				$('#f_caa_date_day').append('<option value="0'+sj+'">0'+sj+'</option>');				
			for (sj = 10; sj < 31; ++sj)
				$('#f_caa_date_day').append('<option value="'+sj+'">'+sj+'</option>');
		}
	if ($(handle).val() == 2) {
		$('#f_caa_date_day').empty();
		$('#f_caa_date_day').append('<option value="0" selected></option>');
		for (sj = 1; sj < 10; ++sj)
			$('#f_caa_date_day').append('<option value="0'+sj+'">0'+sj+'</option>');
		for (sj = 10; sj < 29; ++sj)
			$('#f_caa_date_day').append('<option value="'+sj+'">'+sj+'</option>');
	}
}

function personalData()
{
	jQuery(document).attr("title", "Volko Audio - Edit Account");
	var content;
	
	$.ajax({url: 'view_edit_account.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);

	fillDate();

	fillCountry();
	
	jQuery('#f_caa_header').empty().append(jQuery.i18n.prop('p_f_caa_header_edit'));
	jQuery('#f_caa_explain').empty().append(jQuery.i18n.prop('p_f_caa_explain_edit'));
	jQuery('#f_caa_email_text').empty().append(jQuery.i18n.prop('p_f_caa_email_text'));
	jQuery('#f_caa_first_name_text').empty().append(jQuery.i18n.prop('p_f_caa_first_name_text'));
	jQuery('#f_caa_last_name_text').empty().append(jQuery.i18n.prop('p_f_caa_last_name_text'));
	jQuery('#f_caa_gender_text').empty().append(jQuery.i18n.prop('p_f_caa_gender_text'));
	jQuery('#f_caa_gender1_text').empty().append(jQuery.i18n.prop('p_f_caa_gender1_text'));
	jQuery('#f_caa_gender2_text').empty().append(jQuery.i18n.prop('p_f_caa_gender2_text'));
	jQuery('#f_caa_phone_text').empty().append(jQuery.i18n.prop('p_f_caa_phone_text'));
	jQuery('#f_caa_date_text').empty().append(jQuery.i18n.prop('p_f_caa_date_text'));
	jQuery('#f_caa_country_text').empty().append(jQuery.i18n.prop('p_f_caa_country_text'));
	jQuery('#f_caa_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit_update'));
	
	var caa_email, caa_first_name, caa_last_name, caa_gender, caa_phone, caa_date, caa_country;
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {login:"login"}, success: function(data) { caa_email = data; }, async: false});
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {first_name:"first_name"}, success: function(data) { caa_first_name = data; }, async: false});	
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {last_name:"last_name"}, success: function(data) { caa_last_name = data; }, async: false});

	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {gender:"gender"}, success: function(data) { caa_gender = data; }, async: false});
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {phone:"phone"}, success: function(data) { caa_phone = data; }, async: false});
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {date_of_birth:"date_of_birth"}, success: function(data) { caa_date = data; }, async: false});
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {country:"country"}, success: function(data) { caa_country = data; }, async: false});
	
	jQuery('#f_caa_email').val(caa_email);
	jQuery('#f_caa_first_name').val(caa_first_name);
	jQuery('#f_caa_last_name').val(caa_last_name);

	if (caa_gender == '0')
		jQuery('#f_caa_gender1').attr('checked', true);
	else
		jQuery('#f_caa_gender2').attr('checked', true);
	
	jQuery('#f_caa_phone').val(caa_phone);
	
	jQuery('#f_caa_date_year').val(caa_date.substr(0,4));
	jQuery('#f_caa_date_month').val(caa_date.substr(5,2));
	jQuery('#f_caa_date_day').val(caa_date.substr(8,2));

	jQuery('#f_caa_country').val(caa_country);
	
	$("#f_caa_update").validate({
		rules: {
			f_caa_email: { required: true, email: true, minlength: 6 }, 
			f_caa_first_name: {required: true, minlength: 2 },
			f_caa_last_name: {required: true, minlength: 2 },
			f_caa_country: {required: true }
		}, 
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_update.php', 
	    		data: {
					f_caa_email: $('#f_caa_email').val(),  
					f_caa_first_name: $('#f_caa_first_name').val(), 
					f_caa_last_name: $('#f_caa_last_name').val(), 
					f_caa_gender: jQuery('input[name=f_caa_gender]:checked').val(),
					f_caa_phone: $('#f_caa_phone').val(),
					f_caa_date_year: $('#f_caa_date_year').val(),
					f_caa_date_month: $('#f_caa_date_month').val(),
					f_caa_date_day: $('#f_caa_date_day').val(),
					f_caa_country: $('#f_caa_country option:selected').text()
				}, 
	    		success: function(data) {
	    			updateUserField();
					if (data == 'MEMBER_UPDATE_SUCCESS_ID=001') {
						showResult('p_view_member_update_header', 'p_view_member_update_content');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});
}

function myProducts()
{
	jQuery(document).attr("title", "Volko Audio - My Products");
	var content, picture;
	
	$.ajax({url: 'view_my_products.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);

	$.ajax({ url: 'member_my_products.php', dataType: 'json',  
		success: function(data){
			$.each(data, function(i, item){
				if (i > 1) {
					$("#contents").height($("#contents").height() + 142);
				}
				if (item.pro_id == 1 || item.pro_id == 2) {
					if (item.pro_id == 1)
						picture = 'volko_baglama_box.png';
					else
						picture = 'volko_vinyl_beats_box.png';
					
					if (item.is_need_productid == 1) {
						$('#myproductstable tr:last').after('<tr>'+
								'<td width="140"><img src="images/'+picture+'"</td>'+
								'<td style="vertical-align: middle; ">'+
								jQuery.i18n.prop('p_view_product_name')+' : '+item.pro_name+'<br />'+
								jQuery.i18n.prop('p_view_product_username')+' : '+item.PRODUCTID+'<br />'+
								'<a href="dl.php?d='+item.pro_id+'">'+
								jQuery.i18n.prop('p_view_product_download')+'</a><br />'+
								'<a href="#" onclick="sendRegInfo('+item.pro_id+', \''+item.PRODUCTID+'\');">'+
								jQuery.i18n.prop('p_view_product_SendRegInfo')+'</a><br />'+
								'</td>'+
								'</tr>');
					} else {
						$('#myproductstable tr:last').after('<tr>'+
								'<td width="140"><img src="images/'+picture+'"</td>'+
								'<td style="vertical-align: middle; ">'+
								jQuery.i18n.prop('p_view_product_name')+' : '+item.pro_name+'<br />'+
								'<a href="dl.php?d='+item.pro_id+'">'+
								jQuery.i18n.prop('p_view_product_download')+'</a><br />'+
								'</td></tr>');
					}
				} else {
					$('#myproductstable tr:last').after('<tr>'+
							'<td colspan="2" style="text-align: center;">You do not have any product. </td>'+
							'</tr>');
				}
			});
		}, async: false
	});  
	
	jQuery('#view_my_products_header').empty().append(jQuery.i18n.prop('p_view_my_products_header'));
}

function sendRegInfo(pd, pp)
{
	$.ajax({type: 'GET', url: 'sri.php', 
    	data: {d:pd, p:pp}, success: function(data) {
    		if (data == 'SUCCESSFUL')
    			alert(jQuery.i18n.prop('p_view_product_SendRegInfoSuccess'));
    		else
    			alert(jQuery.i18n.prop('p_view_product_SendRegInfoFail'));
    	}, async: true});
}

function forgotPassword()
{
	jQuery(document).attr("title", "Volko Audio - Forgot Password");
	var content;
	
	$.ajax({url: 'view_forgot_password.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#f_header').empty().append(jQuery.i18n.prop('p_view_forgot_password_header'));
	jQuery('#f_explain').empty().append(jQuery.i18n.prop('p_view_forgot_password_content'));
	jQuery('#f_email_text').empty().append(jQuery.i18n.prop('p_f_caa_email_text'));
	jQuery('#f_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit_send'));
	
	$("#f_forgot_password").validate({
		rules: {
			f_email: { required: true, email: true, minlength: 6 }
		}, 
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_forgot_password.php', 
	    		data: {
					login: $('#f_email').val()
				}, 
	    		success: function(data) {
					if (data == 'MEMBER_FORGOT_PASSWORD_SUCCESS_ID_001') {
						showResult('p_view_forgot_password_success_header', 'p_view_forgot_password_success_content');
					} else if (data == 'MEMBER_FORGOT_PASSWORD_ERROR_ID_003') {
						showError('p_view_forgot_password_error3_header', 
								'p_view_forgot_password_error3_content');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});
}

function changePassword()
{
	
	jQuery(document).attr("title", "Volko Audio - Change Password");
	var content;
	
	$.ajax({url: 'view_edit_password.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#f_header').empty().append(jQuery.i18n.prop('p_view_change_password_header'));
	jQuery('#f_explain').empty().append(jQuery.i18n.prop('p_view_change_password_content'));
	jQuery('#f_password_old_text').empty().append(jQuery.i18n.prop('p_f_password_old_text'));
	jQuery('#f_password_text').empty().append(jQuery.i18n.prop('p_f_password_text'));
	jQuery('#f_password_again_text').empty().append(jQuery.i18n.prop('p_f_password_again_text'));
	jQuery('#f_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit_save'));
	
	$("#f_edit_password").validate({
		rules: {
			f_password_old: { required: true, minlength: 5 },
			f_password: { required: true, minlength: 5 },
			f_password_again: { required: true, equalTo: "#f_password" }
		}, 
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_edit_password.php', 
	    		data: {
					f_password_old: $('#f_password_old').val(),
					f_password: $('#f_password').val(),
					f_password_again: $('#f_password_again').val()
				}, 
	    		success: function(data) {
					if (data == 'MEMBER_EDIT_PASSWORD_SUCCESS_ID_001') {
						showResult('p_view_edit_password_success_header', 'p_view_edit_password_success_content');
					} else if (data == 'MEMBER_EDIT_PASSWORD_ERROR_ID_003') {
						showError('p_view_edit_password_error3_header', 
								'p_view_edit_password_error3_content');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});	
}

function changeEmail()
{
	
	jQuery(document).attr("title", "Volko Audio - Email Address");
	var content;
	
	$.ajax({url: 'view_edit_email.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#f_header').empty().append(jQuery.i18n.prop('p_view_edit_email_header'));
	jQuery('#f_explain').empty().append(jQuery.i18n.prop('p_view_edit_email_content'));
	jQuery('#f_email_text').empty().append(jQuery.i18n.prop('p_f_caa_email_text'));
	jQuery('#f_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit_change'));
	
	var email;
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {login:"login"}, success: function(data) { email = data; }, async: false});
	
	jQuery('#f_email').val(email);
	
	$("#f_edit_email").validate({
		rules: {
			f_email: { required: true, email: true, minlength: 5 }
		}, 
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_edit_email.php', 
	    		data: {
					f_email: $('#f_email').val()
				}, 
	    		success: function(data) {
					if (data == 'MEMBER_EDIT_EMAIL_SUCCESS_ID_001') {
						showResult('p_view_edit_email_success_header', 'p_view_edit_email_success_content');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});
}

function subscriptions()
{
	jQuery(document).attr("title", "Volko Audio - Subscriptions");
	var content;
	
	$.ajax({url: 'view_subscriptions.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#f_header').empty().append(jQuery.i18n.prop('p_view_subs_header'));
	jQuery('#f_explain').empty().append(jQuery.i18n.prop('p_view_subs_content'));
	jQuery('#f_subs_text').empty().append(jQuery.i18n.prop('p_f_subs_text'));
	jQuery('#f_submit').empty().val(jQuery.i18n.prop('p_f_caa_submit_update'));
	
	var subs;
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {subs:"subs"}, success: function(data) { subs = data; }, async: false});
	
	if (subs == 1)
		$('#f_subs').attr('checked', true);
	
	$("#f_newsletter").validate({
		submitHandler: function(form) {
			waitingDialog({});
			$.ajax({type: 'POST', url: 'member_subscriptions.php', 
	    		data: {
					f_subs: $('#f_subs').is(':checked')
				}, 
	    		success: function(data) {
					if (data == 'MEMBER_SUBSCRIPTIONS_SUCCESS_ID_001') {
						showResult('p_view_subs_success_header', 'p_view_subs_success_content');
					} else {
						showError();
					}
	    		}, async: false }
	    	);
			closeWaitingDialog();
		}
	});
}

function page_home()
{
	jQuery(document).attr("title", "Volko Audio - Home");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_home')+'" border="0"></img>');
	
	$('#contents').css('height', '650px');
	
	var content; var content2;
	
	$.ajax({url: 'view_home.php', success: function(data) {
		content = data;
	}, async: false});
	
	$.ajax({url: 'view_home2.php', success: function(data) {
		content2 = data;
	}, async: false});

	$("#big_box_short_id").css({'background-image': 'url()'});
	$("#big_box_short_id").css({'padding': '0px 0px 0px 0px'});
	$("#big_box_short_id").append('<div id="bigBoxContent" style="text-align: center; height: 0px;"></div>');
	$("#big_box_short_id").append('<div id="bigBoxContent2" style="text-align: center; height: 300px;"></div>');
	$("#bigBoxContent").css({'background-image': 'url(images/big_box_short.png)'});
	$("#bigBoxContent2").css({'background-image': 'url(images/big_box_short.png)'});
	$("#bigBoxContent").css({'padding': '22px 5px 5px 5px'});
	$("#bigBoxContent2").css({'padding': '22px 5px 5px 5px'});
	$("#bigBoxContent").empty().append(content);
	$("#bigBoxContent2").empty().append(content2);
	
	jQuery('#baglama_text_short').empty().append(jQuery.i18n.prop('p_baglama_text_short'));
	jQuery('#vinyl_beats_text_short').empty().append(jQuery.i18n.prop('p_vinyl_beats_text_short'));
	
	$('#home_news_1_image').attr("src", jQuery.i18n.prop('p_home_news_1_image'));
	$('#home_news_1_header').empty().append(jQuery.i18n.prop('p_home_news_1_header'));
	$('#home_news_1_date').empty().append(jQuery.i18n.prop('p_home_news_1_date'));
	$('#home_news_1_content').empty().append(jQuery.i18n.prop('p_home_news_1_content'));
	
	$('#home_news_2_image').attr("src", jQuery.i18n.prop('p_home_news_2_image'));
	$('#home_news_2_header').empty().append(jQuery.i18n.prop('p_home_news_2_header'));
	$('#home_news_2_date').empty().append(jQuery.i18n.prop('p_home_news_2_date'));
	$('#home_news_2_content').empty().append(jQuery.i18n.prop('p_home_news_2_content'));
	
	$('#home_news_3_image').attr("src", jQuery.i18n.prop('p_home_news_3_image'));
	$('#home_news_3_header').empty().append(jQuery.i18n.prop('p_home_news_3_header'));
	$('#home_news_3_date').empty().append(jQuery.i18n.prop('p_home_news_3_date'));
	$('#home_news_3_content').empty().append(jQuery.i18n.prop('p_home_news_3_content'));
	
	$('#home_news_4_image').attr("src", jQuery.i18n.prop('p_home_news_4_image'));
	$('#home_news_4_header').empty().append(jQuery.i18n.prop('p_home_news_4_header'));
	$('#home_news_4_date').empty().append(jQuery.i18n.prop('p_home_news_4_date'));
	$('#home_news_4_content').empty().append(jQuery.i18n.prop('p_home_news_4_content'));
	
	$('#home_news_5_image').attr("src", jQuery.i18n.prop('p_home_news_5_image'));
	$('#home_news_5_header').empty().append(jQuery.i18n.prop('p_home_news_5_header'));
	$('#home_news_5_date').empty().append(jQuery.i18n.prop('p_home_news_5_date'));
	$('#home_news_5_content').empty().append(jQuery.i18n.prop('p_home_news_5_content'));
}

function page_products()
{
	jQuery(document).attr("title", "Volko Audio - Products");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_products')+'" border="0"></img>');
	
	$('#contents').css('height', '530px');
	
	var content;
	
	$.ajax({url: 'view_products.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#baglama_text_short').empty().append(jQuery.i18n.prop('p_baglama_text_short'));
	jQuery('#vinyl_beats_text_short').empty().append(jQuery.i18n.prop('p_vinyl_beats_text_short'));
	
}

function page_product_volko_baglama()
{
	jQuery(document).attr("title", "Volko Audio - Product Volko Baglama");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_products')+'" border="0"></img>');
	
	$('#contents').css('height', '930px');
	
	var content;
	
	$.ajax({url: 'view_product_volko_baglama.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#baglama_text_long').empty().append(jQuery.i18n.prop('p_baglama_text_long'));
}

function page_product_volko_vinyl_beats()
{
	jQuery(document).attr("title", "Volko Audio - Product Volko Vinyl Beats");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_products')+'" border="0"></img>');
	
	$('#contents').css('height', '1150px');
	
	var content;
	
	$.ajax({url: 'view_product_volko_vinyl_beats.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	jQuery('#vinyl_beats_text_long1').empty().append(jQuery.i18n.prop('p_vinyl_beats_text_long1'));
	jQuery('#vinyl_beats_text_long2').empty().append(jQuery.i18n.prop('p_vinyl_beats_text_long2'));
}

function page_support()
{
	$(document).attr("title", "Volko Audio - Support");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_support')+'" border="0"></img>');
	
	$('#contents').css('height', '400px');
	
	var content;
	
	$.ajax({url: 'view_support.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#support_sale').empty().append(jQuery.i18n.prop('p_support_sale'));
	$('#support_sale_text').empty().append(jQuery.i18n.prop('p_support_sale_text'));
	$('#support_ts').empty().append(jQuery.i18n.prop('p_support_ts'));
	$('#support_ts_text').empty().append(jQuery.i18n.prop('p_support_ts_text'));
	$('#support_address').empty().append(jQuery.i18n.prop('p_support_address'));
	$('#support_address_text').empty().append(jQuery.i18n.prop('p_support_address_text'));
	
}

function page_download()
{
	$(document).attr("title", "Volko Audio - Download");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_downloads')+'" border="0"></img>');
	
	$('#contents').css('height', '850px');
	
	var content;
	
	$.ajax({url: 'view_download.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#download_free_downloads').empty().append(jQuery.i18n.prop('p_download_free_downloads'));
	$('#download_audio_demos').empty().append(jQuery.i18n.prop('p_download_audio_demos'));
	$('#download_plugin_demos').empty().append(jQuery.i18n.prop('p_download_plugin_demos'));
	$('#download_audio_demos_commercial').empty().append(jQuery.i18n.prop('p_download_audio_demos_commercial'));
	$('#download_free_loops_commercial').empty().append(jQuery.i18n.prop('p_download_free_loops_commercial'));
	$('#download_product_manuals').empty().append(jQuery.i18n.prop('p_download_product_manuals'));
}

function page_company()
{
	$(document).attr("title", "Volko Audio - Company");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_about')+'" border="0"></img>');
	
	$('#contents').css('height', '400px');
	
	var content;
	
	$.ajax({url: 'view_company.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#company_about_us').empty().append(jQuery.i18n.prop('p_company_about_us'));
	$('#company_about_us_text').empty().append(jQuery.i18n.prop('p_company_about_us_text'));
}

function page_shop()
{
	$(document).attr("title", "Volko Audio - Shop");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_shop')+'" border="0"></img>');
	
	$('#contents').css('height', '500px');
	
	var custom;
	
	$.ajax({type: 'POST', url: 'session_get.php', 
    	data: {custom:"custom"}, success: function(data) { custom = data; }, async: false});
	
	var content;
	
	$.ajax({url: 'view_shop.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#shop_vb_vvb_exp').empty().append(jQuery.i18n.prop('p_shop_vb_vvb_exp'));
	$('#shop_vb_vvb_fee').empty().append(jQuery.i18n.prop('p_shop_vb_vvb_fee'));
	$('#shop_vb_exp').empty().append(jQuery.i18n.prop('p_shop_vb_exp'));
	$('#shop_vb_fee').empty().append(jQuery.i18n.prop('p_shop_vb_fee'));
	$('#shop_vvb_exp').empty().append(jQuery.i18n.prop('p_shop_vvb_exp'));
	$('#shop_vvb_fee').empty().append(jQuery.i18n.prop('p_shop_vvb_fee'));
	$('#shop_timing').empty().append(jQuery.i18n.prop('p_shop_timing'));
	
	$('#shop_1001_custom').val(custom);
	$('#shop_1002_custom').val(custom);
	$('#shop_1003_custom').val(custom);
}

function page_purchase_success()
{
	$(document).attr("title", "Volko Audio - Shop");
	
	$('.explain_box').empty().append('<img src="images/'+jQuery.i18n.prop('eb_shop')+'" border="0"></img>');
	
	$('#contents').css('height', '500px');
	
	var content;
	
	$.ajax({url: 'view_purchase_success.php', success: function(data) {
		content = data;
	}, async: false});
	
	$("#bigBoxContent").empty().append(content);
	
	$('#purchase_success_header').empty().append(jQuery.i18n.prop('p_purchase_success_header'));
	$('#purchase_success_content').empty().append(jQuery.i18n.prop('p_purchase_success_content'));
}
