/**
 * Initialize
 */ 
$(document).ready(function(){
    Adelphus.init();

    
/******************************************************/
});


/**
 * Web ScoreTracker Admin NameSpace
 */
var Adelphus = window.Adelphus || 
{
    timerID: new Object(),
    loadingTimeout: 2000,
    
    init: function() 
    {        
    },
    //---------------- Functions For validation -------------//
	LTrim: function(value) {
     	var re = /\s*((\S+\s*)*)/;
     	return value.replace(re, "$1");
    },
    RTrim: function(value) {
    	var re = /((\s*\S+)*)\s*/;
    	return value.replace(re, "$1");
    },
    trim: function(value) {
    	return Adelphus.LTrim(Adelphus.RTrim(value));
  	},
	IsNumeric: function(PossibleNumber)
	{
		var PNum = new String(PossibleNumber);
		var regex = /[^0-9]/;
		return !regex.test(PNum);
	},
	IsPrice: function(PossibleNumber)
	{
		var PNum = new String(PossibleNumber);
		var regex = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
		return !regex.test(PNum);
	},
	IsEmail: function(PossibleEmail)
	{
		var PEmail = new String(PossibleEmail);
		var regex = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
		return !regex.test(PEmail);
	},
	//-------------- For validation End --------------------//
	showAddress: function()
	{
		var a = $('#deliveryAddressList').val();
		$("[id^=deliveryaddress]").hide();
		$('#deliveryaddress'+a).show();
		$("input[@type='checkbox'][@name='differbill']").each(
            function()
            {

                if(!this.checked)
                {
 					$("[id^=billingaddress]").hide();
					$('#billingaddress'+a).show();
                }
                else
                {
                	$('#billingform').show(); 
					$('#billingaddress').show();                	
                }
            });
            
	},
	
	showBillingAddress: function()
	{
		var a = $('#billingAddressList').val();
		$("[id^=billingaddress]").hide();
		$('#billingaddress'+a).show();
	},

	
	//--------------- Change Address for Music Cart --------------//
	showMusicAddress: function()
	{
		var a = $('#billingAddressList').val();
		$("[id^=billingaddress]").hide();
		$('#billingaddress'+a).show();
	},
	//--------------- Show Add Address for Music Cart --------------//
	addAddress: function()
	{
		$("#add_address").show();
	},
	//--------------- Hide Add Address for Music Cart --------------//
	addaddress_cancel: function(){
		$("#add_address").hide();
	},
	//--------------- Save Add Address for Music Cart --------------//
	saveaddress_music: function(){
		var addr_naem = $("#name").val();
		var addr_address = $("#address").val();
		var addr_street = $("#street").val();
		var addr_city = $("#city").val();
		var addr_state = $("#state").val();
		var addr_postcode = $("#postcode").val();
		var addr_country = $("#country").val();
		var addressname = $("#addressname").val();
		
		if(addr_naem == "" || addr_naem.length == 0){
			alert("Please Enter the Name");
			document.getElementById("name").focus();
			return false;
		}
		if(addr_address == null || addr_address.length == 0){
			alert("Please Enter the Address");
			document.getElementById("address").focus();
			return false;
		}
		if(addr_postcode == null || addr_postcode.length == 0){
			alert("Please Enter the Postcode");
			document.getElementById("postcode").focus();
			return false;
		}
		if(addressname == null || addressname.length == 0){
			alert("Please Enter the Title");
			document.getElementById("addressname").focus();
			return false;
		}
		$.post(siteUrl+"mod/stores/musicstores/music_actions.php",{
	       	action:"stores:newaddress:save",
			name: addr_naem,
			address: addr_address,
			street: addr_street,
			city: addr_city,
			state: addr_state,
			postcode: addr_postcode,
			country: addr_country,
			addressname: addressname
	     },function (data){
	     	if(data == "SUCCESS"){
	     		alert("An Address has been successfully saved"); 
	     		window.location = userUrl+"music/address";
	     	}else{
	     		aler(data);
	     	}
	     });
	},
	
	showBillingBlock: function()
    {
		var a = $('#deliveryAddressList').val();
		$("input[@type='checkbox'][@name='differbill']").each(
            function()
            {

                if(this.checked)
                {
                	$('#billingform').show(); 
					$('#billingaddress').show();                	
                }
                else
                {
                	$('#billingform').hide(); 
					$('#billingaddress').hide(); 
					$("[id^=billingaddress]").hide();
					$('#billingaddress'+a).show();               	
                 }
            }
            )
    },
	toggleBlock: function(elementId)
	{
		$('#'+elementId).toggle();
	},
	showBlock: function(elementId)
	{
		$('#'+elementId).show();
	},
	hideBlock: function(elementId)
	{
		$('#'+elementId).hide();
	},
	
	//-------------- Display page for Email This -----------//
	get_email_page: function(valu,class1,widget){
		var show;
		show = document.getElementById("email_this" + valu + widget);
		if($("#email_this"+ valu + widget).val() == 0){
			show.value = 1;
			$("#digitalbox" + valu + widget).slideDown("slow");
		}else{
			show.value = 0;
			$("#digitalbox" + valu + widget).slideUp("slow");
		}
		
		$("#digitalbox" + valu + widget).load(siteUrl+"mod/stores/lib/stores_mail.php?email_pid=" + valu + "&class=" + class1 + "&widget_id=" + widget);
	},
	//-------------- the time of submit the Email This Page --------// 
	send_mail: function(id,widget){
		var name = $("#new_recipient_name" + id + widget).val();
		var email = $("#new_recipient_email" + id + widget).val();
		var class_id = $("#class_id" + id + widget).val();
		
		if(name.length == 0){
			alert("Please Enter your Friend's Name");
			document.getElementById("new_recipient_name" + id + widget).focus();
			return false;
		}
		if (Adelphus.IsEmail(email)){
			alert("Invalid E-mail Address! Please re-enter.");
			document.getElementById("new_recipient_email" + id + widget).focus();
			return false;
		}
		
		$.post(siteUrl+"mod/stores/lib/stores_send_mail.php",{
			class_id: class_id,
			mail_pid: id,
			new_recipient_name: name,
			new_recipient_email: email,
			new_mail_note: $("#new_mail_note" + id + widget).val(),
			action: "stores:email:send"
		},function(str){
			if(str != 0){
					$("#digitalbox" + id + widget).html(str);
			}else{
				$("#error_msg"+ id + widget).html('&nbsp;&nbsp;Mail Not Sent....');
				$("#error_msg"+ id + widget).css({color: "green", background: "#EFF5FB", border:"1px solid #8DB2E3", padding:"3px"});
			}
		});
	},
	show_hide_add_address: function(){
		var show;
		show = document.getElementById("showaddaddress");
		if(show.value == 0){
			$("#newaddress0").slideUp("slow");
		}else{
			$("#newaddress0").slideDown("slow");
		}
	},
	chnage_display_add: function(){
		var show;
		show = document.getElementById("showaddaddress");
		if(show.value == 0){
			show.value = 1;
		}else{
			show.value = 0;
		}
		
	},
	display_view_edit:function(addid){
		var editshow,disaddress;
		disaddress = document.getElementById("disaddress"+addid);
		editshow = document.getElementById("editaddress"+addid);
		editshow.style.display = "";
		disaddress.style.display = "none";
	},
	display_hide_edit:function(addid){
		var editshow,disaddress;;
		editshow = document.getElementById("editaddress"+addid);
		disaddress = document.getElementById("disaddress"+addid);
		editshow.style.display = "none";
		disaddress.style.display = "";
	},
	get_add_address: function(addid,url){ /*----for add Address------*/
		Adelphus.cancel_newaddress();
		$("#newaddress"+addid).load(url+"mod/stores/myaccount_address.php",{address_id:addid});
	},
	get_edit_address: function(addid,url){ /*----for edit Address------*/
		var show;
		show = document.getElementById("showaddaddress");	
		if(show.value == 1){
			Adelphus.cancel_newaddress();
		}
		Adelphus.display_view_edit(addid)
		$("#editaddress"+addid).load(url+"mod/stores/myaccount_address.php",{
			action: "stores:address:edit",
			address_id: addid
		});
	},
	get_add_mainaddress: function(url){ /*----for restore the My Address Tab------*/
		$("#add_sub_div").load(url+"mod/stores/my_address.php",{reload:1});
	},
	get_add_mainaccount: function(url){ /*----for restore the My Account Tab------*/
		$("#myacc_sub_div").load(url+"mod/stores/my_account.php",{reload:1});
	},
	cancel_newaddress: function(){
		Adelphus.chnage_display_add();
		Adelphus.show_hide_add_address();
	},
	cancel_editaddress: function(ident){
		Adelphus.display_hide_edit(ident)
	},
	address_save_success: function(){
		alert(document.getElementById("result").value);
	},
	save_address: function(addrid,url){
		if(document.getElementById("name"+addrid).value == "" || document.getElementById("name"+addrid).value.length == 0){
			alert("Please Enter the Name");
			document.getElementById("name"+addrid).focus();
			return false;
		}
		if(document.getElementById("address"+addrid).value == null || document.getElementById("address"+addrid).value.length == 0){
			alert("Please Enter the Address");
			document.getElementById("address"+addrid).focus();
			return false;
		}
		if(document.getElementById("postcode"+addrid).value == null || document.getElementById("postcode"+addrid).value.length == 0){
			alert("Please Enter the Postcode");
			document.getElementById("postcode"+addrid).focus();
			return false;
		}
		if(document.getElementById("addressname"+addrid).value == null || document.getElementById("addressname"+addrid).value.length == 0){
			alert("Please Enter the Title");
			document.getElementById("addressname"+addrid).focus();
			return false;
		}
		$.post(url+"mod/stores/myaccount_action.php",{
	       	action:"stores:myaddress:save",
			address_id:addrid,
	       	name: $("#name"+addrid).val(),
			address: $("#address"+addrid).val(),
			street: $("#street"+addrid).val(),
			city: $("#city"+addrid).val(),
			state: $("#state"+addrid).val(),
			postcode: $("#postcode"+addrid).val(),
			country: $("#country"+addrid).val(),
			addressname: $("#addressname"+addrid).val()
	     },function (){
	     	alert("An Address has been successfully saved"); 
	     	Adelphus.get_add_mainaddress(url);
	     });
	},
	delete_myaccount_address: function(addrid,url){
		$.post(url+"mod/stores/myaccount_action.php",{
	       	action:"stores:myaddress:delete",
			address_id:addrid
	     },function (){
	     	Adelphus.get_add_mainaddress(url);
	     	alert("An Address has been Deleted"); 
	     });
	},
	setprimary_myaccount_address: function(addrid,url){
		$.post(url+"mod/stores/myaccount_action.php",{
	       	action:"stores:address:primary",
			address_id:addrid
	     },function (){
	     	Adelphus.get_add_mainaddress(url);
	     });
	},
	//--------------------------------- Function for add fund to adelphus account ------------------//
	addfund_to_account: function(url){
		
		if(document.getElementById("pay_amount").value == "" || Adelphus.IsPrice(document.getElementById("pay_amount").value)){
			alert("Please Enter a valid Amount");
			document.getElementById("pay_amount").focus();
			return false;
		}
		if(document.getElementById("cc_number").value == "" || !Adelphus.IsNumeric(document.getElementById("cc_number").value)){
			alert("Please Enter a valid Credit Card Number");
			document.getElementById("cc_number").focus();
			return false;
		}
		if(document.getElementById("cvv_number").value == "" || !Adelphus.IsNumeric(document.getElementById("cvv_number").value)){
			alert("Please Enter a valid CVV Number");
			document.getElementById("cvv_number").focus();
			return false;
		}
		$.post(url+"mod/stores/myaccount_action.php",{
	       	action:"stores:myaccount:fundadd",
	       	pay_amount:$("#pay_amount").val(),
	       	cc_number:$("#cc_number").val(),
	       	cctype:$("#cctype").val(),
	       	expdate_month:$("#expdate_month").val(),
	       	expdate_year:$("#expdate_year").val(),
	       	cvv_number:$("#cvv_number").val()
		},function (data){
	     	if(data == "payment_success"){
	     		alert("Successfully Add Fund");
	     		Adelphus.get_add_mainaccount(url)
	     	}else if(data == "error_no_address"){
				alert("Please add your address");
				/*document.getElementById("ext-comp-1005__my_account").setAttribute("class", "");
				document.getElementById("ext-comp-1005__my_address").setAttribute("class", "x-tab-strip-active");
				$("#my_address").load(url+"mod/stores/my_myaddress.php");*/
	     	}else{
	     		alert(data);
	     	}
	     });
	},
	search_payment_history: function(){
		$("#payment_sub_div").load(siteUrl+"mod/stores/my_payments.php",{
			reload:1,
			payment_type:$("#payment_type").val(),
			search_date:$("#search_date").val(),
			search_month:$("#search_month").val(),
			search_year:$("#search_year").val(),
			search:$("#search").val(),
			action:"payment_search"
		});
	},
	payment_page_link: function(page){
		var action;
		if($("#search").val() == 1){
			action = "payment_search";
		}else{
			action = "payment_pageit";
		}
		$("#payment_sub_div").load(siteUrl+"mod/stores/my_payments.php",{
			reload:1,
			action:action,
			payment_type:$("#payment_type").val(),
			search_month:$("#search_month").val(),
			search_year:$("#search_year").val(),
			search:$("#search").val(),
			pageit:page
			
		});
	},
	all_payment_history: function(){
		$("#payment_sub_div").load(siteUrl+"mod/stores/my_payments.php",{
			reload:1
		});
	},
	filter_purchases: function(type,pageit){
		$("#purchase_sub_div").load(siteUrl+"mod/stores/my_purchases.php",{
			reload:1,
			product_type:type,
			pageit: pageit
		});
	},
	filter_solditems: function(type,pageit){
		$("#solditems_sub_div").load(siteUrl+"mod/stores/my_solditems.php",{
			reload:1,
			product_type:type,
			pageit: pageit
		});
	},
	set_shipped: function(id,type,pageit,url){
		if(document.getElementById("sold_ship"+id).checked == true){
			$.post(url+"mod/stores/myaccount_action.php",{
		       	action:"stores:myaccount:shipped",
		       	order_id:id
			},function (data){
		     	Adelphus.filter_solditems(type,pageit);
		     	if(data == "SUCCESS"){
		     		alert("Successfully Updated");	
		     	}
		    });
		}
	},
	//----------------------- Show and Hide the paypal payout section -------------//
	withdraw_fund: function(){
		$('#withdraw_paypal').show(); 
		$('#payment_paypal').hide(); 
		$('#transfer_fund').hide();
	},
	//----------------------- Show and Hide the Add Fund Section -------------//
	add_fund: function(){
		$('#payment_paypal').show(); 
		$('#withdraw_paypal').hide(); 
		$('#transfer_fund').hide();
	},
        //-----------------Show and Hide Transfer Fund Section ----------------- //
        transfer_fund: function(){
                $('#status').html('');
                $('#pament_paypal').hide();
		$('#withdraw_paypal').hide();
		$('#transfer_fund').fadeIn(100);

        },
        //-------------------Process of Transfer Fund --------------//
        transfer_fund_action: function (url,final_balance){
            final_balance = $('#my_cur_balance').html();
            var user_frnd_select  = $('#user_frnd_select').val();
            //alert(user_frnd_select);
            var transfering_amount = $('#transfering_amount').val();
            if(transfering_amount <= 0) {
                alert('Please Enter amount greater than 0');
                return false;
            }
            if(user_frnd_select == "0"){
                alert('Please select a friend from the list');
                return false;
            }
            url = 'http://' + url+'/';
            //alert(url);
            $('#status').html(' Processing...');
            $.post(url+"mod/stores/myaccount_action.php",{
	       	action: "stores:myaccount:fundtransfer",
	       	transfer_id: $("#user_frnd_select").val(),
	       	transfering_amount:$("#transfering_amount").val(),
                final_balance:final_balance
	    },function (data){
                var mydata = data.split('##');
                var datas =mydata[0];
                //alert(datas);
                var cur_balance = mydata[1];
	     	if(datas == "transfer_fund_success"){
	     		//alert("Successfully Transfer Amount")
                        $('#status').html(' <b>Success!!</b>');

                        $("#user_frnd_select").val('0');
                        $("#transfering_amount").val(''); 
                        $('#my_cur_balance').html(cur_balance);
                        $('#transfer_fund').fadeOut(3000);
	     		//Adelphus.get_add_mainaccount(url);
	     		//setTimeout("Adelphus.withdraw_fund();",450);
	     	}else if(datas == "error_no_address"){
				alert("Please add your address");
			}else{
	     		alert(datas);
	     	}
	     });
         },
         hideTransferFund: function(){
             $('#transfer_fund').fadeOut(1000);
         },

	//----------------------- Process of payout (Withdrow fund) -------------//
	withdrow_fund: function(url){
		if(document.getElementById("withdrow_email").value == "" || Adelphus.IsEmail(document.getElementById("withdrow_email").value)){
			alert("Please Enter a valid Email");
			document.getElementById("withdrow_email").focus();
			return false;
		}
		var withdrowamount = document.getElementById("withdrow_amount");
		var total_amount = document.getElementById("total_amount");
		if(withdrowamount.value == "" || Adelphus.IsPrice(withdrowamount.value)){
			alert("Please Enter a valid Amount");
			withdrowamount.focus();
			return false;
		}
		if(parseInt(withdrowamount.value) > parseInt(total_amount.value)){
			alert("Your withdrawal amount is higher than your Resent Account Balance");
			withdrowamount.focus();
			return false;
		}
		$.post(url+"mod/stores/myaccount_action.php",{
	       	action: "stores:myaccount:fundwithdraw",
	       	withdraw_email: $("#withdrow_email").val(),
	       	withdrow_amount:$("#withdrow_amount").val()
	    },function (data){
	     	if(data == "transfer_success"){
	     		alert("Successfully Transfer Amound");
	     		Adelphus.get_add_mainaccount(url);
	     		setTimeout("Adelphus.withdraw_fund();",450);
	     	}else if(data == "error_no_address"){
				alert("Please add your address");
			}else{
	     		alert(data);
	     	}
	     });
	},
	search_cbankpayment_history: function(){
		$("#cbank_payment_subdiv").load(siteUrl+"mod/cbank/cbank_payments.php",{
			reload:1,
			payment_type:$("#payment_type").val(),
			search_date:$("#search_date").val(),
			search_month:$("#search_month").val(),
			search_year:$("#search_year").val(),
			search:$("#search").val(),
			action:"payment_search"
		});
	},
	cbank_page_link: function(page){
		var action;
		if($("#search").val() == 1){
			action = "payment_search";
		}else{
			action = "payment_pageit";
		}
		$("#cbank_payment_subdiv").load(siteUrl+"mod/cbank/cbank_payments.php",{
			reload:1,
			action:action,
			payment_type:$("#payment_type").val(),
			search_month:$("#search_month").val(),
			search_year:$("#search_year").val(),
			search:$("#search").val(),
			pageit:page
			
		});
	},
	all_cbank_history: function(){
		$("#cbank_payment_subdiv").load(siteUrl+"mod/cbank/cbank_payments.php",{
			reload:1
		});
	},
	rating_category: function(rating){
		switch(parseInt(rating)){
			case 0:
				alert("Please Select Your Rating");
				return false;
				break;
			case 1:
				rate = "Poor";
				break;
			case 2:
				rate = "Fair";
				break;
			case 3:
				rate = "Good";
				break; 
			case 4:
				rate = "Very Good";
				break; 
			case 5:
				rate = "Excellent";
				break; 
		}
		return rate;
	},
	rate_show_hide: function(order_id,product_id){
		var show = $("#show"+order_id+product_id).val();
		var showowner = $("#showowner"+order_id+product_id).val();
		var ratediv = document.getElementById("rate"+order_id+product_id);
		var rateownerdiv = document.getElementById("rateowner"+order_id+product_id);
		if(showowner == 1){
			$("#rateowner"+order_id+product_id).slideUp("slow");
			document.getElementById("showowner"+order_id+product_id).value = 0;
		}
		if(show == 0){
			$("#rate"+order_id+product_id).slideDown("slow");
			document.getElementById("show"+order_id+product_id).value = 1;
		}else{
			$("#rate"+order_id+product_id).slideUp("slow");
			document.getElementById("show"+order_id+product_id).value = 0;
		}
	},
	add_rate_product: function(order_id,product_id,type,pageit){
		var rating = $("#rating"+order_id+product_id).val();
		var rate = Adelphus.rating_category(rating);
		$.post(siteUrl+"mod/stores/myaccount_action.php",{
			reload:1,
			product_type:type,
			pageit: pageit,
			product_ident: product_id,
			rating: rating,
			flag: "PRODUCT",
			comment: $("#rate_commant"+order_id+product_id).val(),
			action: "add:rating:product"
		},function (data){
	     	if(data == "SUCCESS"){
	     		alert("Thank you for your vote of " + rate + " ( " + rating + " )");
	     		Adelphus.filter_purchases(type,pageit);
	     	}else{
	     		alert(data);
	     	}
	     });
	},
	edit_rate_product: function(order_id,product_id,type,pageit,ident){
		var rating = $("#rating"+order_id+product_id).val();
		var rate = Adelphus.rating_category(rating);
		$.post(siteUrl+"mod/stores/myaccount_action.php",{
			reload:1,
			product_type:type,
			pageit: pageit,
			product_ident: product_id,
			rating: rating,
			rating_id:ident,
			comment: $("#rate_commant"+order_id+product_id).val(),
			action: "edit:rating:product"
		},function (data){
	     	if(data == "SUCCESS"){
	     		alert("Thank you for your vote of " + rate + " ( " + rating + " )");
	     		Adelphus.filter_purchases(type,pageit);
	     	}else{
	     		alert(data);
	     	}
	     });
	},
	add_rate_owner: function(order_id,product_id,type,pageit){
		var rating = $("#ratingowner"+order_id+product_id).val();
		var rate = Adelphus.rating_category(rating);
		$.post(siteUrl+"mod/stores/myaccount_action.php",{
			reload:1,
			product_type:type,
			pageit: pageit,
			product_ident: product_id,
			rating: rating,
			comment: $("#sellerrate_commant"+order_id+product_id).val(),
			flag: "OWNER",
			action: "add:rating:product"
		},function (data){
	     	if(data == "SUCCESS"){
	     		alert("Thank you for your vote of " + rate + " ( " + rating + " )");
	     		Adelphus.filter_purchases(type,pageit);
	     	}else{
	     		alert(data);
	     	}
	     });
	},
	edit_rate_owner: function(order_id,product_id,type,pageit,ident){
		var rating = $("#ratingowner"+order_id+product_id).val();
		var rate = Adelphus.rating_category(rating);
		$.post(siteUrl+"mod/stores/myaccount_action.php",{
			reload:1,
			product_type:type,
			pageit: pageit,
			product_ident: product_id,
			rating: rating,
			comment: $("#sellerrate_commant"+order_id+product_id).val(),
			rating_id:ident,
			action: "edit:rating:product"
		},function (data){
	     	if(data == "SUCCESS"){
	     		alert("Thank you for your vote of " + rate + " ( " + rating + " )");
	     		Adelphus.filter_purchases(type,pageit);
	     	}else{
	     		alert(data);
	     	}
	     });
	},
	rateowner_show_hide: function(order_id,product_id){
		var showowner = $("#showowner"+order_id+product_id).val();
		var show = $("#show"+order_id+product_id).val();
		var rateownerdiv = document.getElementById("rateowner"+order_id+product_id);
		var ratediv = document.getElementById("rate"+order_id+product_id);
		
		if(show == 1){
			$("#rate"+order_id+product_id).slideUp("slow");
			document.getElementById("show"+order_id+product_id).value = 0;
		}
		if(showowner == 0){
			$("#rateowner"+order_id+product_id).slideDown("slow");
			document.getElementById("showowner"+order_id+product_id).value = 1;
		}else{
			$("#rateowner"+order_id+product_id).slideUp("slow");
			document.getElementById("showowner"+order_id+product_id).value = 0;
		}
	},
	show_comments: function(product_id,rate_ids){
		var show = $("#showcomment"+product_id).val();
		if(show == 1){
			$("#comments"+product_id).load(siteUrl+"mod/stores/myaccount_action.php",{
				product_ident: product_id,
				rate_ids: rate_ids,
				action: "view:rating:comments"
			},function (data){
		     	if(data != ""){
		     		$("#comments"+product_id).show("slow");
		     	}
		     });
		     document.getElementById("showcomment"+product_id).value = 0;
		}		
	},
	hide_comments: function(product_id){
		document.getElementById("showcomment"+product_id).value = 1;
		$("#comments"+product_id).hide("slow");
	},
	show_hide_question_div: function(class_id){
		var show = $("#qshow"+class_id).val();
		var rqshow = $("#rqshow"+class_id).val();
		var class_question_div = document.getElementById("class_question_div"+class_id);
		//var rateownerdiv = document.getElementById("rateowner"+order_id+product_id);
		if(rqshow == 1){
			$("#class_recent_question_div"+class_id).slideUp("slow");
			document.getElementById("rqshow"+class_id).value = 0;
		}
		if(show == 0){
			$("#class_question_div"+class_id).slideDown("slow");
			document.getElementById("qshow"+class_id).value = 1;
		}else{
			$("#class_question_div"+class_id).slideUp("slow");
			document.getElementById("qshow"+class_id).value = 0;
		}
	},
	add_class_question: function(class_id,user_id){
		var question = Adelphus.trim($("#classquestion"+class_id).val());
		if(question.length == 0 || question == null){
			alert("Please Enter the Question");
			return false;
		}else{
			$.post(siteUrl+"mod/stores/myaccount_action.php",{
				question: question,
				flag: "CLASS",
				userid: user_id,
				classid: class_id,
				action: "add:class:question"
			},function (data){
		     	if(data == "SUCCESS"){
		     		$("#qtable"+class_id).hide();
		     		$("#class_question_result"+class_id).html("&nbsp; Your Question has been successfully sent. &nbsp;<br>");
		     		$("#class_question_result"+class_id).css({color: "green", background: "#EFF5FB", border:"1px solid #8DB2E3", padding:"3px"});
		     		document.getElementById("classquestion"+class_id).value = "";
		     	}else{
		     		alert(data);
		     	}
		     });
		}
	},
	show_hide_recent_question: function(class_id){
		var rqshow = $("#rqshow"+class_id).val();
		var qshow = $("#qshow"+class_id).val();
		var oneshow = $("#rqshowone"+class_id).val();
		
		var class_question_div = document.getElementById("class_question_div"+class_id);
		//var rateownerdiv = document.getElementById("rateowner"+order_id+product_id);
		if(qshow == 1){
			$("#class_question_div"+class_id).slideUp("slow");
			document.getElementById("qshow"+class_id).value = 0;
		}
		
		if(rqshow == 0){
			if(oneshow == 0){
				Adelphus.display_recent_questions(class_id,1);
				document.getElementById("rqshowone"+class_id).value = 1;
			}
			$("#class_recent_question_div"+class_id).slideDown("slow");
			document.getElementById("rqshow"+class_id).value = 1;
		}else{
			$("#class_recent_question_div"+class_id).slideUp("slow");
			document.getElementById("rqshow"+class_id).value = 0;
		}
	},
	display_recent_questions: function(class_id, pageit){
		$.post(siteUrl+"mod/stores/recent_questions.php",{
			classid: class_id,
			pageit: pageit
		},function (data){
     		$("#class_recent_question_subdiv"+class_id).html(data);
     	});
	},
	show_hide_answer_div: function(question_id){
		var show = $("#answershow"+question_id).val();
		if(show == 0){
			$("#answerquest"+question_id).slideDown("slow");
			document.getElementById("answershow"+question_id).value = 1;
		}else{
			$("#answerquest"+question_id).slideUp("slow");
			document.getElementById("answershow"+question_id).value = 0;
		}
	},
	add_class_answer: function(class_id,question_id,pageit){
		var answer = Adelphus.trim($("#classanswer"+question_id).val());
		if(answer.length == 0 || answer == null){
			alert("Please Enter Answer");
			return false;
		}else{
			$.post(siteUrl+"mod/stores/myaccount_action.php",{
				answer: answer,
				questionid: question_id,
				action: "add:class:answer"
			},function (data){
		     	if(data == "SUCCESS"){
		     		Adelphus.display_recent_questions(class_id,pageit);
		     	}else{
		     		alert(data);
		     	}
		     });
		}
	},
	//----------------------- Pagination for hot music -----------//
	filter_hotmusic: function(pageit){
		$("#hotmusic_main_div").load(siteUrl+"mod/stores/hot_music.php",{
			reload:1,
			pageit: pageit
		});
	},
	//----------------------- Pagination for recent music -----------//
	filter_recentmusic: function(pageit){
		$("#recentmusic_main_div").load(siteUrl+"mod/stores/recent_music.php",{
			reload:1,
			pageit: pageit
		});
	},
	//----------------------- Display rating div on mouse over -----------//
	display_user_rating_side: function(owner){
		var showval = $("#show_user_rate").val();
		if(showval == 0){
			$("#show_user_rate").val(1);
			$.post(siteUrl + "mod/stores/myaccount_action.php",{
				action: "profile:rating:display",
				psgeowner: owner
			},function (data){
				$("#rating_contents").html(data);
				$("#display_user_rating").fadeIn("slow");
			});
		}
	},
	//----------------------- Hide rating div on mouse over -----------//
	hide_user_rating_side: function(){
		$("#display_user_rating").fadeOut("slow");
		$("#show_user_rate").val(0);
	},
	//------------------ Display Rating comments in profile page when click in the page link -----------//
	display_more_rating_comments: function(pageowner,page){
		$.post(siteUrl + "mod/stores/rating_comments.php",{
			powner: pageowner,
			pageit: page
		},function (data){
			$("#rating_comment_main_div").html(data);
		});
	},
	//----------------------- Page link for search stores -----------//
	filter_search_stores: function(pageit){
		$("#search_stores_main_div").load(siteUrl+"mod/stores/function_search_pagelink.php",{
			reload:1,
			spage_returned_items:$("#spage_returned_items").val(),
			sparameter0:$("#sparameter0").val(),
			sparameter1:$("#sparameter1").val(),
			spowner:$("#spowner").val(),
			spage_search_type_unformatted:$("#spage_search_type_unformatted").val(),
			spage_search_type:$("#spage_search_type").val(),
			stores_pageit: pageit
		});
	},
	//----------------------- Page link for search reader -----------//
	filter_search_reader: function(pageit){
		$("#search_reader_main_div").load(siteUrl+"mod/reader/function_search_pagelink.php",{
			reload:1,
			rpage_returned_items:$("#rpage_returned_items").val(),
			rparameter0:$("#rparameter0").val(),
			rparameter1:$("#rparameter1").val(),
			rpowner:$("#rpowner").val(),
			rpage_search_type_unformatted:$("#rpage_search_type_unformatted").val(),
			rpage_search_type:$("#rpage_search_type").val(),
			reader_pageit: pageit
		});
	},
	//----------------------- Page link for search Conversation -----------//
	filter_search_conversations: function(pageit){
		$("#search_conversations_main_div").load(siteUrl+"mod/conversations/function_search_pagelink.php",{
			coeload:1,
			copage_returned_items:$("#copage_returned_items").val(),
			coparameter0:$("#coparameter0").val(),
			coparameter1:$("#coparameter1").val(),
			copowner:$("#rpowner").val(),
			copage_search_type_unformatted:$("#copage_search_type_unformatted").val(),
			copage_search_type:$("#copage_search_type").val(),
			concer_pageit: pageit
		});
	},
	error_reporting: function(){
		window.open(userUrl+"errorreporting","ereport_window",
					"width=430,height=505,menubar=no,toolbar=no,resizable=0,titlebar = 0,status = 0,top = 100,left = 300");
	},
	//-------------- the time of submit the Email This Page --------// 
	send_errorreporting: function(){
		var name = $("#reporter_name").val();
		var email = $("#reporter_email").val();
		var subject = $("#reporter_subject").val();
		var message = $("#reporter_message").val();
		
		if(name.length == 0){
			alert("Please Enter your Name");
			/*document.getElementById("reporter_name").focus();*/
			return false;
		}
		if (Adelphus.IsEmail(email)){
			alert("Invalid E-mail Address! Please re-enter.");
			/*document.getElementById("reporter_email").focus();*/
			return false;
		}
		if (subject.length == 0){
			alert("Please enter Subject.");
			/*document.getElementById("reporter_subject").focus();*/
			return false;
		}
		if (message.length == 0){
			alert("Please enter Message.");
			/*document.getElementById("reporter_message").focus();*/
			return false;
		}
	},
	//-------------- Registration form validation and form submition --------// 
	regform_validation: function(){
		var name = $("#join_name");
		var username = $("#join_username");
		var password1 = $("#join_password1");
		var password2 = $("#join_password2");
		var email = $("#join_email");
		var account_type = $("#businessorindividual");
		var cname = $("#join_cname");
		var clocation = $("#join_clocation");
		var industry = $("#industry");
		var band_name = $("#join_bandname");
		var genre = $("#join_genre");
		var over13 = $("#over13checkbox");
		if(over13.attr('checked')){
			over13 = 1;
		}else{
			over13 = 0;	
		}
		$.post(siteUrl + "units/invite/invite_ajax_actions.php",{
			action: "invite_validation",
			name: name.val(),
			username: username.val(),
			password1: password1.val(),
			password2: password2.val(),
			email: email.val(),
			account_type: account_type.val(),
			cname: cname.val(),
			clocation: clocation.val(),
			industry: industry.val(),
			band_name: band_name.val(),
			genre: genre.val(),
			over13: over13
		},function (data){
			if(data.length == 0){
				document.adelphus_registration.submit();
			}else{
				$("#reg_error_display").html(data);
			}
		});
	},
	show_error_fields: function(field,test_res){
		if(test_res == 0){
			$('#errormsg_'+field).show();
			$('#error_'+field).show();
		}else{
			$('#errormsg_'+field).hide();
			$('#error_'+field).hide();
			$("#errormsg_"+field).html("");
		}
	},
	//-------------- Registration form's one by one field validation --------// 
	validate_reg_fields: function(field){
		var val_result;
		var test_res = 1;
		intfield = parseInt(field);
		switch(intfield){
			case 1:
				val_result = Adelphus.trim($("#join_name").val());
				test_res = val_result.length;
				$("#errormsg_"+field).html("<div class='styout_dump'>Enter Your Name</div>");
				Adelphus.show_error_fields(field,test_res);
				break;
			case 2:
				val_result = Adelphus.trim($("#join_username").val());
				if(val_result.length != 0){
					$.post(siteUrl + "units/invite/invite_ajax_actions.php",{
						action: "test_username",
						username: val_result,
					},function (data){
						if(data.length != 0){
							test_res = 0;
							$("#errormsg_"+field).html("<div class='styout_dump'>" + data + "</div>");
							Adelphus.show_error_fields(field,test_res);
						}else{
							test_res = val_result.length
							Adelphus.show_error_fields(field,test_res);
						}
					});
				}else{
					test_res = 0;
					$("#errormsg_"+field).html("<div class='styout_dump'>Enter Username</div>");
					Adelphus.show_error_fields(field,test_res);
				}
				break;
			case 3:
				val_result = Adelphus.trim($("#join_password1").val());
				if(val_result.length != 0){
					$.post(siteUrl + "units/invite/invite_ajax_actions.php",{
						action: "test_password1",
						password1: val_result,
					},function (data){
						if(data.length != 0){
							test_res = 0;
							$("#errormsg_"+field).html("<div class='styout_dump'>" + data + "</div>");
							Adelphus.show_error_fields(field,test_res);
						}else{
							test_res = val_result.length;
							Adelphus.show_error_fields(field,test_res);
						}
					});
				}else{
					test_res = 0;
					$("#errormsg_"+field).html("<div class='styout_dump'>Enter Password</div>");
					Adelphus.show_error_fields(field,test_res);
				}
				break;
			case 4:
				var pass1 = Adelphus.trim($("#join_password1").val());
				var pass2 = Adelphus.trim($("#join_password2").val());
				if(pass1 != pass2){
					test_res = 0;
					$("#errormsg_"+field).html("<div class='styout_dump'>Invalid password. Your passwords does not match</div>");
					Adelphus.show_error_fields(field,test_res);
				}else{
					test_res = 1;
					Adelphus.show_error_fields(field,test_res);
				}
				break;
			case 5:
				val_result = Adelphus.trim($("#join_email").val());
				if (Adelphus.IsEmail(val_result)){
					test_res = 0;
					$("#errormsg_"+field).html("<div class='styout_dump'>Invalid E-mail Address! Please re-enter.");
					Adelphus.show_error_fields(field,test_res);
				}else{
					$.post(siteUrl + "units/invite/invite_ajax_actions.php",{
						action: "test_email",
						email: val_result,
					},function (data){
						if(data.length != 0){
							test_res = 0;
							$("#errormsg_"+field).html("<div class='styout_dump'>" + data + "</div>");
							Adelphus.show_error_fields(field,test_res);
						}else{
							test_res = val_result.length;
							Adelphus.show_error_fields(field,test_res);
						}
					});
				}
				break;
			case 6:
				val_result = Adelphus.trim($("#businessorindividual").val());
				test_res = val_result;
				$("#errormsg_"+field).html("<div class='styout_dump'>You must indicate whether this is an individual or business or artist account.</div>");
				Adelphus.show_error_fields(field,test_res);
				break;
		}
	},
	//-------------- Login form validation and form submition --------// 
	homepage_login: function(){
		var username = $("#username");
		var password = $("#password");
		$.post(siteUrl + "units/invite/invite_ajax_actions.php",{
			action: "login_validation",
			username: username.val(),
			password: password.val()
		},function (data){
                        var ifliveensure = data.split('^^^^');
                        var liveensureauth = false;
                        liveensureauthAct = false;
                        //alert
                        if(ifliveensure[0] == 'liveensure'){
                            var liveensureSessUrl= ifliveensure[1];
                            liveensureauthAct = true;
                            //$('#liveensure_div').show();
                            $('#liveensure_div').show();
                            $('#liveensure_iframe').attr('src',liveensureSessUrl);
                            $('#liveensure_link').attr('href',liveensureSessUrl);

                                //loadLightBoxLiveEnsure();
                             $('#liveensure_div').lightbox_me({
                                centered: true,
                                appearEffect: "fadeIn",
                                closeSelector: ".close"
                             });

                        }

                        else if(data.length == 0){
				document.homepage_login.submit();
			}else{
				$("#homepage_error_display_div").html(data);
				$("#homepage_main_errors").fadeIn("slow");
				var t = setTimeout("$('#homepage_main_errors').fadeOut('slow')",5000);
				password.val("");
			}
		});
	},
	//-------------- Display the login fields --------// 
	show_homepage_login: function(){
		$('#homepage_main_errors').fadeOut('slow');
		$("#password").val("");
	}
};
    
function submitForm(){

}