var imagepath = "../../Content/";
var serverpath = "/Service";
var downloadpath = "/Service/Download";
var downloadhost = "http://" + document.domain.replace("developer", "download");
var devpath = "http://" + document.domain;
var userpicpath = "../../Content/temp/userpic";
//var pagename = jQuery.url.param("pageid");
var pagename = $("#pageid").attr("innerHTML");
var areacode = "en"; 	//get from ip
var area = 1;
var nav="free";
var confirm = false;
var homeurl = document.domain;


function init() {
    checkPage();
    checkArea();
    checkSession();
	if (typeof (HTTP_LOGIN_SOURCE_URL) == "boolean" && HTTP_LOGIN_SOURCE_URL == true) {
		openEULATools();
    }
}

function browsercheck() {
    if ($.browser.msie) {
        if ($.browser.version == "6.0" || $.browser.version == "7.0") alert(" In order to provide a better experience for our users, Internet Explorer 6 and 7 are no longer supported. Please use a more recent browser, such as Internet Explorer 8, Firefox, Safari, or Chrome to best experience Insyde Market.");
    }
}

function checkPage() {
    pagename = $("#pageid").attr("innerHTML");
    var pagelist = ["DVHMEN", "DVNWS", "DVBLG", "DVABU", "DVSTS", "DVPLYPV", "DVLGOT", "DVDAC", "DVMPF", "DVMCOHT", "DVMAPFO", "DVCPWS", "DVCUS", "DVFAQ", "DVUPMAP", "DVUPMAP2", "DVMAPFOSUM","DVAPSD", "DVTOLS", "DVFPWS", "DVJONS3E", "DVJONS5", "DVJONS5E", "DVJONSUSE", "DVJONREE", "DVLGIN", "DVIMDP", "DVTRM", "DVPMSRC", "ENCTPC", "ENDMCA","DVLGIN"];
    if (jQuery.inArray(pagename, pagelist) == -1) {
        $("body").attr("innerHTML", "");
        alert("This funcion is not currently opened, if you have any problem, please contact the system administrator, thank you!");
        window.history.back();
    }
}

function checkArea() {
    $.ajax({
        url: serverpath+'/checkArea',
        type: "POST",
        data: ({
            action: "checkArea",
            areacode: areacode
        }),
        datatype: "JSON",
        success: function (data) {
            area = data.result;
        }
    });
}

function checkSession() {
    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        data: ({
            act: "iniSession"
        }),
        success: function (data) {

            var denypage = ["DVDAC", "DVMPF", "DVMCOHT", "DVMAPFO", "DVCPWS", "DVUPMAP", "DVUPMAP2", "DVTOLS", "DVMAPFOSUM","DVAPSD"];

            if (data == "guest" && jQuery.inArray(pagename, denypage) != -1) {
                $("body").attr("innerHTML", "");
                openLoginDialog();
                return;
            }

            if (data != "guest") $("#devHome_mac").css("display", "inline");

            $.ajax({
                url: serverpath + '/checkSession',
                type: "POST",
                data: ({
                    action: "checkSession",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    $.ajax({
                        url: "/Handle/checkSession",
                        type: "POST",
                        data: ({
                            act: "checkSession"
                        }),
                        success: function (data) {
                           // alert(data);
                           // alert(pagename);
                            $("#logDiv").attr("innerHTML", data);
                            templateGen(pagename);
                        }
                    });
                }
            });
        }
    });
}

//load template required pages

function templateGen(pagename) {
    //var template = jQuery.url.attr("file").split('.')[0].toLowerCase();
    //alert(pagename);
    switch (pagename) {
	case "devhp":
	case "DVHMEN":
	case "DVFPWS":
	case "DVJONREE":
	case "DVJONS3E":
    case "DVCUS":
    case "DVLGIN":
        getResource(pagename, area);
        break;
    case "devbk":
    case "DVTRM":
    case "DVPMSRC":
    case "DVPLYPV":
    case "DVSTS":
    case "ENCTPC":
    case "ENDMCA":
    case "DVIMDP":
    case "DVLGOT":
    case "DVBLG":
    case "DVNWS":
    case "DVABU":
        $.get("../../Content/form/" + pagename + ".html", function (data) {
            $("#mainContent").attr("innerHTML", data);
            getResource(pagename, area);
        });
        break;
    case "DVDAC":
        $.get("/Content/" + pagename, function (data) {
            $("#mainContent").attr("innerHTML", data);
            getResource(pagename, area);
        });
        break;
    case "devac":
    case "DVFAQ":
    case "DVTOLS":
    case "DVMPF":
    case "DVMAPFO":
    case "DVMAPFOSUM":
    case "DVAPSD":
    case "DVUPMAP":
    case "DVUPMAP2":
    case "DVMCOHT":
    case "DVIMDP":
    case "DVANLT":
    //case "DVCUS":
    case "DVCPWS":
        $.get("../../Content/form/" + pagename + ".html", function (data) {
			$("#mainContent").attr("innerHTML", data);
            getResource(pagename, area);
        });
        break;
    case "DVJONSUSE":
    case "DVJONS5":
        $.get("../../Content/form/" + pagename + ".html", function (data) {
            $("#mainContent").attr("innerHTML", data);
            getResource(pagename, area);
        });
        break;
    }
}

function getResource(pagename, area) {
    
    if(pagename=="DVUPMAP2"){
        pagename = "DVUPMAP";
    }

//    if (pagename == "DVMAPFOSUM") {
//        pagename = "DVMAPFO";
//    }


    $.ajax({
        url: serverpath+'/getResource',
        type: "POST",
        data: ({
            action: "getResource",
            pagename: pagename,
            area: area
        }),
        datatype: "JSON",
        success: function (data) {
			if (typeof JSON === "object" && JSON.parse ) {
				//alert('JSON parser loaded!');
			}
            if (data.status == "success") {
				var jsonobj = (data.result);

                //apply common resources
                for (key in jsonobj) {
                    switch (jsonobj[key].Resource_id) {
                    case "devHomeImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "devHomeHref":
                        $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                        break;
                    case "acTxt":
                        $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                        break;
                    case "logHref":
						$("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                        break;
                    case "signdevImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "logoImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "supportImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "blogImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "newsImg":
                        $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                        break;
                    case "devblogurl":
                        //$("#" + jsonobj[key].Resource_id).attr("href", jsonobj[key].Link);
                        $("#" + jsonobj[key].Resource_id).attr("href", "javascript:blog('"+jsonobj[key].Link+"')");
                        break;
                    case "devnewsurl":
                        $("#" + jsonobj[key].Resource_id).attr("href", jsonobj[key].Link);
                        $("#" + jsonobj[key].Resource_id).attr("href", "javascript:news('"+jsonobj[key].Link+"')");
                        break;
                    case "pathAreaSet":
                        $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                        break;
                    case "category":
                        $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                        break;
                    case "footerLinks":
                        var links = jsonobj[key].Link.split(',');
                        var footerHtml = "<a href=\"http://"+homeurl+"/Support/Faq\" class=\"footer_link\">" + links[0] + "</a> | ";
                        footerHtml += "<a href=\"http://" + homeurl + "/Home/AboutUs\" class=\"footer_link\">" + links[1] + "</a> | ";
                        footerHtml += "<a href=\"http://" + homeurl + "/Support/ContactUs\" class=\"footer_link\">" + links[2] + "</a>";
                        $("#" + jsonobj[key].Resource_id).append(footerHtml);
                        break;
                    case "socialicon":
                        var obj = JSON.parse(jsonobj[key].Link);
                        var socialHtml = "";
                        for (i in obj) {
                            socialHtml += "<img src=\"../../Content/" + obj[i].icon + "\" onClick=\"javascript:window.open('" + obj[i].link + "','_blank');\" alt=\"\" border=\"0\" width=\"15\" hspace=\"2\" height=\"16\" valign=\"top\" style=\"cursor:pointer;\" align=\"absmiddle\"/>";
                        }
                        $("#" + jsonobj[key].Resource_id).append(socialHtml);
                        break;
                    }
                }
                placingResources(jsonobj);

                //list resources
/*
        var string = "";
        $('body').append("Get Resource<br>status : success load <br>");
        for (key in jsonobj)
        string = string + ("position:" + jsonobj[key].Resource_id) + "====" + "link:" + (jsonobj[key].Link) + "<br>";
        $('body').append(string);
        */
            }
        }
    });
}

function placingResources(jsonobj) {
    switch (pagename) {
        //Home     
    case "DVHMEN":
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "homeBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link + "?" + guid());
                break;
            case "hLeftTopDiv":
                $.get(jsonobj[key].Link, function (data) {
                    $("#hLeftTopDiv").attr("innerHTML", data);
                });
                break;
            case "hLeftBaseDiv":
                $.get(jsonobj[key].Link, function (data) {
                    $("#hLeftBaseDiv").attr("innerHTML", data);
                });
                break;
            case "hRightDiv":
                $.get(jsonobj[key].Link, function (data) {
                    $("#hRightDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        $.ajax({
            url: "/Handle/iniSession",
            type: "POST",
            data: ({
                act: "iniSession"
            }),
            success: function (data) {
                if (data != "guest") $("#home_banner_href").attr("href", "/Developer/Index");
            }
        });
      //  playInvitation();
        browsercheck();

        break;
        //News    
    case "DVNWS":
        document.title = "NEWS | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "newsdevDiv":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        break;
        //Blog    
    case "DVBLG":
        document.title = "BLOG | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "blogdevDiv":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        break;
        //About Insyde Market    
    case "DVABU":
        document.title = "About Insyde Market | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "AboutDiv":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "AboutImg":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        break;
        //Site Terms of Service    
    case "DVSTS":
        document.title = "Developer Agreement | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "SitetermContentDivdev":
                $.get("../../"+jsonobj[key].Link, function (data) {
                    $("#SitetermContentDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        break;
        //Privacy Policy    
    case "DVPLYPV":
        document.title = "Privacy Policy | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "PrivacyContentDiv":
//                $.get("../../"+jsonobj[key].Link, function (data) {
//                    $("#PrivacyContentDiv").attr("innerHTML", data);
//                });
                $.get("/Eula/PrivacyPolicy", function (data) {
                    $("#PrivacyContentDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        break;
        //Logout    
    case "DVLGOT":
        document.title = "Logout | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "logoutImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            }
        }
        break;
        //Developer Account Center    
    case "DVDAC":
        document.title = "Developer Account Center | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "myAccImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "AnalyImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "uploadImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "checkoutImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "visitInsydeImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "portfolioImg":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            }
        }
        
        if(jQuery.url.param("s")!==undefined){
				$.ajax({
            url: "/Handle/iniSession",
            type: "POST",
            async: false,
            data: ({
                act: "iniSession"
            }),
            success: function (data) {
            	if(data!=decodeURIComponent(jQuery.url.param("s"))){
            		alert("You are currently logged into another account with Insyde Market. Please logout of that account first before proceeding!");
            	}
            }
        });
				}
        
        $.ajax({
            url: "/Handle/iniSession",
            type: "POST",
            data: ({
                act: "iniSession"
            }),
            success: function (data) {

                $.ajax({
                    url: serverpath+'/getUserProfileByUserName',
                    type: "POST",
                    data: ({
                        action: "getUserProfileByUserName",
                        username: data
                    }),
                    datatype: "JSON",
                    success: function (data) {
                        if (data.status == "success") {
                            var jsonobj = data.result;

                            if (jsonobj[0].ddegree == 0) {
                                $("body").attr("innerHTML", "");
                                alert("You are not a developer, please register as a developer!");
                                window.location = "http://"+homeurl+"/Developer/SignUp?email=" +  encodeURIComponent(jsonobj[0].user_name);
                            }

                            if (jsonobj[0].mdegree != null && jsonobj[0].mdegree != 0) 
                            	$("#switchMemBtn").css("display", "inline");
                            else {                            		
                                $("#resMemBtn").parent().attr("href", $("#resMemBtn").parent().attr("href") + "?email=" +  encodeURIComponent(jsonobj[0].user_name));
                                $("#resMemBtn").css("display", "inline");
                            }
                            
                            $("#switchMemBtn").parent().attr("href", $("#switchMemBtn").parent().attr("href") + "?s=" +  encodeURIComponent(jsonobj[0].user_name));
                        }
                    }
                });
            }
        });
        break;
        //My Profile
    case "DVMPF":
        //document.title = "Developer Profile | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
                case "submitdevBtn":
                    $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                    break;
                case "requiredTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "pictureTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "picLtdTxt":
                    $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                    $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                    break;
                case "emailTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "pwdTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "chgPwdTxt":
                    $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                    break;
                case "level2Txtdev":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "fnameTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "lnameTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "phoneNoTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "phoneExTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "addrTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "postcodeTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "countryTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "timeTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "langTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "notify1":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "notify2":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "rightMenuLinks":
                    $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                    break;
                case "rightTitleAC":
                    $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                    break;
            }
        }

//        $.getJSON("../../Content/country/en.txt", function (data) {
//            $.each(data, function (key, value) {
//                $("#profile_country").append("<option value=\"" + key + "\" item=\"" + value + "\">" + key + "</option>");
//            });
//        });

        $.ajax({
            url: serverpath + '/getCountry',
            type: "POST",
            data: ({
                action: "getCountry"
            }),
            datatype: "JSON",
            success: function (data) {
                var option = "";
                $.each(data.data, function (key, value) {
                    option += "<option value=\"" + value.Id + "\" item=\"" + value.Id + "\">" + value.Name + "</option>";
                });
                $("#profile_country").html($("#profile_country").html() + option);
                getMemberProfile();
            }
        });


        $.getJSON("../../Content/language/en.txt", function (data) {
            $.each(data, function (key, value) {
                $("#profile_lang").append("<option value=\"" + key + "\">" + value + "</option>");
            });
        });

       DVMPF();

        break;
        //My Checkout History    
    case "DVMCOHT":
        document.title = "Checkout History | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "rightMenuLinks":
                $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitleAC":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            case "explortTxt":
                $("#export_history").val(jsonobj[key].Link);
                break;
            }
        }
        DVMCOHT();
        getCheckoutHistory();
        break;
        //My Application Portfolio    
    case "DVMAPFO":
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "rightMenuLinks":
                $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitleAC":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            case "apptable":
                $("#apptable").attr("innerHTML", jsonobj[key].Link);
                break;
            case "softtable":
                $("#softtable").attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        DVMAPFO();
        getCategory();
        getMyAppInfo();
        getMySoftInfo();
        break;
    case "DVMAPFOSUM":
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
                case "rightMenuLinks":
                    $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                    break;
                case "rightTitleAC":
                    $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                    break;
                case "appStatistics":
                    $("#"+jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "Updatehistory":
                    $("#"+jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
            }
        }
        $("#pathAreaSet").html('<a href="/">Home</a> > <a href="/Developer/Index">Account Center</a> > <a href="/Developer/MyAppsPortfolio">My Apps</a> > My Application Summary');
//        $("#category").html('Apps portfolio Summary');
//        $("#AppStatistic").html('App statistic');
//        $("#Updatehistory").html('Update history');
        getAppStats();
        getAppUpdateHistory();
        break;
    case "DVAPSD":
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
                case "rightMenuLinks":
                    $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                    break;
                case "rightTitleAC":
                    $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                    break;
                case "appReviewDetail":
                    $("#"+jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
            }
        }
       // alert(jQuery.url.param("app"));
        $("#pathAreaSet").html('<a href="/">Home</a> > <a href="/Developer/Index">Account Center</a> > <a href="/Developer/MyAppsPortfolio">My Apps</a> > <a href="/Developer/MyApplicationSummary?app='+jQuery.url.param("app")+'">My Application Summary</a> > App statistic detail');
      //  $("#category").html('App statistic');
      //  $("#AppStatistic").html('App Review Detail');
        getReviews();
        break;    //Change Password     
    case "DVCPWS":
        document.title = "Change password | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "submitdevBtn":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "newPwdTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "cfNewPwdTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "pwdLtdTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "rightMenuLinks":
                $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitleAC":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        DVCPWS();
        break;
        //Contact Us    
    case "DVCUS":
        document.title = "Contact Us | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "contactTitle":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "requiredTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "nameTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "emailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "subjectTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "catTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "catOption":
                var str = jsonobj[key].Link.split(',');
                for (s in str)
                $("#" + jsonobj[key].Resource_id).append("<option value=\"" + (parseInt(str[s].split(':')[0]) + 1) + "\">" + str[s].split(':')[1] + "</option>");
                break;
            case "mstTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "codeTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "fillTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "diffTxt":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            case "submitBtn":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            case "rightdevLinksSUP":
                $("#rightMenuLinks").append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitle":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        DVCUS();
        break;
        //FAQ    
    case "DVFAQ":
        document.title = "FAQ | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "rightdevLinksSUP":
                $("#rightMenuLinks").append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "faqDes":
                $("#faqDes").attr("innerHTML", jsonobj[key].Link);
                break;
            case "rightTitle":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        var now = new Date();
        getSupportFiles(getTimestamp(now));
        break;
        //Upload My Applications    
    case "DVUPMAP":
        document.title = "Upload Application | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "uploadTitle":
            case "uploadTitle1":
            case "uploadTitle2":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "requiredTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "uploadprgTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "prgLtdTxt":
                $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                break;
            case "previewTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "iconLtdTxt":
                $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                break;
            case "scnshotLtdTxt":
                $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                break;
            case "scnshot1Txt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "scnshot2Txt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "scnshot3Txt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "scnshot4Txt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "scnshot5Txt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "langTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "prgTitle":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "desTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "catTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "priceTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "webTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "emailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "agreeprgTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "submitdevBtn":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "rightMenuLinks":
                $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitleAC":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }

        $.getJSON("../../Content/language/en.txt", function (data) {
            $.each(data, function (key, value) {
                $("#prg_lang").append("<option value=\"" + key + "\">" + value + "</option>");
            });
        });

        getCategory();
        getPrice();
      //  getRegion();
        if ($("#uploadError").attr("innerHTML") == "" || $("#uploadError").attr("innerHTML") == undefined)	
		{
			DVUPMAP();
			getEditApp();
		}
        break;
    //Tools
    case "DVUPMAP2":
        document.title = "Upload Application Step2 | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
                case "uploadTitle":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "requiredTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "uploadprgTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "prgLtdTxt":
                    $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                    $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                    break;
                case "previewTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "iconLtdTxt":
                    $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                    $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                    break;
                case "scnshotLtdTxt":
                    $("#" + jsonobj[key].Resource_id + "0").attr("innerHTML", jsonobj[key].Link.split(',')[0]);
                    $("#" + jsonobj[key].Resource_id + "1").attr("innerHTML", jsonobj[key].Link.split(',')[1]);
                    break;
                case "scnshot1Txt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "scnshot2Txt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "scnshot3Txt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "scnshot4Txt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "scnshot5Txt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "langTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "prgTitle":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "desTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "catTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "priceTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "webTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "emailTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "agreeprgTxt":
                    $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                    break;
                case "submitdevBtn":
                    $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                    break;
                case "rightMenuLinks":
                    $("#" + jsonobj[key].Resource_id).append(parseRightLinks(jsonobj[key].Link.split(',')));
                    break;
                case "rightTitleAC":
                    $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                    break;
            }
        }
        $("#category").attr("innerHTML", "Upload My Applications");
        $("#pathAreaSet").attr("innerHTML", "Home > Account Center > Upload Apps");
        break;

    case "DVTOLS":
        document.title = "Tools | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "rightdevLinksSUP":
                $("#rightMenuLinks").append(parseRightLinks(jsonobj[key].Link.split(',')));
                break;
            case "rightTitle":
                $("#rightMenuTitle").attr("innerHTML", jsonobj[key].Link);
                break;
            case "toolsTitleTxt":
                $("#toolsTitleTxt").attr("innerHTML", jsonobj[key].Link);
                break;
            case "toolsDescTxt":
                $("#toolsDescTxt").attr("innerHTML", jsonobj[key].Link);
                break;
            case "toolsEnvTxt":
                $("#toolsEnvTxt").attr("innerHTML", "<img src=\"../../Content/images/DevEnvIcon.png\" width=\"17px\" height=\"17px\"/> " + jsonobj[key].Link);
                break;
            case "toolsAppTxt":
                $("#toolsAppTxt").attr("innerHTML", "<img src=\"../../Content/images/DevToolsIcon.png\" width=\"17px\" height=\"17px\"/> " + jsonobj[key].Link);
                break;
            case "toolsPic":
                $("#toolsPic").attr("innerHTML", "<img alt=\"\" src=\"../../Content/" + jsonobj[key].Link + "\" />");
                break;
            }
        }

        //$("#pathAreaSet").attr("innerHTML","");
        $("#category").attr("innerHTML", "&nbsp;");

        getTools();
        //getMATE();
        break;
    case "DVLGIN":
//        document.title = "Login | " + document.title;
//        $("#pathAreaSet").html('<a href="/">Home</a> > Login');
//        $("#category").html('Login');
        $("#devHomeHref").html('Developer Home');
        break;
        //Forget Password    
    case "DVFPWS":
        document.title = "Forget your password? | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "submitdevBtn":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "titleTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "emailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "codeTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "fillTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "diffTxt":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            }
        }
        DVFPWS();
       // $('#captchaImg').attr('src', '/Handle/showcaptcha?' + Math.random());
        break;
        //SignUp    
    case "DVJONS3E":
        document.title = "SignUp Developer | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "titleImg_step1":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "submitdevBtn":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "requiredTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "emailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "cfEmailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "pwdTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "pwdLimitTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "cfPwdTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "level2Txtdev":
                $("#level2Txt").attr("innerHTML", jsonobj[key].Link);
                break;
            case "fnameTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "lnameTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "chkAviTxt":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            case "limitTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "companyTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "phoneNoTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "phoneExTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "addrTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "postcodeTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "countryTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "codeTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "fillTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "diffTxt":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            case "SitetermContentSign":
				//alert(jsonobj[key].Link);
               // $("#" + jsonobj[key].Resource_id).attr("src", jsonobj[key].Link);
                break;
            case "devagreetxt":
                $("#agreeTxt").attr("innerHTML", jsonobj[key].Link);
                break;
            case "bankTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "billAccTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "webTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;

            }
        }

//        $.getJSON("../../Content/country/en.txt", function (data) {
//            $.each(data, function (key, value) {
//                $("#sign_country").append("<option value=\"" + key + "\" item=\"" + value + "\">" + key + "</option>");
//            });
//        });

        $.ajax({
            url: serverpath + '/getCountry',
            type: "POST",
            data: ({
                action: "getCountry"
            }),
            datatype: "JSON",
            success: function (data) {
                $.each(data.data, function (key, value) {
                    $("#sign_country").append("<option value=\"" + value.Id + "\" item=\"" + value.Id + "\">" + value.Name + "</option>");
                });
                DVJONS3E();
                getRegistrationProfile();
            }
        });

        if($("#signup_provider").html()!=""){
            var provider = eval('('+$("#signup_provider").html()+')');
            if(provider.firstname!=null){
                $("#sign_fname").val(provider.firstname);
            }
            if(provider.lastname!=null){
                $("#sign_lname").val(provider.lastname);
            }
            if(provider.email!=null){
                $("#sign_email").val(provider.email);
                $("#sign_email").attr("readonly", true);
                $("#sign_cfEmail").val(provider.email);
                $("#sign_cfEmail").attr("readonly", true);
//                $('#sign_email').trigger('change');
            }
       }


        break;
        //SignUp Check    
    case "DVJONS5":
        document.title = "Check your email | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "titleImg_step2":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "contentImg_step4":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "notReceiveHref":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            }
        }
        break;
        //SignUp Check (Check Email)    
    case "DVJONS5E":
        document.title = "Check your email | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "titleImg_step2":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "checkEmailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link.split('.')[0] + ".<br/>" + jsonobj[key].Link.split('.')[1] + ".");
                break;
            }
        }
        break;
        //SignUp Finish    
    case "DVJONSUSE":
        document.title = "Congratulations | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "titleImg_step3":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "contentImg_end_dev":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            }
        }
        checkUserVerification();
        break;
        //SignUp Verification Email    
    case "DVJONREE":
        document.title = "Not received verification mail | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "mainBanner":
                $("#" + jsonobj[key].Resource_id).attr("src", imagepath + jsonobj[key].Link);
                break;
            case "emailTxt":
                $("#" + jsonobj[key].Resource_id).attr("innerHTML", jsonobj[key].Link);
                break;
            case "resendBtn":
                $("#" + jsonobj[key].Resource_id).attr("value", jsonobj[key].Link);
                break;
            }
        }
        DVJONREE();
        break;
        //Insyde Market Developer Program    
    case "DVIMDP":
        document.title = "Insyde Market Developer Program | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "imdpContentDiv":
//                $.get('../../'+jsonobj[key].Link, function (data) {
//                    $("#imdpContentDiv").attr("innerHTML", data);
//                    if (window.location.toString().indexOf("#") != -1) {
//                        window.location = "#" + window.location.toString().split("#")[1];
//                    }
//                });
                $.get('/Eula/DeveloperProgram', function (data) {
                    $("#imdpContentDiv").attr("innerHTML", data);
                    if (window.location.toString().indexOf("#") != -1) {
                        window.location = "#" + window.location.toString().split("#")[1];
                    }
                });
                break;
            }
        }
        break;

        //Site terms of service   
    case "DVTRM":
        document.title = "Site terms of service | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "SitetermContentDiv":
//                $.get("../../"+jsonobj[key].Link, function (data) {
//                    $("#SitetermContentDiv").attr("innerHTML", data);
                //                });
                $.get("/Eula/TermsofService", function (data) {
                    $("#SitetermContentDiv").attr("innerHTML", data);
                });                
                break;
            }
        }
        break;
     
    // Payment source        
    case "DVPMSRC":
        document.title = "Payment source | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "paymentContentDiv":
//                $.get("../../"+jsonobj[key].Link, function (data) {
//                    $("#paymentContentDiv").attr("innerHTML", data);
//                });
                $.get("/Eula/PaymentSource", function (data) {
                    $("#paymentContentDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        break;

        // Content Policy        
    case "ENCTPC":
        document.title = "Content Policy | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "contentPolicyContentDiv":
//                $.get("../../"+jsonobj[key].Link, function (data) {
//                    $("#contentPolicyContentDiv").attr("innerHTML", data);
//                });
                $.get("/Eula/ContentPolicy", function (data) {
                    $("#contentPolicyContentDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        break;

        // DMCA Dispute Policy        
    case "ENDMCA":
        document.title = "DMCA Dispute Policy | " + document.title;
        for (key in jsonobj) {
            switch (jsonobj[key].Resource_id) {
            case "dmcaContentDiv":
//                $.get("../../"+jsonobj[key].Link, function (data) {
//                    $("#dmcaContentDiv").attr("innerHTML", data);
//                });
                $.get("/Eula/DMCADisputePolicy", function (data) {
                    $("#dmcaContentDiv").attr("innerHTML", data);
                });
                break;
            }
        }
        break;
    }
}

function parseRightLinks(rightLinks) {
    var innerHtml = "";
    for (key in rightLinks) {
        innerHtml += "<tr><td>";
        switch (rightLinks[key]) {
        case "Account Center":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"http://" + homeurl + "/Developer/Index\">" + rightLinks[key] + "</a>";
            break;
        case "My Profile":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"https://" + homeurl + "/Developer/MyProfile\">" + rightLinks[key] + "</a>";
            break;
        case "My Apps Portfolio":
        case "My Apps":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"http://" + homeurl + "/Developer/MyAppsPortfolio\">" + rightLinks[key] + "</a>";
            break;
        case "My Checkout":
        case "Checkout Record":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"http://" + homeurl + "/Developer/MyCheckout\">" + rightLinks[key] + "</a>";
            break;
        case "Upload Apps":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"http://" + homeurl + "/Developer/UploadApps\">" + rightLinks[key] + "</a>";
            break;
        case "Analytics":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"/Developer/Analytics\">" + rightLinks[key] + "</a>";
            break;
        case "FAQ":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"/Support/Faq\">" + rightLinks[key] + "</a>";
            break;
        case "Tools":
            $.ajax({
                url: "/Handle/iniSession",
                type: "POST",
                data: ({
                    act: "iniSession"
                }),
                success: function (data) {
                    if (data != "guest") $.ajax({
                        url: serverpath+'/getUserProfileByUserName',
                        type: "POST",
                        data: ({
                            action: "getUserProfileByUserName",
                            username: data
                        }),
                        datatype: "JSON",
                        async: false,
                        success: function (data) {
                            if (data.status == "success") {
                                var jsonobj = data.result;
                                if (jsonobj[0].ddegree != 0) innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"/Developer/Tools\">" + rightLinks[key] + "</a>";
                            }
                        }
                    });
                },
                async: false
            });
            break;
        case "Contact Us":
            innerHtml += "<a class=\"mainright_text\" target=\"_parent\" href=\"/Support/ContactUs\">" + rightLinks[key] + "</a>";
            break;
        }
        innerHtml += "</td></tr>";
    }
    return innerHtml;
}

function openMaintainDialog() {
    $.get("../../Content/form/maintain.html", function (data) {
        $("#boxes").remove();
        window.location = "#";
        $("body").append(data);
        $("body").css("overflow", "hidden");

        // Get the A tag
        var id = "#dialog";

        // Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        // Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        // transition effect
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo(1000, 0.8);

        // Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        // Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        // transition effect
        $(id).fadeIn(1000);

        $("#accField").val("");
        $("#passField").val("");
        $("#accField").focus();

        $(window).resize(function () {
            //Get the A tag
            var id = "#dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);
        });

    });
}

function openLoginDialog() {
    $.get("../../Content/form/login_https.html", function (data) {
        $("#boxes").remove();
        $("body").append(data);
        window.location = "#";
        $("body").css("overflow", "hidden");

        //Get the A tag
        var id = "#dialog";

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        //transition effect		
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo(1000, 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(1000);

        $("#accField").val("");
        $("#passField").val("");
        $("#accField").focus();

        $(window).resize(function () {
            //Get the A tag
            var id = "#dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);
        });
    });
}

function openSignUpDialog() {
    $.get("../../Content/form/signup_https.html", function (data) {
        $("#boxes").remove();
        $("body").append(data);
        window.location = "#";
        $("body").css("overflow", "hidden");

        //Get the A tag
        var id = "#dialog";

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        //transition effect		
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo(1000, 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(1000);

        $("#accField").val("");
        $("#passField").val("");
        $("#accField").focus();

        $(window).resize(function () {
            //Get the A tag
            var id = "#dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);
        });
    });
}

function openCheckoutDialog() {
    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession"
        }),
        success: function (data) {
            $.ajax({
                url: serverpath+'/getUserProfileByUserName',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        if (jsonobj[0].ddegree != 2) {
                            alert("Please upgrade your developer account to level 2 at My Account Profile before checkout!");
                        } else {
                            $.get("../../Content/form/check.html", function (data) {
                                window.location = "#";
                                $("body").append(data);

                                $("#form_table").css("display", "inline");
                                $("#result_form").css("display", "none");
                                $("#chk_result").attr("innerHTML", "");
                                $("#chk_send").attr("disabled",false);
                                //$("body").css("overflow", "hidden");
                                //Get the A tag
                                var id = "#download_dialog";

                                //Get the screen height and width
                                var maskHeight = $(document).height();
                                var maskWidth = $(window).width();

                                //Set height and width to mask to fill up the whole screen
                                $('#mask').css({
                                    'width': maskWidth,
                                    'height': maskHeight
                                });

                                //transition effect		
                                $('#mask').fadeIn(1000);
                                $('#mask').fadeTo(1000, 0.8);

                                //Get the window height and width
                                var winH = $(window).height();
                                var winW = $(window).width();

                                //Set the popup window to center
                                $(id).css('top', winH / 2 - $(id).height() / 2);
                                $(id).css('left', winW / 2 - $(id).width() / 2);

                                //transition effect
                                $(id).fadeIn(1000);

                                $(window).resize(function () {
                                    //Get the A tag
                                    var id = "#download_dialog";

                                    //Get the screen height and width
                                    var maskHeight = $(document).height();
                                    var maskWidth = $(window).width();

                                    //Set height and width to mask to fill up the whole screen
                                    $('#mask').css({
                                        'width': maskWidth,
                                        'height': maskHeight
                                    });

                                    //Get the window height and width
                                    var winH = $(window).height();
                                    var winW = $(window).width();

                                    //Set the popup window to center
                                    $(id).css('top', winH / 2 - $(id).height() / 2);
                                    $(id).css('left', winW / 2 - $(id).width() / 2);
                                });
                            });

                        }
                    }
                }
            });
        }
    });
}

function openPwdDialog() {
    $.get("../../Content/form/changePwd.html", function (data) {
        window.location = "#";
        $("body").append(data);
        $("body").css("overflow", "hidden");

        //Get the A tag
        var id = "#changePwd_dialog";

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        //transition effect		
        $('#mask').fadeIn(700);
        $('#mask').fadeTo(700, 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(700);

        $("#profile_pwd").val("");
        $("#new_pass").val("");
        $("#cfnew_pass").val("");
        $("#chgpwdError").attr("innerHTML", "");
        $("#change_table").css("display", "inline");
        $("#change_result_table").css("display", "none");

        $(window).resize(function () {
            //Get the A tag
            var id = "#changePwd_dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);
        });
    });
}

function openUpgradeDialog() {
    $.get("../../Content/form/upgrade.html", function (data) {
        window.location = "#";
        $("body").append(data);
        $("body").css("overflow", "hidden");

        //Get the A tag
        var id = "#upgrade_dialog";

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        //transition effect		
        $('#mask').fadeIn(700);
        $('#mask').fadeTo(700, 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(700);

        $(window).resize(function () {
            //Get the A tag
            var id = "#upgrade_dialog";

            //Get the screen height and width
            var maskHeight = $(document).height();
            var maskWidth = $(window).width();

            //Set height and width to mask to fill up the whole screen
            $('#mask').css({
                'width': maskWidth,
                'height': maskHeight
            });

            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();

            //Set the popup window to center
            $(id).css('top', winH / 2 - $(id).height() / 2);
            $(id).css('left', winW / 2 - $(id).width() / 2);
        });
    });
}

function playInvitation() {
    $.get("../../Content/form/invitation.html", function (data) {
        //window.location = "#";
        $("body").append(data);
        //$("body").css("overflow","hidden");
        //Get the A tag
        var id = "#invite_dialog";

        //Get the screen height and width
        var maskHeight = 1450;
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({
            'width': maskWidth,
            'height': maskHeight
        });

        //transition effect		
        $('#mask').fadeIn(700);
        $('#mask').fadeTo(700, 0.7);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', 40);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(700);
    });
}


function openDownloadTools(eulaid, resourceid, resourcetype, platform) {
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
		/*
            $.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
*/
                        $.ajax({
                            url: serverpath+'/queryEULASignUp',
                            type: "POST",
                            data: ({
                                action: "queryEULASignUp",
                                userid: data,//jsonobj[0].user_id,
                                eulaid: eulaid
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                if (data.result == 0) {
                                    $.get("../../Content/form/download_tools.html", function (data) {
                                        window.location = "#";
                                        $("body").append(data);
                                        $("body").css("overflow", "hidden");

                                        $("#agree_ck").attr("checked", false);
                                        $("#agreeLink").css("display", "none");

                                        //Get the A tag
                                        var id = "#dwn_tools_dialog";

                                        //Get the screen height and width
                                        var maskHeight = $(document).height();
                                        var maskWidth = $(window).width();

                                        //Set height and width to mask to fill up the whole screen
                                        $('#mask').css({
                                            'width': maskWidth,
                                            'height': maskHeight
                                        });

                                        //transition effect		
                                        $('#mask').fadeIn(700);
                                        $('#mask').fadeTo(700, 0.8);

                                        //Get the window height and width
                                        var winH = $(window).height();
                                        var winW = $(window).width();

                                        //Set the popup window to center
                                        $(id).css('top', 50);
                                        $(id).css('left', winW / 2 - $(id).width() / 2);

                                        //transition effect
                                        $(id).fadeIn(700);
										$("#agreeLink").unbind("click");
                                        $("#agreeLink").bind("click", function () {
                                            setEULASignUp(eulaid, resourceid, resourcetype, platform);
                                            //window.location.href = downloadpath + "?eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform;
                                        });
                                        //$("#agreeLink").attr("href", downloadpath + "?eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform);
                                        //$("#agreeLink").attr("href", "javascript:setEULASignUp('" + eulaid + "','" + resourceid + "','" + resourcetype + "','" + platform + "')");
                                        $(window).resize(function () {
                                            //Get the A tag
                                            var id = "#dwn_tools_dialog";

                                            //Get the screen height and width
                                            var maskHeight = $(document).height();
                                            var maskWidth = $(window).width();

                                            //Set height and width to mask to fill up the whole screen
                                            $('#mask').css({
                                                'width': maskWidth,
                                                'height': maskHeight
                                            });

                                            //Get the window height and width
                                            var winH = $(window).height();
                                            var winW = $(window).width();

                                            //Set the popup window to center
                                            $(id).css('top', 50);
                                            $(id).css('left', winW / 2 - $(id).width() / 2);
                                        });
                                    });
                                } else {
                                    setDownloadRec(eulaid, resourceid, resourcetype, platform);
                                }
                            }
                        });

                    //}
                //}
            //});
        }
    });
}

function openEULATools() {
    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession"
        }),
        success: function (data) {
            $.ajax({
                url: serverpath+'/getUserProfileByUserName',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        $.ajax({
                            url: serverpath+'/queryMemberEULA',
                            type: "POST",
                            data: ({
                                action: "queryMemberEULA",
                                userid: jsonobj[0].user_id
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                var agree = 1;
                                if (jsonobj[0].ddegree != 0) agree = data.result;
                                if (agree == 0) {
                                    $.get("form/eula.html", function (data) {
                                        window.location = "#";
                                        $("body").append(data);
                                        $("body").css("overflow", "hidden");

                                        //Get the A tag
                                        var id = "#eula_dialog";

                                        //Get the screen height and width
                                        var maskHeight = $(document).height();
                                        var maskWidth = $(window).width();

                                        //Set height and width to mask to fill up the whole screen
                                        $('#mask').css({
                                            'width': maskWidth,
                                            'height': maskHeight
                                        });

                                        //transition effect		
                                        $('#mask').fadeIn(700);
                                        $('#mask').fadeTo(700, 0.8);

                                        //Get the window height and width
                                        var winH = $(window).height();
                                        var winW = $(window).width();

                                        //Set the popup window to center
                                        $(id).css('top', 50);
                                        $(id).css('left', winW / 2 - $(id).width() / 2);

                                        //transition effect
                                        $(id).fadeIn(700);
                                        //$("#agreeLink").attr("href", "javascript:setMemberEULA()");
                                        $("#agreeLink").bind("click", function () {
                                            setMemberEULA();
                                        });

                                        $(window).resize(function () {
                                            //Get the A tag
                                            var id = "#eula_dialog";

                                            //Get the screen height and width
                                            var maskHeight = $(document).height();
                                            var maskWidth = $(window).width();

                                            //Set height and width to mask to fill up the whole screen
                                            $('#mask').css({
                                                'width': maskWidth,
                                                'height': maskHeight
                                            });

                                            //Get the window height and width
                                            var winH = $(window).height();
                                            var winW = $(window).width();

                                            //Set the popup window to center
                                            $(id).css('top', 50);
                                            $(id).css('left', winW / 2 - $(id).width() / 2);
                                        });

                                    });
                                } else {
                                    var allowpage = ["DVNWS", "DVBLG", "DVABU", "DVSTS", "DVPLYPV", "DVDAC", "DVMPF", "DVMCOHT", "DVMAPFO", "DVCPWS", "DVCUS", "DVFAQ", "DVUPMAP", "DVUPMAP2", "DVTOLS", "DVLGIN", "DVIMDP", "DVTRM", "DVPMSRC", "ENCTPC", "ENDMCA"];
                                    var accountCenter = ["DVHMEN", "DVJONS3E", "DVFPWS", "DVJONREE", "DVJONS5", "DVJONS5E", "DVJONSUSE", "DVLGOT"];


                                    if (jQuery.inArray(pagename, allowpage) == -1) {
                                        if (jQuery.inArray(pagename, accountCenter) == -1) window.location = "/Home/Index";
                                        else window.location = "/Developer/Index";
                                    } else window.location = window.location.toString().split('#')[0];
                                }
                            }
                        });

                    }

                }
            });
        }
    });
}

function setMemberEULA() {
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
			/*
			$.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
*/
                        $.ajax({
                            url: serverpath+'/setMemberEULA',
                            type: "POST",
                            data: ({
                                action: "setMemberEULA",
                                userid: data//jsonobj[0].user_id
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                if (pagename == "DVJONS3E") {

                                    $.ajax({
                                        url: "/Handle/logout",
                                        type: "POST",
                                        data: ({
                                            act: "logout"
                                        }),
                                        success: function (data) {
                                            window.location = "/Developer/RegistrationFinish?token=";
                                        }
                                    });
                                } else {
                                    var allowpage = ["DVNWS", "DVBLG", "DVABU", "DVSTS", "DVPLYPV", "DVDAC", "DVMPF", "DVMCOHT", "DVMAPFO", "DVCPWS", "DVCUS", "DVFAQ", "DVUPMAP", "DVUPMAP2", "DVTOLS", "DVLGIN", "DVIMDP", "DVTRM", "DVPMSRC", "ENCTPC", "ENDMCA"];
                                    var accountCenter = ["DVHMEN", "DVJONS3E", "DVFPWS", "DVJONREE", "DVJONS5", "DVJONS5E", "DVJONSUSE", "DVLGOT"];


                                    if (jQuery.inArray(pagename, allowpage) == -1) {
                                        if (jQuery.inArray(pagename, accountCenter) == -1) window.location = "/Home/Index";
                                        else window.location = "/Developer/Index";
                                    } else window.location = window.location.toString().split('#')[0];
                                }
                            }
                        });
                    //}
                //}
            //});
        }
    });
}

function setEULASignUp(eulaid, resourceid, resourcetype, platform) {
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
            /*
			$.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
*/
                        $.ajax({
                            url: serverpath+'/setEULASignUp',
                            type: "POST",
                            data: ({
                                action: "setEULASignUp",
                                userid: data,//jsonobj[0].user_id,
                                eulaid: eulaid
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                //getTools();
                                //getMATE();
                                setDownloadRec(eulaid, resourceid, resourcetype, platform);
                                //window.location = "DevAc.php?pageid=DVTOLS";
                            }
                        });
                    //}
                //}
            //});
        }
    });
}

function setDownloadRec(eulaid, resourceid, resourcetype, platform) {
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        cache: false,
        async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
            /*
			$.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
*/
                        $.ajax({
                            url: serverpath+'/setDownloadRec',
                            type: "POST",
                            data: ({
                                action: "setDownloadRec",
                                userid: data,//jsonobj[0].user_id,
                                resourceid: resourceid,
                                resourcetype: resourcetype
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                //$.download(downloadpath, "eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform, "get");
                                //window.open("form/dwn.html?id="+guid()+"&eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform,"_blank");
                                //$("#dwn_frame").attr("src","form/dwn.html?id="+guid()+"&eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform);
                                window.location.href = downloadpath + "?eulaid=" + eulaid + "&resourceid=" + resourceid + "&type=" + resourcetype + "&area=" + area + "&class=2&platform=" + platform;
                            }
                        });
                    //}
                //}
            //});
        }
    });
}

function login() {
    //vibrate configurations
    var conf = {
        frequency: 5000,
        spread: 7,
        duration: 600
    };

    if ($.trim($("#accField").val()).length == 0 || $.trim($("#passField").val()).length == 0) {
        $("#loginErrSpan").attr("innerHTML", "Please fill E-Mail And Password!");
        $("#loginDiv").vibrate(conf);
    } else {
        block_view("logging");
        $.ajax({
            url: serverpath+'/requestAuthentication',
            type: "POST",
            data: ({
                action: "requestAuthentication",
                username: $("#accField").val(),
                password: $("#passField").val()
            }),
            datatype: "JSON",
            success: function (data) {
                if (data.status == "success") {
                    $("#loginErrSpan").attr("innerHTML", "");
                    $("#mask, .window").fadeOut(1000);
                    openEULATools();
                    //checkSession();
                } else if (data.status == "notactive") {
                    $("#loginErrSpan").attr("innerHTML", $("#accountNotActivatedTxt").html());
                    $("#loginDiv").vibrate(conf);
                } else {
                    $("#loginErrSpan").attr("innerHTML", "Incorrect Email or Password!");
                    $("#loginDiv").vibrate(conf);
                }
                end_view("logging");
            }
        });
    }
}

function logout() {
    $.ajax({
        url: "/Handle/logout",
        type: "POST",
        data: ({
            act: "logout"
        }),
        success: function (data) {
            if (data == "success") {
                checkSession();
                window.location.href = "/Developer/Logout";
            }
        }
    });
}

function addContactRequest() {
    block_view("Processing...");
    //contact name
    if ($.trim($("#con_name").val()).length == 0) {
        $("#contactError").attr("innerHTML", "Please fill your name!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    //email name
    if ($.trim($("#con_mail").val()).length == 0) {
        $("#contactError").attr("innerHTML", "Please fill your email!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    //email format
    if (!ismail($("#con_mail").val())) {
        $("#contactError").attr("innerHTML", "Incorrect email format!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    //subject
    if ($.trim($("#con_subject").val()).length == 0) {
        $("#contactError").attr("innerHTML", "Please fill your subject!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    //message
    if ($.trim($("#con_msg").val()).length == 0) {
        $("#contactError").attr("innerHTML", "Please fill your message!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    var recaptcha_challenge_field = $("#recaptcha_challenge_field").val();
    var recaptcha_response_field = $("#recaptcha_response_field").val();

    $.ajax({
        url: "/Handle/captcha",
        type: "POST",
        data: ({
            act: "captcha",
            recaptcha_challenge_field: recaptcha_challenge_field,
            recaptcha_response_field: recaptcha_response_field
        }),
        success: function (data) {
            if (data == "success") {

                var now = new Date();
                var publish_time = getTimestamp(now);
                var asker = $("#con_name").val();
                var asker_email = $("#con_mail").val();
                var subject = $("#con_subject").val();
                var msg = $("#con_msg").val();
                var msg_type = $("#catOption").val();
                var asker_type = -1;

                $.ajax({
                    url: "/Handle/iniSession",
                    type: "POST",
                    data: ({
                        act: "iniSession"
                    }),
                    success: function (data) {
                        if (data != "guest") asker_type = 1;
                        $.ajax({
                            url: serverpath+'/addContactRequest',
                            type: "POST",
                            data: ({
                                action: "addContactRequest",
                                area: area,
                                publish_time: publish_time,
                                asker: asker,
                                asker_email: asker_email,
                                subject: subject,
                                msg: msg,
                                msg_type: msg_type,
                                asker_type: asker_type
                            }),
                            datatype: "JSON",
                            success: function (data) {
                                if (data.status == "success") {
                                    $("#contact_content").css("display", "none");
                                    $("#contactError").attr("innerHTML", "The message has been sent successfully!");
                                    window.location = "#";
                                }else{
                                    $("#contactError").attr("innerHTML", "Fail to send the message! Please try again later!");
                                    window.location = "#";
                                }
                                end_view("Processing...");
                            }
                        });
                    }
                });
            } else {
                $("#contactError").attr("innerHTML", "Incorrect confirmation code!");
                window.location = "#";
                Recaptcha.reload();
                $("#recaptcha_response_field").val("");
                $("#recaptcha_response_field").focus();
                end_view("Processing...");
                return;
            }

        }
    });
}

function getTimestamp(date) {
    return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}

function getTime(date) {
    return date.getFullYear() + "_" + (date.getMonth() + 1) + "_" + date.getDate();
}

function getSupportFiles(timestamp) {
    $.ajax({
        url: serverpath+'/getSupportFiles',
        type: "POST",
        data: ({
            action: "getSupportFiles",
            area: area,
            timestamp: timestamp
        }),
        datatype: "JSON",
        success: function (data) {
            var faqType = new Array();
            if (data.status == "success") {
                var jsonobj = (data.result);

                //get Type
                for (key in jsonobj) {
                    faqType[key] = jsonobj[key].q.split(']')[0] + "]";
                }
                faqType = unique(faqType);

                //generate Type Div
                for (key in faqType) {
                    var innerHtml = "<div id=\"" + faqType[key].replace("[", "").replace("]", "").replace(/\ /g, "") + "\">";
                    innerHtml += "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"faq_q\">";
                    innerHtml += "<tr>";
                    innerHtml += "<td valign=\"top\">";
                    innerHtml += "<img width=\"24\" height=\"24\" align=\"absbottom\" class=\"faq_image\" alt=\"\" src=\"../../Content/images/icon_q.gif\">";
                    innerHtml += "<a class=\"faq_textbig\" href=\"javascript:slideToggle('" + faqType[key].replace("[", "").replace("]", "").replace(/\ /g, "") + "S" + "',500);\">" + faqType[key] + "</a>";
                    innerHtml += "</td>";
                    innerHtml += "</tr>";
                    innerHtml += "</table>";
                    innerHtml += "</div>";
                    innerHtml += "<div id=\"" + faqType[key].replace("[", "").replace("]", "").replace(/\ /g, "") + "S" + "\" style=\"display:none;\"></div>";

                    $("#faqDiv").append(innerHtml);
                }

                //generate Question and Answer Table
                for (key in jsonobj) {
                    //Question
                    var qHtml = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"faq_q\">";
                    qHtml += "<tr>";
                    qHtml += "<td valign=\"top\" style=\"cursor:pointer;\" onclick=\"slideToggle('f" + key + "',300)\" class=\"faq_text\">";
                    qHtml += faqType[key] = jsonobj[key].q.split(']')[1].substring(1);
                    qHtml += "</td>";
                    qHtml += "<td valign=\"top\" align=\"right\">";
                    qHtml += "</td>";
                    qHtml += "</tr>";
                    qHtml += "</table>";
                    $("#" + (jsonobj[key].q.split(']')[0] + "]").replace("[", "").replace("]", "").replace(/\ /g, "") + "S").append(qHtml);

                    //Answer
                    var aHtml = "<table id=\"f" + key + "\" style=\"display:none; width:600px;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"faq_a\">";
                    aHtml += "<tr>";
                    aHtml += "<td width=\"35\" valign=\"top\">&nbsp;</td>";
                    aHtml += "<td valign=\"top\">";
                    aHtml += "<img width=\"24\" height=\"24\" class=\"faq_image\" alt=\"\" src=\"../../Content/images/icon_qa.gif\"/>";
                    aHtml += "</td>";
                    aHtml += "<td>";
                    aHtml += jsonobj[key].a;
                    aHtml += "</td>";
                    aHtml += "</tr>";
                    aHtml += "</table>";
                    $("#" + (jsonobj[key].q.split(']')[0] + "]").replace("[", "").replace("]", "").replace(/\ /g, "") + "S").append(aHtml);
                }
            }
        }
    });
}

function slideToggle(div, speed) {
    $("#" + div).slideToggle(speed);
}

function unique(arrayName) {
    var newArray = new Array();
    label: for (var i = 0; i < arrayName.length; i++) {
        for (var j = 0; j < newArray.length; j++) {
            if (newArray[j] == arrayName[i]) continue label;
        }
        newArray[newArray.length] = arrayName[i];
    }
    return newArray;
}

function checkfield(isValid) {
    if (isValid) return "<img alt=\"\" src=\"../../Content/images/correct.png\" />";
    else return "<img alt=\"\" src=\"../../Content/images/wrong.png\" />";
}

function requestPasswordReset() {


    if ($.trim($("#profile_pwd").val()).length == 0) {
        $("#chgpwdError").attr("innerHTML", "Please fill your old password!");
        return;
    }

    if ($.trim($("#new_pass").val()).length == 0) {
        $("#chgpwdError").attr("innerHTML", "Please fill your new password!");
        return;
    }

    if ($.trim($("#cfnew_pass").val()).length == 0) {
        $("#chgpwdError").attr("innerHTML", "Please confirm your new password!");
        return;
    }

    if ($.trim($("#new_pass").val()).length < 6 || $("#new_pass").val().toLowerCase().replace(/[^a-z]/g, '').length == 0 || $("#new_pass").val().replace(/[^0-9]/g, '').length == 0) {
        $("#chgpwdError").attr("innerHTML", "Incorrect password format!");
        return;
    }

    if ($("#cfnew_pass").val() != $("#new_pass").val()) {
        $("#chgpwdError").attr("innerHTML", "Confirm password incorrect!");
        return;
    }

    block_view("Loading...");
    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        data: ({
            act: "iniSession"
        }),
        async: false,
        success: function (data) {
            var useracc = data;
            $.ajax({
                url: serverpath+'/requestAuthentication',
                type: "POST",
                data: ({
                    action: "requestAuthentication",
                    username: data,
                    password: $("#profile_pwd").val()
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var password = $("#new_pass").val();
                        var reason = "forget it";

                        $.ajax({
                            url: serverpath+'/requestPasswordReset',
                            type: "POST",
                            async: false,
                            data: ({
                                action: "requestPasswordReset",
                                username: useracc,
                                password: password,
                                reason: reason
                            }),
                            datatype: "JSON",
                            success: function (data) {
                                if (data.status == "success") {
                                    $("#change_table").css("display", "none");
                                    $("#change_result_table").css("display", "block");
                                    $("#chgpwdResult").attr("innerHTML", "New password has been changed successfully!");
                                } else $("#chgpwdError").attr("innerHTML", "Can't change your new password, please try again later!");
                            }
                        });


                    } else $("#chgpwdError").attr("innerHTML", "Incorrect old password!");
                }
            });
        }
    });
    end_view("Loading...");
}

function recoveryPassword() {
    block_view("Processing...");
    if ($.trim($("#pws_email").val()).length == 0) {
        $("#pwsError").attr("innerHTML", "Please fill E-Mail Address!");
        end_view("Processing");
        window.location = "#";
        return;
    }

    var recaptcha_challenge_field = $("#recaptcha_challenge_field").val();
    var recaptcha_response_field = $("#recaptcha_response_field").val();

    $.ajax({
        url: "/Handle/captcha",
        type: "POST",
        data: ({
            act: "captcha",
            recaptcha_challenge_field: recaptcha_challenge_field,
            recaptcha_response_field: recaptcha_response_field
        }),
        async: false,
        success: function (data) {
            if (data == "success") {
                var useract = $("#pws_email").val();
                $.ajax({
                    url: serverpath+'/recoveryPassword',
                    type: "POST",
                    data: ({
                        action: "recoveryPassword",
                        username: useract
                    }),
                    datatype: "JSON",
                    success: function (data) {
                        var innerHtml = "";
                        if (data.status == "success") {
                            innerHtml = "<tr><td width=\"12%\">&nbsp;</td>";
                            innerHtml += "<td width=\"88%\" align=\"left\" class=\"login_font13\">";
                            innerHtml += "<span style=\"color:red;\">The password sent successfully!</span>";
                            innerHtml += "</td></tr>";
                        } else {
                            innerHtml = "<tr><td width=\"12%\">&nbsp;</td>";
                            innerHtml += "<td width=\"88%\" align=\"left\" class=\"login_font13\">";
                            innerHtml += "<span style=\"color:red;\">Fail to sent your password, please confirm your email and resent your password!</span><br/>";
                            innerHtml += "<a class=\"about_link\" href=\"/Developer/ForgetPassword\">Resent my password</a>";
                            innerHtml += "</td></tr>";
                        }
                        $("#pwdForm").empty();
                        $("#pwdForm").append(innerHtml);
                    }
                });

                $("#pwsError").attr("innerHTML", "");
            } else {
                $("#pwsError").attr("innerHTML", "Incorrect Confirmation Code!");
                window.location = "#";
                Recaptcha.reload();
                $("#recaptcha_response_field").val("");
                $("#recaptcha_response_field").focus();
            }

        }
    });
    end_view("Processing...");
}

function initailizeUserVerification() {
    block_view("Processing...");
    //email
    if ($.trim($("#verify_mail").val()).length == 0) {
        $("#verifyError").attr("innerHTML", "Please fill E-Mail Address!");
        window.location = "#";
        end_view("Processing...");
        return;
    }

    var recaptcha_challenge_field = $("#recaptcha_challenge_field").val();
    var recaptcha_response_field = $("#recaptcha_response_field").val();

    $.ajax({
        url: "/Handle/captcha",
        type: "POST",
        data: ({
            act: "captcha",
            recaptcha_challenge_field: recaptcha_challenge_field,
            recaptcha_response_field: recaptcha_response_field
        }),
        async: false,
        success: function (data) {
            if (data == "success") {
                $.ajax({
                    url: serverpath+'/getUserProfileByUserName',
                    type: "POST",
                    data: ({
                        action: "getUserProfileByUserName",
                        username: $("#verify_mail").val()
                    }),
                    datatype: "JSON",
                    success: function (data) {
                        if (data.status == "success") {
                            var jsonobj = data.result;
                            if (jsonobj[0].status == 2) {
                                $.ajax({
                                    url: serverpath+'/initializeUserVerification',
                                    type: "POST",
                                    data: ({
                                        action: "initializeUserVerification",
                                        area: area,
                                        userid: jsonobj[0].user_id
                                    }),
                                    datatype: "JSON",
                                    success: function (data) {
                                        if (data.status == "success") {
                                            var innerHtml = "<tr>";
                                            innerHtml += "<td width=\"88%\" align=\"left\"><span style=\"padding-left:30px;\" class=\"error_text\">The verification mail have been sent successfully!</span>";
                                            innerHtml += "</td></tr>";
                                            $("#verify_content").empty();
                                            $("#verify_content").append(innerHtml);
                                            window.location = "#";
                                        }
                                        end_view("Processing...");
                                    }
                                });
                            } else {
                                $("#verifyError").attr("innerHTML", "The email you fill has already been activated!");
                                window.location = "#";
                                end_view("Processing...");
                            }
                        } else {
                            $("#verifyError").attr("innerHTML", "The email you fill doesn't exist!");
                            window.location = "#";
                            end_view("Processing...");
                        }
                    }
                });
            } else {
                $("#verifyError").attr("innerHTML", "Incorrect confirmation code!");
                window.location = "#";
                Recaptcha.reload();
                $("#recaptcha_response_field").val("");
                $("#recaptcha_response_field").focus();
                end_view("Processing...");
            }
        }
    });
}

function registration() {
    //first name
    if ($.trim($("#sign_fname").val()).length == 0) {
        $("#signError").attr("innerHTML", "Please fill your first name!");
        window.location = "#";
        return;
    }

    //last name
    if ($.trim($("#sign_lname").val()).length == 0) {
        $("#signError").attr("innerHTML", "Please fill your last name!");
        window.location = "#";
        return;
    }

    //email
    if ($("#email_tr").css("display") != "none") {
        if ($.trim($("#sign_email").val()).length == 0 || (!ismail($("#sign_email").val()))) {
            $("#signError").attr("innerHTML", "Please fill correct E-mail!");
            window.location = "#";
            return;
        } else {
            $.ajax({
                url: serverpath + '/checkUserData',
                type: "POST",
                data: ({
                    action: "checkUserData",
                    field: "Email",
                    value: $("#sign_email").val()
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        $("#signError").attr("innerHTML", "Please fill correct E-mail!");
                        window.location = "#";
                        return;
                    }else{
                    	
    //confirm email
    if ($("#cfEmail_tr").css("display") != "none") {
        if ($("#sign_email").val() != $("#sign_cfEmail").val()) {
            $("#signError").attr("innerHTML", "Confirm E-Mail error!");
            window.location = "#";
            return;
        }
    }


    //password
    if ($("#pwd_tr").css("display") != "none") {
        if ($.trim($("#sign_pwd").val()).length < 6 || $("#sign_pwd").val().toLowerCase().replace(/[^a-z]/g, '').length == 0 || $("#sign_pwd").val().replace(/[^0-9]/g, '').length == 0) {
            $("#signError").attr("innerHTML", "Incorrect password format!");
            window.location = "#";
            return;
        }
    }

    //confirm password
    if ($("#cfPwd_tr").css("display") != "none") {
        if ($("#sign_pwd").val() != $("#sign_cfPwd").val()) {
            $("#signError").attr("innerHTML", "Confirm password error!");
            window.location = "#";
            return;
        }
    }

    //country
    if ($("#sign_country").val() == "0") {
        $("#signError").attr("innerHTML", "Please select your country!");
        window.location = "#";
        return;
    }

    //level2 checked
    if ($("#tolevel2Ck").is(":checked")) {
        //phone number
        if ($.trim($("#sign_councode").val()).length == 0 || $.trim($("#sign_areacode").val()).length == 0 || $.trim($("#sign_phone").val()).length == 0) {
            $("#signError").attr("innerHTML", "Please fill your phone number!");
            window.location = "#";
            return;
        }

        if ((!$("#sign_payment_bank").is(":checked")) && (!$("#sign_payment_paypal").is(":checked"))) {
            $("#signError").attr("innerHTML", "Please select your payment type!");
            window.location = "#";
            return;
        }

        //payment bank
        if ($("#sign_payment_bank").is(":checked")) {
            if ($.trim($("#sign_bankname").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your bank name!");
                window.location = "#";
                return;
            }

            if ($.trim($("#sign_billacc").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your bill account!");
                window.location = "#";
                return;
            }

            //SWIFT Code
            if ($("#swift_tr").css("display") == "table-row" && $.trim($("#sign_swift").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your SWIFT Code!");
                window.location = "#";
                return;
            }

            //ABA Code
            if ($("#aba_tr").css("display") == "table-row" && $.trim($("#sign_aba").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your ABA Code!");
                window.location = "#";
                return;
            }
        }

        //payment paypal
        if ($("#sign_payment_paypal").is(":checked")) {
            if ($.trim($("#sign_paypal").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your paypal ID!");
                window.location = "#";
                return;
            }
        }
    }

    var recaptcha_challenge_field = $("#recaptcha_challenge_field").val();
    var recaptcha_response_field = $("#recaptcha_response_field").val();
    $.ajax({
        url: "/Handle/captcha",
        type: "POST",
        data: ({
            act: "captcha",
            recaptcha_challenge_field: recaptcha_challenge_field,
            recaptcha_response_field: recaptcha_response_field
        }),
        success: function (data) {
            if (confirm) data = "success";
            if (data != "success") {
                $("#signError").attr("innerHTML", "Incorrect Confirmation Code!");
                window.location = "#";
                Recaptcha.reload();
                $("#recaptcha_response_field").val("");
                $("#recaptcha_response_field").focus();
                confirm = false;
                return;
            } else {
                confirm = true;
                //agree checkbox
                if (!$("#sign_agree").is(":checked")) {
                    $("#signError").attr("innerHTML", "Please check agree!");
                    window.location = "#";
                    return;
                }

                block_view("Processing...");
                //confirmation code
                var mdegree = 1;
                var ddegree = 1;
                if ($("#tolevel2Ck").is(":checked")) ddegree = 2;
                var username = $("#sign_email").val();
                var email = $("#sign_email").val();
                var password = $("#sign_pwd").val();
                var firstname = $("#sign_fname").val();
                var lastname = $("#sign_lname").val();
                var nickname = $("#sign_email").val();
                var company = $("#sign_company").val();
                var phonenumber = "";
                if ($("#tolevel2Ck").is(":checked")) phonenumber = $("#sign_councode").val() + "-" + $("#sign_areacode").val() + "-" + $("#sign_phone").val();
                if ($.trim($("#sign_councode").val()).length != 0 && $.trim($("#sign_areacode").val()).length != 0 && $.trim($("#sign_phone").val()).length != 0) phonenumber = $("#sign_councode").val() + "-" + $("#sign_areacode").val() + "-" + $("#sign_phone").val();
                var paypadid = $("#sign_paypal").val();
                var sex = "";
                var address = $("#sign_addr").val();
                var postcode = $("#sign_postcode").val();
                var country = "";
                if ($("#sign_country").val() != "0") country = $("#sign_country :selected").val();
                var picture = "";
                var timezone = "";
                //if ($("#sign_country").val() != "0") timezone = $("#sign_country :selected").attr("item");
                var website = $("#sign_website").val();
                var bankname = $("#sign_bankname").val();
                var billaccount = $("#sign_billacc").val();
                var notice1 = "";
                var notice2 = "";
                var bankaba = $("#sign_aba").val();
                var bankswift = $("#sign_swift").val();
                var payment = 0;
                if ($("#sign_payment_bank").is(":checked")) payment = 1;
                if ($("#sign_payment_paypal").is(":checked")) payment = 2;

                $.ajax({
                    url: "/Handle/iniSession",
                    type: "POST",
                    cache: false,
                    async: false,
                    data: ({
                        act: "iniSession"
                    }),
                    success: function (data) {
                        if (jQuery.url.param("email") !== undefined) {
                            $.ajax({
                                url: serverpath+'/getUserProfileByUserName',
                                type: "POST",
                                async: false,
                                data: ({
                                    action: "getUserProfileByUserName",
                                    username: decodeURIComponent(jQuery.url.param("email"))
                                }),
                                datatype: "JSON",
                                success: function (data) {
                                    var jsonobj = data.result;

                                    var userid = jsonobj[0].user_id;
                                    $.ajax({
                                        url: serverpath+'/setUserProfile',
                                        type: "POST",
                                        async: false,
                                        data: ({
                                            action: "setUserProfile",
                                            userid: userid,
                                            email: jsonobj[0].email,
                                            firstname: firstname,
                                            lastname: lastname,
                                            nickname: jsonobj[0].nick_name,
                                            company: company,
                                            phone: phonenumber,
                                            timezone: timezone,
                                            postcode: postcode,
                                            country: country,
                                            website: website,
                                            bankname: bankname,
                                            billaccount: billaccount,
                                            notice1: jsonobj[0].notice1,
                                            notice2: jsonobj[0].notice2,
                                            status: jsonobj[0].status,
                                            ddegree: ddegree,
                                            mdegree: jsonobj[0].mdegree,
                                            address: address,
                                            paypadid: jsonobj[0].paypad_id,
                                            area: jsonobj[0].area,
                                            sex: jsonobj[0].gender,
                                            picture: jsonobj[0].picture,
                                            bankaba: bankaba,
                                            bankswift: bankswift,
                                            paymenttype: payment
                                        }),
                                        datatype: "JSON",
                                        success: function (data) {
                                            if (data.status == "success") {
                                                $.ajax({
                                                    url: serverpath+'/setMemberEULA',
                                                    type: "POST",
                                                    async: false,
                                                    data: ({
                                                        action: "setMemberEULA",
                                                        userid: userid
                                                    }),
                                                    datatype: "JSON",
                                                    async: false,
                                                    success: function (data) {
                                                        $.ajax({
                                                            url: "/Handle/logout",
                                                            type: "POST",
                                                            data: ({
                                                                act: "logout"
                                                            }),
                                                            success: function (data) {
                                                                window.location = "/Developer/RegistrationFinish?token=";
                                                            }
                                                        });
                                                    }
                                                });
                                            } else {
                                                $("#profileError").attr("innerHTML", "Fail to register, please try again later!");
                                                window.location = "#";
                                            }
                                        }
                                    });
                                }
                            });
                        } else {
                            $.ajax({
                                url: serverpath+'/Registration',
                                type: "POST",
                                async: false,
                                data: ({
                                    action: "Registration",
                                    ddegree: ddegree,
                                    mdegree: mdegree,
                                    username: username,
                                    email: email,
                                    password: password,
                                    firstname: firstname,
                                    lastname: lastname,
                                    nickname: nickname,
                                    company: company,
                                    phone: phonenumber,
                                    address: address,
                                    paypadid: paypadid,
                                    sex: sex,
                                    area: area,
                                    country: country,
                                    postcode: postcode,
                                    picture: picture,
                                    timezone: timezone,
                                    website: website,
                                    bankname: bankname,
                                    billaccount: billaccount,
                                    notice1: notice1,
                                    notice2: notice2,
                                    bankaba: bankaba,
                                    bankswift: bankswift,
                                    paymenttype: payment
                                }),
                                datatype: "JSON",
                                success: function (data) {
                                    if (data.status == "success") {
                                        window.location = "/Developer/ThankYouForRegistering";
                                    }else if (data.status == "open id success") {
                                        window.location = "/Developer/RegistrationFinish";
                                    } else {
                                        $("#signError").attr("innerHTML", "Fail to register, please try again later!");
                                        window.location = "#";
                                    }
                                }
                            });
                        }
                    }
                });
                end_view("Processing...");
            }
        }
    });
                    }
                }
            });
        }
    }else{

    //country
    if ($("#sign_country").val() == "0") {
        $("#signError").attr("innerHTML", "Please select your country!");
        window.location = "#";
        return;
    }

    //level2 checked
    if ($("#tolevel2Ck").is(":checked")) {
        //phone number
        if ($.trim($("#sign_councode").val()).length == 0 || $.trim($("#sign_areacode").val()).length == 0 || $.trim($("#sign_phone").val()).length == 0) {
            $("#signError").attr("innerHTML", "Please fill your phone number!");
            window.location = "#";
            return;
        }

        if ((!$("#sign_payment_bank").is(":checked")) && (!$("#sign_payment_paypal").is(":checked"))) {
            $("#signError").attr("innerHTML", "Please select your payment type!");
            window.location = "#";
            return;
        }

        //payment bank
        if ($("#sign_payment_bank").is(":checked")) {
            if ($.trim($("#sign_bankname").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your bank name!");
                window.location = "#";
                return;
            }

            if ($.trim($("#sign_billacc").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your bill account!");
                window.location = "#";
                return;
            }

            //SWIFT Code
            if ($("#swift_tr").css("display") == "table-row" && $.trim($("#sign_swift").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your SWIFT Code!");
                window.location = "#";
                return;
            }

            //ABA Code
            if ($("#aba_tr").css("display") == "table-row" && $.trim($("#sign_aba").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your ABA Code!");
                window.location = "#";
                return;
            }
        }

        //payment paypal
        if ($("#sign_payment_paypal").is(":checked")) {
            if ($.trim($("#sign_paypal").val()).length == 0) {
                $("#signError").attr("innerHTML", "Please fill your paypal ID!");
                window.location = "#";
                return;
            }
        }
    }

    var recaptcha_challenge_field = $("#recaptcha_challenge_field").val();
    var recaptcha_response_field = $("#recaptcha_response_field").val();
    $.ajax({
        url: "/Handle/captcha",
        type: "POST",
        data: ({
            act: "captcha",
            recaptcha_challenge_field: recaptcha_challenge_field,
            recaptcha_response_field: recaptcha_response_field
        }),
        success: function (data) {
            if (confirm) data = "success";
            if (data != "success") {
                $("#signError").attr("innerHTML", "Incorrect Confirmation Code!");
                window.location = "#";
                Recaptcha.reload();
                $("#recaptcha_response_field").val("");
                $("#recaptcha_response_field").focus();
                confirm = false;
                return;
            } else {
                confirm = true;
                //agree checkbox
                if (!$("#sign_agree").is(":checked")) {
                    $("#signError").attr("innerHTML", "Please check agree!");
                    window.location = "#";
                    return;
                }

                block_view("Processing...");
                //confirmation code
                var mdegree = 1;
                var ddegree = 1;
                if ($("#tolevel2Ck").is(":checked")) ddegree = 2;
                var username = $("#sign_email").val();
                var email = $("#sign_email").val();
                var password = $("#sign_pwd").val();
                var firstname = $("#sign_fname").val();
                var lastname = $("#sign_lname").val();
                var nickname = $("#sign_email").val();
                var company = $("#sign_company").val();
                var phonenumber = "";
                if ($("#tolevel2Ck").is(":checked")) phonenumber = $("#sign_councode").val() + "-" + $("#sign_areacode").val() + "-" + $("#sign_phone").val();
                if ($.trim($("#sign_councode").val()).length != 0 && $.trim($("#sign_areacode").val()).length != 0 && $.trim($("#sign_phone").val()).length != 0) phonenumber = $("#sign_councode").val() + "-" + $("#sign_areacode").val() + "-" + $("#sign_phone").val();
                var paypadid = $("#sign_paypal").val();
                var sex = "";
                var address = $("#sign_addr").val();
                var postcode = $("#sign_postcode").val();
                var country = "";
                if ($("#sign_country").val() != "0") country = $("#sign_country :selected").val();
                var picture = "";
                var timezone = "";
                //if ($("#sign_country").val() != "0") timezone = $("#sign_country :selected").attr("item");
                var website = $("#sign_website").val();
                var bankname = $("#sign_bankname").val();
                var billaccount = $("#sign_billacc").val();
                var notice1 = "";
                var notice2 = "";
                var bankaba = $("#sign_aba").val();
                var bankswift = $("#sign_swift").val();
                var payment = 0;
                if ($("#sign_payment_bank").is(":checked")) payment = 1;
                if ($("#sign_payment_paypal").is(":checked")) payment = 2;

                $.ajax({
                    url: "/Handle/iniSession",
                    type: "POST",
                    cache: false,
                    async: false,
                    data: ({
                        act: "iniSession"
                    }),
                    success: function (data) {
                        if (jQuery.url.param("email") !== undefined) {
                            $.ajax({
                                url: serverpath+'/getUserProfileByUserName',
                                type: "POST",
                                async: false,
                                data: ({
                                    action: "getUserProfileByUserName",
                                    username: decodeURIComponent(jQuery.url.param("email"))
                                }),
                                datatype: "JSON",
                                success: function (data) {
                                    var jsonobj = data.result;

                                    var userid = jsonobj[0].user_id;
                                    $.ajax({
                                        url: serverpath+'/setUserProfile',
                                        type: "POST",
                                        async: false,
                                        data: ({
                                            action: "setUserProfile",
                                            userid: userid,
                                            email: jsonobj[0].email,
                                            firstname: firstname,
                                            lastname: lastname,
                                            nickname: jsonobj[0].nick_name,
                                            company: company,
                                            phone: phonenumber,
                                            timezone: timezone,
                                            postcode: postcode,
                                            country: country,
                                            website: website,
                                            bankname: bankname,
                                            billaccount: billaccount,
                                            notice1: jsonobj[0].notice1,
                                            notice2: jsonobj[0].notice2,
                                            status: jsonobj[0].status,
                                            ddegree: ddegree,
                                            mdegree: jsonobj[0].mdegree,
                                            address: address,
                                            paypadid: paypadid,
                                            area: jsonobj[0].area,
                                            sex: jsonobj[0].gender,
                                            picture: jsonobj[0].picture,
                                            bankaba: bankaba,
                                            bankswift: bankswift,
                                            paymenttype: payment
                                        }),
                                        datatype: "JSON",
                                        success: function (data) {
                                            if (data.status == "success") {
                                                $.ajax({
                                                    url: serverpath+'/setMemberEULA',
                                                    type: "POST",
                                                    async: false,
                                                    data: ({
                                                        action: "setMemberEULA",
                                                        userid: userid
                                                    }),
                                                    datatype: "JSON",
                                                    async: false,
                                                    success: function (data) {
                                                        $.ajax({
                                                            url: "/Handle/logout",
                                                            type: "POST",
                                                            data: ({
                                                                act: "logout"
                                                            }),
                                                            success: function (data) {
                                                                window.location = "/Developer/RegistrationFinish?token=";
                                                            }
                                                        });
                                                    }
                                                });
                                            } else {
                                                $("#profileError").attr("innerHTML", "Fail to register, please try again later!");
                                                window.location = "#";
                                            }
                                        }
                                    });
                                }
                            });
                        } else {
                            $.ajax({
                                url: serverpath+'/Registration',
                                type: "POST",
                                async: false,
                                data: ({
                                    action: "Registration",
                                    ddegree: ddegree,
                                    mdegree: mdegree,
                                    username: username,
                                    email: email,
                                    password: password,
                                    firstname: firstname,
                                    lastname: lastname,
                                    nickname: nickname,
                                    company: company,
                                    phone: phonenumber,
                                    address: address,
                                    paypadid: paypadid,
                                    sex: sex,
                                    area: area,
                                    country: country,
                                    postcode: postcode,
                                    picture: picture,
                                    timezone: timezone,
                                    website: website,
                                    bankname: bankname,
                                    billaccount: billaccount,
                                    notice1: notice1,
                                    notice2: notice2,
                                    bankaba: bankaba,
                                    bankswift: bankswift,
                                    paymenttype: payment
                                }),
                                datatype: "JSON",
                                success: function (data) {
                                    if (data.status == "success") {
                                        window.location = "/Developer/ThankYouForRegistering";
                                    } else {
                                        $("#signError").attr("innerHTML", "Fail to register, please try again later!");
                                        window.location = "#";
                                    }
                                }
                            });
                        }
                    }
                });
                end_view("Processing...");
            }
        }
    });
        }    
    
}

function checkUserData(field, value, resultSpan) {
    $.ajax({
        url: serverpath+'/checkUserData',
        type: "POST",
        data: ({
            action: "checkUserData",
            field: field,
            value: value
        }),
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") $("#" + resultSpan).attr("innerHTML", checkfield(false));
            else {
                $("#" + resultSpan).attr("innerHTML", checkfield(true));
                $("#signError").attr("innerHTML", "");
            }
        }
    });
}

function checkUserData2(field, value, resultSpan) {
    $.ajax({
        url: serverpath+'/checkUserData',
        type: "POST",
        data: ({
            action: "checkUserData",
            field: field,
            value: value
        }),
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") $("#" + resultSpan).attr("innerHTML", checkfield(true));
            else {
                $("#" + resultSpan).attr("innerHTML", checkfield(false));
                $("#signError").attr("innerHTML", "");
            }
        }
    });
}

function getMemberProfile() {
    //alert('getMemberProfile');
    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        cache: false,
        data: ({
            act: "iniSession"
        }),
        success: function (data) {
            $.ajax({
                url: serverpath + '/getUserProfileByUserName',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        if (jsonobj[0].mdegree == 2 || jsonobj[0].ddegree == 1 || jsonobj[0].ddegree == 2) {
                            $("#fname_required").attr("innerHTML", "*");
                            $("#lname_required").attr("innerHTML", "*");
                            $("#country_required").attr("innerHTML", "*");
                        }

                        if (jsonobj[0].mdegree == 2 || jsonobj[0].ddegree == 2) {
                            $("#phone_required").attr("innerHTML", "*");
                        }

                        if (jsonobj[0].ddegree != 2) {
                            $("#payment_type_tr").css("display", "none");
                            $("#website_tr").css("display", "none");
                            $("#swift_tr").css("display", "none");
                            $("#aba_tr").css("display", "none");
                        }

                        if (jsonobj[0].ddegree == 2) {
                            $("#tolevel2_tr").css("display", "none");
                        }

                        //picture
                        if (jsonobj[0].picture != "") {
                            $("#profile_img").attr("src", downloadhost + "/" + jsonobj[0].picture + "?" + guid());
                            $("#oldpicture").val(jsonobj[0].picture);
                            $("#delete_file").css("display", "inline");
                            $("#cancel_file").css("display", "none");
                        }
                        //email
                        $("#profile_email").attr("innerHTML", jsonobj[0].email);
                        //first name
                        if (jsonobj[0].first_name != "") $("#profile_fname").val(jsonobj[0].first_name);
                        //lase name
                        if (jsonobj[0].last_name != "") $("#profile_lname").val(jsonobj[0].last_name);
                        //company
                        if (jsonobj[0].company != "") $("#profile_company").val(jsonobj[0].company);
                        if (jsonobj[0].ddegree == 2) {
                            $("#payment_type_tr").css("display", "table-row");
                            if (jsonobj[0].paymenttype == 1) {
                                $("#profile_payment_bank").attr("checked", "true");
                                $("#paypal_tr").css("display", "none");
                                $("#billacc_tr").css("display", "table-row");
                                $("#bankacc_tr").css("display", "table-row");

                                //SWIFT Code and ABA code
                                if (jsonobj[0].country != "") {
                                    if (jsonobj[0].country == "USA") $("#aba_tr").css("display", "table-row");
                                    else $("#swift_tr").css("display", "table-row");
                                }
                            } else if (jsonobj[0].paymenttype == 2) {
                                $("#profile_payment_paypal").attr("checked", "true");
                                $("#paypal_tr").css("display", "table-row");
                                $("#billacc_tr").css("display", "none");
                                $("#bankacc_tr").css("display", "none");
                                $("#swift_tr").css("display", "none");
                                $("#aba_tr").css("display", "none");
                            }
                        }
                        //bill account
                        if (jsonobj[0].billaccount != "") $("#profile_billacc").val(jsonobj[0].billaccount);
                        //bank account
                        if (jsonobj[0].bankname != "") $("#profile_bankacc").val(jsonobj[0].bankname);
                        //paypal
                        if (jsonobj[0].paypad_id != "") $("#profile_paypal").val(jsonobj[0].paypad_id);
                        //SWIFT code
                        if (jsonobj[0].bankSWIFT != "") $("#profile_swift").val(jsonobj[0].bankSWIFT);
                        //ABA code
                        if (jsonobj[0].bankABA != "") $("#profile_aba").val(jsonobj[0].bankABA);
                        //phone number
                        if (jsonobj[0].phone_number != "" && jsonobj[0].phone_number != null) {
                            $("#profile_coun").val(jsonobj[0].phone_number.split('-')[0]);
                            $("#profile_area").val(jsonobj[0].phone_number.split('-')[1]);
                            $("#profile_phone").val(jsonobj[0].phone_number.split('-')[2]);
                        }
                        //website
                        if (jsonobj[0].website != "") $("#profile_website").val(jsonobj[0].website);
                        //address
                        if (jsonobj[0].address != "") $("#profile_addr").val(jsonobj[0].address);
                        //postcode
                        if (jsonobj[0].postcode != 0) $("#profile_postcode").val(jsonobj[0].postcode);
                        //country
                        if (jsonobj[0].country != "") {
                            $("#profile_country").val(jsonobj[0].country);
                            //$("#profile_country :selected").text(jsonobj[0].country);
                        }
                        //timezone
                        //if (jsonobj[0].timezone != "") $("#profile_timezone").val(jsonobj[0].timezone);
                        //language
                        if (jsonobj[0].area != "") $("#profile_lang").val(jsonobj[0].area);
                        //notice1
                        if (jsonobj[0].notice1 != 0) $("#profile_notice1").attr("checked", "true");
                        //notice2
                        if (jsonobj[0].notice2 != 0) $("#profile_notice2").attr("checked", "true");
                    }
                }
            });
        }
    });
}

function getRegistrationProfile() {

    var usermail = decodeURIComponent(jQuery.url.param("email"));

    $.ajax({
        url: serverpath+'/getUserProfileByUserName',
        type: "POST",
        data: ({
            action: "getUserProfileByUserName",
            username: usermail
        }),
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") {
                //hide column
                $("#already_member").css("display", "none");
                $("#email_tr").css("display", "none");
                $("#cfEmail_tr").css("display", "none");
                $("#pwd_tr").css("display", "none");
                $("#pwd_limit_tr").css("display", "none");
                $("#cfPwd_tr").css("display", "none");

                var jsonobj = data.result;

                //if already as developer
                if (jsonobj[0].ddegree != 0) {
                    $("body").attr("innerHTML", "");
                    alert("You are already as a developer!");
                    window.location = "/Developer/Index";
                }
                //first name
                if (jsonobj[0].first_name != "") $("#sign_fname").val(jsonobj[0].first_name);
                //last name
                if (jsonobj[0].last_name != "") $("#sign_lname").val(jsonobj[0].last_name);
                //email
                $("#sign_email").val(jsonobj[0].email);
                //confirm email
                $("#sign_cfEmail").val(jsonobj[0].email);
                //country
                if (jsonobj[0].country != "") $("#sign_country").val(jsonobj[0].country);
                //ABA
                $("#sign_aba").val(jsonobj[0].bankABA);
                //SWIFT
                $("#sign_swift").val(jsonobj[0].bankSWIFT);
                //Company
                if (jsonobj[0].company != "") $("#sign_company").val(jsonobj[0].company);
                //phone number
                if (jsonobj[0].phone_number != "" && jsonobj[0].phone_number != null) {
                    $("#sign_councode").val(jsonobj[0].phone_number.split('-')[0]);
                    $("#sign_areacode").val(jsonobj[0].phone_number.split('-')[1]);
                    $("#sign_phone").val(jsonobj[0].phone_number.split('-')[2]);
                }
                //website
                if (jsonobj[0].website != "") $("#sign_website").val(jsonobj[0].website);
                //address
                if (jsonobj[0].address != "") $("#sign_addr").val(jsonobj[0].address);
                //postcode
                if (jsonobj[0].postcode != 0) $("#sign_postcode").val(jsonobj[0].postcode);
                //bill account
                if (jsonobj[0].billaccount != "") $("#sign_billacc").val(jsonobj[0].billaccount);
                //bank account
                if (jsonobj[0].bankname != "") $("#sign_bankname").val(jsonobj[0].bankname);
            }
        }
    });
}

function getTools() {
    var platform = 2;
    if ($.client.os == "Android") platform = 1;

    $.ajax({
        url: serverpath + '/getTools',
        type: "POST",
        data: ({
            action: "getTools",
            area: area,
            toolid: "",
            classes: 2,
            platform: platform
        }),
        datatype: "JSON",
        async: false,
        success: function (data) {
            if (data.status == "success") {
                var jsonobj = data.result;

                var innerHtml = "<table class=\"mainleft\" width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";
                var innerHtml1 = "<table class=\"mainleft\" width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";

                for (key in jsonobj) {
                    //alert(jsonobj[key].img_link);
                    if (jsonobj[key].type == "Tool") {
                        if (key == 0) {
                            key = 1;
                        }else if(key==1){
                            key=0;
                        }

                        if (jsonobj[key].img_link == '' || jsonobj[key].img_link == null) jsonobj[key].img_link = '../../Content/images/dot.png';
                        innerHtml += "<table width=\"640px\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"background-color:#EAEAEA;\">";
                        innerHtml += "<tr>";
                        innerHtml += "<td align=\"left\" style=\"font-size:18px; font-weight:bold;\"><u>" + jsonobj[key].title + "</u></td>";
                        innerHtml += "<td align=\"right\">";
                        innerHtml += "<img src=\"../../Content/" + jsonobj[key].img_link + "\" width=\"30px\" height=\"30px\"/>";
                        innerHtml += "</td>";
                        innerHtml += "</tr><tr>";
                        innerHtml += "<td colspan=\"2\" align=\"left\" class=\"about\">";
                        innerHtml += jsonobj[key].description;
                        innerHtml += "<p/></td>";
                        innerHtml += "</tr><tr>";
                        innerHtml += "<td colspan=\"2\" style=\"background-color:#77933C; color:white; font-size:13px;\" valign=\"middle\">";


                        innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',1,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"../../Content/images/tools_download.png\"> Download</a>";


                        //innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].link + "','" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',1,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"images/tools_download.png\"> Download</a>";
                        innerHtml += "</td>";
                        innerHtml += "</tr>";
                        innerHtml += "</table><br/>";
                    } else {
                        if (jsonobj[key].img_link == '') jsonobj[key].img_link = 'images/dot.png';
                        innerHtml1 += "<table width=\"640px\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"background-color:#EAEAEA;\">";
                        innerHtml1 += "<tr>";
                        innerHtml1 += "<td align=\"left\" style=\"font-size:18px; font-weight:bold;\"><u>" + jsonobj[key].title + "</u></td>";
                        innerHtml1 += "<td align=\"right\">";
                        innerHtml1 += "<img src=\"../../Content/" + jsonobj[key].img_link + "\" width=\"30px\" height=\"30px\"/>";
                        innerHtml1 += "</td>";
                        innerHtml1 += "</tr><tr>";
                        innerHtml1 += "<td colspan=\"2\" align=\"left\" class=\"about\">";
                        innerHtml1 += jsonobj[key].description;
                        innerHtml1 += "<p/></td>";
                        innerHtml1 += "</tr><tr>";
                        innerHtml1 += "<td colspan=\"2\" style=\"background-color:#666666; color:white; font-size:13px;\" valign=\"middle\">";

                        innerHtml1 += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',2,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"../../Content/images/tools_download.png\"> Download</a>";
                        //innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].link + "','" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',2,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"images/tools_download.png\"> Download</a>";
                        innerHtml1 += "</td>";
                        innerHtml1 += "</tr>";
                        innerHtml1 += "</table><br/>";

                    }
                }

                innerHtml += "</td></tr></table>";
                $("#toolsDiv").empty();
                $("#toolsDiv").append(innerHtml);

                innerHtml1 += "</td></tr></table>";
                $("#mateDiv").empty();
                $("#mateDiv").append(innerHtml1);
            }
        }
    });
}

function getMATE() {
    var platform = 2;
    if ($.client.os == "Android") platform = 1;

    $.ajax({
        url: serverpath+'/getMATE',
        type: "POST",
        data: ({
            action: "getMATE",
            area: area,
            mateid: "",
            classes: 2,
            platform: platform
        }),
        datatype: "JSON",
        async: false,
        success: function (data) {
            if (data.status == "success") {
                var jsonobj = data.result;
                var innerHtml = "<table class=\"mainleft\" width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";

/*
        $.ajax({
          url: "/Handle/",
          type: "POST",
          cache: false,
          async: false,
          data: ({act:"iniSession"}),
          success: function (data) {
            $.ajax({
              url: serverpath+'/',
              type: "POST",
              data: ({action:"getUserProfileByUserName",username:data}),
              datatype: "JSON",
              async: false,
              success: function (data) {
                if (data.status == "success") {
                  var jsonobjs = data.result;
*/

                for (key in jsonobj) {
                    if (jsonobj[key].img_link == '') jsonobj[key].img_link = 'images/dot.png';
                    innerHtml += "<table width=\"640px\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" style=\"background-color:#EAEAEA;\">";
                    innerHtml += "<tr>";
                    innerHtml += "<td align=\"left\" style=\"font-size:18px; font-weight:bold;\"><u>" + jsonobj[key].title + "</u></td>";
                    innerHtml += "<td align=\"right\">";
                    innerHtml += "<img src=\"../../Content/images/" + jsonobj[key].img_link + "\" width=\"30px\" height=\"30px\"/>";
                    innerHtml += "</td>";
                    innerHtml += "</tr><tr>";
                    innerHtml += "<td colspan=\"2\" align=\"left\" class=\"about\">";
                    innerHtml += jsonobj[key].description;
                    innerHtml += "<p/></td>";
                    innerHtml += "</tr><tr>";
                    innerHtml += "<td colspan=\"2\" style=\"background-color:#666666; color:white; font-size:13px;\" valign=\"middle\">";

/*
                    $.ajax({
                      url: serverpath+'/',
                      type: "POST",
                      data: ({action:"queryEULASignUp",userid:jsonobjs[0].user_id,eulaid:jsonobj[key].EULAid}),
                      datatype: "JSON",
                      async: false,
                      success: function (data) {
                        if (data.result == 0) {
                          innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].link + "','" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',2,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"images/tools_download.png\"> Download</a>";
                        } else {
                          innerHtml += "<a href=\"" + downloadpath + "?eulaid=" + jsonobj[key].EULAid + "&resourceid=" + jsonobj[key].id + "&type=2&area=" + area + "&class=2&platform=" + jsonobj[key].platform + "\" style=\"color:white; text-decoration:none;\"><img onclick=\"setDownloadRec('" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "', 1, '" + jsonobj[key].platform + "')\" src=\"images/tools_download.png\"> Download</a>";
                        }
                      }
                    });
*/

                    innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',2,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"../../Content/images/tools_download.png\"> Download</a>";
                    //innerHtml += "<a href=\"javascript:openDownloadTools('" + jsonobj[key].link + "','" + jsonobj[key].EULAid + "','" + jsonobj[key].id + "',2,'" + jsonobj[key].platform + "')\" style=\"color:white; text-decoration:none;\"><img src=\"images/tools_download.png\"> Download</a>";
                    innerHtml += "</td>";
                    innerHtml += "</tr>";
                    innerHtml += "</table><br/>";
                }
/*
                }
              }
            });
          }
        });
*/

                innerHtml += "</td></tr></table>";
                $("#mateDiv").empty();
                $("#mateDiv").append(innerHtml);
            }
        }
    });
}

function getCheckoutHistory() {
    block_view("Loading...");
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
		async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
			//alert(data);
			/*
            $.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    var jsonobj = data.result;

                    var userid = jsonobj[0].user_id;
			*/
                    var userid = data;
					var status = "";
                    if ($("#status_yes").is(":checked")) status = "YES";
                    else if ($("#status_no").is(":checked")) status = "NO";
                    var startdate = $("#start_date").val();
                    var enddate = $("#end_date").val();

                    $.ajax({
                        url: serverpath+'/getCheckoutHistory',
                        type: "POST",
                        data: ({
                            action: "getCheckoutHistory",
                            userid: userid,
                            status: status,
                            startdate: startdate,
                            enddate: enddate
                        }),
                        datatype: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                var jsonobj = data.result;
                                var totalpage = parseInt((jsonobj.length % 10 == 0) ? (jsonobj.length / 10) : (jsonobj.length / 10) + 1);

                                if (jsonobj.length > 0){
                                     $("#export_history").css("display", "inline");
                                }else{
                                     $("#export_history").css("display", "none");
                                }
                                $("#checkout_list").empty();

                                var innerHtml = "<tr>";

                                innerHtml += "<td width=\"40px\" class=\"member_description\"> No </td>";
                                innerHtml += "<td width=\"110px\" class=\"member_description\"> Check out ID </td>";
                                innerHtml += "<td width=\"60px\" class=\"member_description\"> Amount </td>";
                                innerHtml += "<td width=\"130px\" class=\"member_description\"> Date </td>";
                                innerHtml += "<td width=\"100px\" class=\"member_description\"> Paid Status </td>";
                                innerHtml += "<td width=\"100px\" class=\"member_description\"> Remaining </td>";
                                innerHtml += "<td width=\"130px\" class=\"member_description\"> Payment Date </td>";
                                innerHtml += "</tr>";
                                innerHtml += "<tr>";
                                innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"7\" width=\"670px\">";

                                var page = ((jsonobj.length % 10) == 0) ? parseInt(jsonobj.length / 10) : (parseInt(jsonobj.length / 10) + 1);
                                for (var i = 0; i < page; i++) {
                                    innerHtml += "<table id=\"checkout_listPage" + (i + 1) + "\" style=\"display:" + ((i == 0) ? "table" : "none") + ";\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                                    for (var key = ((i * 10) == 0) ? 0 : (i * 10); key < ((i * 10) + 10); key++) {
                                        if (key == jsonobj.length) break;
                                        innerHtml += "<tr class=\"ap_description\">";
                                        innerHtml += "<td width=\"40px\" align=\"center\" height=\"24px\">" + (parseInt(key) + 1) + "</td>";
                                        innerHtml += "<td width=\"110px\" align=\"center\"> " + jsonobj[key].checkout_id + " </td>";
                                        innerHtml += "<td width=\"60px\" align=\"center\"> " + jsonobj[key].amount + " </td>";
                                        innerHtml += "<td width=\"130px\" align=\"center\"> " + jsonobj[key].date + " </td>";
                                        innerHtml += "<td width=\"100px\" align=\"center\">" + jsonobj[key].finish_paid + "</td>";
                                        innerHtml += "<td width=\"100px\" align=\"center\"> " + jsonobj[key].remaining + " </td>";
                                        innerHtml += "<td width=\"130px\" align=\"center\"> " + jsonobj[key].payment_date + " </td>";
                                        innerHtml += "</tr>";
                                        innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                        innerHtml += "<td colspan=\"7\" class=\"hr\">&nbsp;</td>";
                                        innerHtml += "</tr>";
                                    }
                                    innerHtml += "</table>";
                                }

                                innerHtml += "</td>";
                                innerHtml += "</tr>";
                                if (jsonobj.length > 10) {
                                    innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                    innerHtml += "<td colspan=\"7\" align=\"center\">";
                                    innerHtml += "<img id=\"checkout_list_pre\" onclick=\"prevNavMember('checkout_list'," + totalpage + ")\" style=\"display:none;\" width=\"18\" height=\"18\" src=\"../../Content/images/arrow_left.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "<img id=\"checkout_list_nex\" onclick=\"nextNavMember('checkout_list'," + totalpage + ")\" width=\"18\" height=\"18\" src=\"../../Content/images/arrow_right.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "/ to page ";
                                    innerHtml += "<select id=\"checkout_list_pager\" onchange=\"navigateMember('checkout_list',$(this).val()," + totalpage + ")\">";
                                    for (var i = 1; i <= totalpage; i++)
                                    innerHtml += "<option>" + i + "</option>";
                                    innerHtml += "</select>";
                                    innerHtml += "</td>";
                                    innerHtml += "</tr>";
                                }

                                if (data.result == "No Record!") {
                                    innerHtml = "<tr><td><span style=\"color:green; font-size:16px;\">No record!</span></td></tr>";
                                    //        							$("#report_tr").attr("innerHTML","&nbsp;");
                                    //        							$("#report_tr").attr("height","");
                                    $("#export_history").css("display", "none");
                                }
                                $("#checkout_list").append(innerHtml);
                            } else {
                                $("#export_history").css("display", "none");
                            }
                            end_view("Loading...");
                        }
                    });

//        			$.ajax({
//                        url: serverpath+'/getBalance',
//                        type: "POST",
//                        data: ({
//                            action: "getBalance",
//                            userid: userid
//                        }),
//        				datatype: "JSON",
//        				success: function(data){
//        					$("#available_balance").html(Math.round(data.result*1000)/1000);
//          				}
//        			});

                //}
            //});
        }
    });
}

function getCheckoutHistory2() {
    block_view("Loading...");
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        async: false,
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
            //alert(data);
            /*
            $.ajax({
            url: serverpath+'/',
            type: "POST",
            data: ({
            action: "getUserProfileByUserName",
            username: data
            }),
            datatype: "JSON",
            success: function (data) {
            var jsonobj = data.result;

            var userid = jsonobj[0].user_id;
            */
            var userid = data;
            var status = "";
            if ($("#status_yes").is(":checked")) status = "YES";
            else if ($("#status_no").is(":checked")) status = "NO";
            var startdate = $("#start_date").val();
            var enddate = $("#end_date").val();

            $.ajax({
                url: serverpath + '/getCheckoutHistory',
                type: "POST",
                data: ({
                    action: "getCheckoutHistory",
                    userid: userid,
                    status: status,
                    startdate: startdate,
                    enddate: enddate
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
                        var totalpage = parseInt((jsonobj.length % 10 == 0) ? (jsonobj.length / 10) : (jsonobj.length / 10) + 1);

                        if (jsonobj.length == 0) $("#export_history").css("display", "none");
                        $("#checkout_list").empty();

                        var innerHtml = "<tr>";

                        innerHtml += "<td width=\"40px\" class=\"member_description\"> No </td>";
                        innerHtml += "<td width=\"110px\" class=\"member_description\"> Check out ID </td>";
                        innerHtml += "<td width=\"60px\" class=\"member_description\"> Amount </td>";
                        innerHtml += "<td width=\"130px\" class=\"member_description\"> Date </td>";
                        innerHtml += "<td width=\"100px\" class=\"member_description\"> Paid Status </td>";
                        innerHtml += "<td width=\"100px\" class=\"member_description\"> Remaining </td>";
                        innerHtml += "<td width=\"130px\" class=\"member_description\"> Payment Date </td>";
                        innerHtml += "</tr>";
                        innerHtml += "<tr>";
                        innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"7\" width=\"670px\">";

                        var page = ((jsonobj.length % 10) == 0) ? parseInt(jsonobj.length / 10) : (parseInt(jsonobj.length / 10) + 1);
                        for (var i = 0; i < page; i++) {
                            innerHtml += "<table id=\"checkout_listPage" + (i + 1) + "\" style=\"display:" + ((i == 0) ? "table" : "none") + ";\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                            for (var key = ((i * 10) == 0) ? 0 : (i * 10); key < ((i * 10) + 10); key++) {
                                if (key == jsonobj.length) break;
                                innerHtml += "<tr class=\"ap_description\">";
                                innerHtml += "<td width=\"40px\" align=\"center\" height=\"24px\">" + (parseInt(key) + 1) + "</td>";
                                innerHtml += "<td width=\"110px\" align=\"center\"> " + jsonobj[key].checkout_id + " </td>";
                                innerHtml += "<td width=\"60px\" align=\"center\"> " + jsonobj[key].amount + " </td>";
                                innerHtml += "<td width=\"130px\" align=\"center\"> " + jsonobj[key].date + " </td>";
                                innerHtml += "<td width=\"100px\" align=\"center\">" + jsonobj[key].finish_paid + "</td>";
                                innerHtml += "<td width=\"100px\" align=\"center\"> " + jsonobj[key].remaining + " </td>";
                                innerHtml += "<td width=\"130px\" align=\"center\"> " + jsonobj[key].payment_date + " </td>";
                                innerHtml += "</tr>";
                                innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                innerHtml += "<td colspan=\"7\" class=\"hr\">&nbsp;</td>";
                                innerHtml += "</tr>";
                            }
                            innerHtml += "</table>";
                        }

                        innerHtml += "</td>";
                        innerHtml += "</tr>";
                        if (jsonobj.length > 10) {
                            innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                            innerHtml += "<td colspan=\"7\" align=\"center\">";
                            innerHtml += "<img id=\"checkout_list_pre\" onclick=\"prevNavMember('checkout_list'," + totalpage + ")\" style=\"display:none;\" width=\"18\" height=\"18\" src=\"images/arrow_left.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                            innerHtml += "<img id=\"checkout_list_nex\" onclick=\"nextNavMember('checkout_list'," + totalpage + ")\" width=\"18\" height=\"18\" src=\"images/arrow_right.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                            innerHtml += "/ to page ";
                            innerHtml += "<select id=\"checkout_list_pager\" onchange=\"navigateMember('checkout_list',$(this).val()," + totalpage + ")\">";
                            for (var i = 1; i <= totalpage; i++)
                                innerHtml += "<option>" + i + "</option>";
                            innerHtml += "</select>";
                            innerHtml += "</td>";
                            innerHtml += "</tr>";
                        }

                        if (data.result == "No Record!") {
                            innerHtml = "<tr><td><span style=\"color:green; font-size:16px;\">No record!</span></td></tr>";
                            //        							$("#report_tr").attr("innerHTML","&nbsp;");
                            //        							$("#report_tr").attr("height","");
                            $("#export_history").css("display", "none");
                        }
                        $("#checkout_list").append(innerHtml);
                    } else {
                        $("#export_history").css("display", "none");
                    }
                    end_view("Loading...");
                }
            });
            //}
            //});
        }
    });
}

function getMyAppInfo() {
    block_view("Loading...");
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
		/*
            $.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    var jsonobj = data.result;
*/
                    //alert(data);
					var userid = data;//jsonobj[0].user_id;
                    var cid = ($("#catOption").val() == -1) ? "" : $("#catOption").val();
                    var price = "";
                    if ($("#paid").is(":checked")) price = "PAID";
                    else if ($("#free").is(":checked")) price = "FREE";
                    var startdate = $("#start_date").val();
                    var enddate = $("#end_date").val();
                    var kw = $("#kw").val();

                    $.ajax({
                        url: serverpath+'/getMyAppsInfo',
                        type: "POST",
                        data: ({
                            action: "getMyAppsInfo",
                            userid: userid,
                            category: cid,
                            keyword: kw,
                            startdate: startdate,
                            enddate: enddate,
                            price: price,
                            area: area
                        }),
                        datatype: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                var jsonobj = data.result;
                                var totalpage = parseInt((jsonobj.length % 10 == 0) ? (jsonobj.length / 10) : (jsonobj.length / 10) + 1);

                                $("#application_list").empty();

                                var innerHtml = "<tr>";

                                innerHtml += "<td style=\"text-align:center;\" width=\"40px\" class=\"member_description\"> No </td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"80px\" class=\"member_description\">&nbsp;&nbsp;</td>";
                                innerHtml += "<td style=\"text-align:left;\" width=\"230px\" class=\"member_description\"> Application</td>";
                                innerHtml += "<td style=\"text-align:left;\" width=\"200px\" class=\"member_description\">Detail</td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"70px\" class=\"member_description\"> Display </td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"50px\" class=\"member_description\"> Action </td>";
                                innerHtml += "</tr>";
                                innerHtml += "<tr>";
                                innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"6\" width=\"670px\">";


                                var page = ((jsonobj.length % 10) == 0) ? parseInt(jsonobj.length / 10) : (parseInt(jsonobj.length / 10) + 1);
                                for (var i = 0; i < page; i++) {
                                    innerHtml += "<table id=\"application_listPage" + (i + 1) + "\" style=\"display:" + ((i == 0) ? "table" : "none") + ";\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                                    for (var key = ((i * 10) == 0) ? 0 : (i * 10); key < ((i * 10) + 10); key++) {
                                        if (key == jsonobj.length) break;
                                        innerHtml += "<tr class=\"ap_description\">";
                                        innerHtml += "<td width=\"40px\"  style=\"text-align:center;\" height=\"24px\">" + (parseInt(key) + 1) + "</td>";
                                        innerHtml += "<td width=\"80px\"  style=\"text-align:center;\"><img src=\"" + jsonobj[key].app_icon + "?" + guid() + "\" height=\"49\" width=\"49\"></td>";
                                        innerHtml += "<td width=\"230px\"  style=\"text-align:left;\">" + ((jsonobj[key].app_name.length <= 20) ? jsonobj[key].app_name : (jsonobj[key].app_name.substring(0, 20) + "...")) + "</td>";
                                        innerHtml += "<td width=\"200px\"  style=\"text-align:left;\" valign=\"top\">Rating: " + viewRateResult(jsonobj[key].rating) + "("+jsonobj[key].ratingCounter+")<br/>";
                                        innerHtml += "Download count: " + jsonobj[key].sold_count + "<br/>";
                                        innerHtml += "Uploaded: " + jsonobj[key].update_date + "<br/>";
                                        innerHtml += "Version number: " + jsonobj[key].version_number + "<br/>";
                                        innerHtml += "Price: " + jsonobj[key].price + "<br/>";
                                        innerHtml += "Status: " + jsonobj[key].status + "<br/>";
                                        innerHtml += "</td>";
                                        innerHtml += "<td width=\"70px\"  style=\"text-align:center;\">";
                                        if (jsonobj[key].status == "Un-published" || jsonobj[key].status == "Published") {
                                            innerHtml += "<select id=\"\" class=\"contact_textfield\" onChange=\"setAppStatus(" + jsonobj[key].app_id + ",$(this).val())\">";
                                            innerHtml += "<option " + ((jsonobj[key].status == "Unpublished") ? "selected=\"selected\"" : "") + " value=\"UNPUBLISH\">Hide</option>";
                                            innerHtml += "<option " + ((jsonobj[key].status == "Published") ? "selected=\"selected\"" : "") + " value=\"PUBLISH\">Show</option>";
                                            innerHtml += "</select>";
                                        } else if (jsonobj[key].status == "Removed") {
                                            innerHtml += "<span class=\"ap_name\">Removed</span>";
                                        } else {
                                            innerHtml += "<span class=\"ap_name\">Verifying</span>";
                                        }
                                        innerHtml += "</td>";
                                        innerHtml += "<td width=\"50px\"  style=\"text-align:center;\"><a href=\"/Developer/EditMyApplication?app=" + jsonobj[key].app_id + "\"><img src=\"../../Content/images/icon_summary.gif\" alt=\"\" height=\"24\" width=\"24\"></a>&nbsp;<a href=\"/Developer/MyApplicationSummary?app=" + jsonobj[key].app_id + "\"><img src=\"../../Content/images/icon_summary2.gif\" alt=\"\" height=\"24\" width=\"24\"></a></td>";
                                        innerHtml += "</tr>";
                                        innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                        innerHtml += "<td colspan=\"6\" class=\"hr\">&nbsp;</td>";
                                        innerHtml += "</tr>";
                                    }
                                    innerHtml += "</table>";
                                }

                                innerHtml += "</td>";
                                innerHtml += "</tr>";
                                if (jsonobj.length > 10) {
                                    innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                    innerHtml += "<td colspan=\"6\" align=\"center\">";
                                    innerHtml += "<img id=\"application_list_pre\" onclick=\"prevNavMember('application_list'," + totalpage + ")\" style=\"display:none;\" width=\"18\" height=\"18\" src=\"../../Content/images/arrow_left.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "<img id=\"application_list_nex\" onclick=\"nextNavMember('application_list'," + totalpage + ")\" width=\"18\" height=\"18\" src=\"../../Content/images/arrow_right.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "/ to page ";
                                    innerHtml += "<select id=\"application_list_pager\" onchange=\"navigateMember('application_list',$(this).val()," + totalpage + ")\">";
                                    for (var i = 1; i <= totalpage; i++)
                                    innerHtml += "<option>" + i + "</option>";
                                    innerHtml += "</select>";
                                    innerHtml += "</td>";
                                    innerHtml += "</tr>";
                                }

                                if (jsonobj.length == 0) innerHtml = "<tr><td><span style=\"color:green; font-size:16px;\">No record!</span></td></tr>";
                                $("#application_list").append(innerHtml);
                            }
                        }
                    });
                //}
            //});
        }
    });
}

function getMySoftInfo() {
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
		/*
            $.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    var jsonobj = data.result;
*/
                    var userid = data;//jsonobj[0].user_id;
                    
                    var cid = ($("#catOption").val() == -1) ? "" : $("#catOption").val();
                    var price = "";
                    if ($("#paid").is(":checked")) price = "PAID";
                    else if ($("#free").is(":checked")) price = "FREE";
                    var startdate = $("#start_date").val();
                    var enddate = $("#end_date").val();
                    var kw = $("#kw").val();

                    $.ajax({
                        url: serverpath+'/getMySubmitted',
                        type: "POST",
                        data: ({
                            action: "getMySubmitted",
                            userid: userid,
                            category: cid,
                            keyword: kw,
                            startdate: startdate,
                            enddate: enddate,
                            price: price,
                            area: area
                        }),
                        datatype: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                var jsonobj = data.result;
                                var totalpage = parseInt((jsonobj.length % 10 == 0) ? (jsonobj.length / 10) : (jsonobj.length / 10) + 1);

                                $("#software_list").empty();

                                var innerHtml = "<tr>";

                                innerHtml += "<td style=\"text-align:center;\" width=\"40px\" class=\"member_description\"> No </td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"80px\" class=\"member_description\">&nbsp;&nbsp;</td>";
                                innerHtml += "<td style=\"text-align:left;\" width=\"230px\" class=\"member_description\"> Software</td>";
                                innerHtml += "<td style=\"text-align:left;\" width=\"200px\" class=\"member_description\">Detail </td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"70px\" class=\"member_description\"> Price </td>";
                                innerHtml += "<td style=\"text-align:center;\" width=\"50px\" class=\"member_description\"> Status </td>";
                                innerHtml += "</tr>";
                                innerHtml += "<tr>";
                                innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"6\" width=\"670px\">";


                                var page = ((jsonobj.length % 10) == 0) ? parseInt(jsonobj.length / 10) : (parseInt(jsonobj.length / 10) + 1);
                                for (var i = 0; i < page; i++) {
                                    innerHtml += "<table id=\"software_listPage" + (i + 1) + "\" style=\"display:" + ((i == 0) ? "table" : "none") + ";\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                                    for (var key = ((i * 10) == 0) ? 0 : (i * 10); key < ((i * 10) + 10); key++) {
                                        if (key == jsonobj.length) break;
                                        innerHtml += "<tr class=\"ap_description\">";
                                        innerHtml += "<td style=\"text-align:center;\" width=\"40px\" height=\"24px\">" + (parseInt(key) + 1) + "</td>";
                                        innerHtml += "<td style=\"text-align:center;\" width=\"80px\"><img src=\"" + jsonobj[key].app_icon + "?" + guid() + "\" height=\"49\" width=\"49\"></td>";
                                        innerHtml += "<td style=\"text-align:left;\" width=\"230px\">" + ((jsonobj[key].app_name.length <= 20) ? jsonobj[key].app_name : (jsonobj[key].app_name.substring(0, 20) + "...")) + "</td>";
                                        innerHtml += "<td style=\"text-align:left;\" width=\"200px\" valign=\"top\">Rating: " + viewRateResult(jsonobj[key].rating) + "("+jsonobj[key].ratingCounter+")<br/>";
                                        innerHtml += "Download count: " + jsonobj[key].sold_count + "<br/>";
                                        innerHtml += "Uploaded: " + jsonobj[key].update_date + "<br/>";
                                        innerHtml += "Version number: " + jsonobj[key].version_number + "<br/>";
                                        innerHtml += "</td>";
                                        innerHtml += "<td style=\"text-align:center;\" width=\"70px\">";
                                        innerHtml += jsonobj[key].price;
                                        innerHtml += "</td>";
                                        innerHtml += "<td style=\"text-align:center;\" width=\"50px\">" + jsonobj[key].status + "</td>";
                                        innerHtml += "</tr>";
                                        innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                        innerHtml += "<td colspan=\"6\" class=\"hr\">&nbsp;</td>";
                                        innerHtml += "</tr>";
                                    }
                                    innerHtml += "</table>";
                                }

                                innerHtml += "</td>";
                                innerHtml += "</tr>";
                                if (jsonobj.length > 10) {
                                    innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                                    innerHtml += "<td colspan=\"6\" align=\"center\">";
                                    innerHtml += "<img id=\"software_list_pre\" onclick=\"prevNavMember('software_list'," + totalpage + ")\" style=\"display:none;\" width=\"18\" height=\"18\" src=\"images/arrow_left.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "<img id=\"software_list_nex\" onclick=\"nextNavMember('software_list'," + totalpage + ")\" width=\"18\" height=\"18\" src=\"images/arrow_right.gif\" class=\"topage\" style=\"cursor:pointer;\"> ";
                                    innerHtml += "/ to page ";
                                    innerHtml += "<select id=\"software_list_pager\" onchange=\"navigateMember('software_list',$(this).val()," + totalpage + ")\">";
                                    for (var i = 1; i <= totalpage; i++)
                                    innerHtml += "<option>" + i + "</option>";
                                    innerHtml += "</select>";
                                    innerHtml += "</td>";
                                    innerHtml += "</tr>";
                                }

                                if (jsonobj.length == 0) innerHtml = "<tr><td><span style=\"color:green; font-size:16px;\">No record!</span></td></tr>";
                                $("#software_list").append(innerHtml);
                            }
                            end_view("Loading...");
                        }
                    });
                //}
            //});
        }
    });
}

function getAppStats() {
    block_view("Loading...");
    var appid = jQuery.url.param("app");

    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {

            $.ajax({
                url: serverpath + '/getAppDetail',
                type: "POST",
                data: ({
                    appid: appid,
                    area: area
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        var innerHtml = "<tr>";
                        innerHtml += "<td width=\"80\" style=\"text-align:center;\" class=\"member_description\"> Status </td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\" class=\"member_description\">Version number</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\" class=\"member_description\"> Download count</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\" class=\"member_description\">Refund count</td>";
                        innerHtml += "<td width=\"70\" style=\"text-align:center;\" class=\"member_description\"> Rating </td>";
                        innerHtml += "<td width=\"100\" style=\"text-align:center;\" class=\"member_description\"> Action </td>";
                        innerHtml += "</tr>";
                        innerHtml += "<tr>";
                        innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"6\">";

                        innerHtml += "<table style=\"display:table\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                        innerHtml += "<tr class=\"ap_description\">";
                        innerHtml += "<td width=\"80\" style=\"text-align:center;\">-</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\">" + jsonobj.version + "</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\">" + jsonobj.downloadnumber + "</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\">-</td>";
                        innerHtml += "<td width=\"70\" style=\"text-align:center;\">" + jsonobj.rating + "</td>";
                        innerHtml += "<td width=\"100\" style=\"text-align:center;\"><a href=\"/Developer/AppStatsDetail?app=" + jsonobj.id + "\"><img src=\"../../Content/images/icon_summary2.gif\" alt=\"\" height=\"24\" width=\"24\"></a></td>";
                        innerHtml += "</tr>";
                        innerHtml += "</table>";
                        innerHtml += "</td>";
                        innerHtml += "</tr>";
                        $("#statistic_list").html(innerHtml);
                        end_view("Loading...");
                    }
                }
            });

        }
    });
}

function getAppUpdateHistory() {
    var appid = jQuery.url.param("app");

    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {

            $.ajax({
                url: serverpath + '/getAppUpdateHistory',
                type: "POST",
                data: ({
                    appid: appid,
                    area: area
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;
                        var totalpage = parseInt((jsonobj.length % 10 == 0) ? (jsonobj.length / 10) : (jsonobj.length / 10) + 1);

                        var innerHtml = "<tr>";

                        innerHtml += "<td style=\"text-align:center;\" width=\"100\" class=\"member_description\"> Version number </td>";
                        innerHtml += "<td style=\"text-align:center;\" width=\"200\" class=\"member_description\">Update date</td>";
                        innerHtml += "<td style=\"text-align:center;\" width=\"100\" class=\"member_description\"> Price </td>";
                        innerHtml += "<td style=\"text-align:center;\" width=\"80\" class=\"member_description\"> Passed or not </td>";
                        innerHtml += "</tr>";
                        innerHtml += "<tr>";
                        innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"6\">";


                        var page = ((jsonobj.length % 10) == 0) ? parseInt(jsonobj.length / 10) : (parseInt(jsonobj.length / 10) + 1);
                        for (var i = 0; i < jsonobj.length; i++) {
                            innerHtml += "<table id=\"software_listPage" + (i + 1) + "\" style=\"display:" + ((i == 0) ? "table" : "none") + ";\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                            innerHtml += "<tr class=\"ap_description\">";
                            innerHtml += "<td style=\"text-align:center;\" width=\"100\" height=\"24px\">" + jsonobj[i].VersionName + "</td>";
                            innerHtml += "<td style=\"text-align:center;\" width=\"200\">" + jsonobj[i].UploadDate + "</td>";
                            innerHtml += "<td style=\"text-align:center;\" width=\"100\">-</td>";
                            switch(jsonobj[i].Status){
                                case 1:
                                     var Status="Submitted"; 
                                    break;
                                case 2:
                                     var Status = "Pass"; 
                                    break;
                                case 3:
                                     var Status = "Published"; 
                                    break;
                                case 4:
                                     var Status = "Removed"; 
                                    break;
                                case 5:
                                     var Status = "Fail"; 
                                    break;
                                case 6:
                                     var Status = "Reported"; 
                                    break;
                                case 7:
                                     var Status = "Un-published"; 
                                    break;
                                case 90:
                                    var Status = "Uploaded"; 
                                    break;
                                case 91:
                                    var Status = "Verified"; 
                                    break;
                                case 92:
                                    var Status = "Patching"; 
                                    break;
                                case 93:
                                    var Status = "Preparing Publish"; 
                                    break;
                                case 94:
                                    var Status = "Ready to Publish"; 
                                    break;
                                case 95:
                                    var Status = "Rejected"; 
                                    break;
                                case 96:
                                    var Status = "Reported"; 
                                    break;

                            }

                            innerHtml += "<td style=\"text-align:center;\" width=\"80\">" + Status + "</td>";
                            innerHtml += "</tr>";
                            innerHtml += "<tr class=\"ap_description\" valign=\"top\">";
                            innerHtml += "<td colspan=\"4\" class=\"hr\">&nbsp;</td>";
                            innerHtml += "</tr>";
                            innerHtml += "</table>";
                        }

                        innerHtml += "</td>";
                        innerHtml += "</tr>";
                        $("#history_list").html(innerHtml);
                    }
                    end_view("Loading...");
                }
            });
            //}
            //});
        }
    });
}

function getReviews() {
    block_view("Loading...");
    var appid = jQuery.url.param("app");

    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {

            $.ajax({
                url: serverpath + '/getReview',
                type: "POST",
                data: ({
                    appid: appid,
                    area: area
                }),
                datatype: "JSON",
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        $("#appReviewDetail").html($("#appReviewDetail").html()+" ("+jsonobj.length+")");

                        var innerHtml = "<tr>";
                        innerHtml += "<td width=\"80\" style=\"text-align:center;\" class=\"member_description\"> Date </td>";
                        innerHtml += "<td width=\"300\" style=\"text-align:center;\" class=\"member_description\">Account</td>";
                        innerHtml += "<td width=\"400\" style=\"text-align:center;\" class=\"member_description\"> Comment</td>";
                        innerHtml += "<td width=\"200\" style=\"text-align:center;\" class=\"member_description\"> Rating </td>";
                        innerHtml += "</tr>";

                        for (var i = 0; i < jsonobj.length; i++) {
                            innerHtml += "<tr>";
                            innerHtml += "<td class=\"ap_description\" align=\"center\" colspan=\"5\">";
                            innerHtml += "<table style=\"display:table\" width=\"670px\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
                            innerHtml += "<tr class=\"ap_description\">";
                            innerHtml += "<td width=\"80\" style=\"text-align:center;\">"+ jsonobj[i].date +"</td>";
                            innerHtml += "<td width=\"200\" style=\"text-align:center;\">" + jsonobj[i].account + "</td>";
                            innerHtml += "<td width=\"400\" style=\"text-align:left;\">" + jsonobj[i].comment + "</td>";
                            innerHtml += "<td width=\"200\" style=\"text-align:center;\">"+ jsonobj[i].rating +"</td>";
                            innerHtml += "</tr>";
                            innerHtml += "</table>";
                            innerHtml += "</td>";
                            innerHtml += "</tr>";
                        }

                        $("#statistic_list").html(innerHtml);
                        end_view("Loading...");
                    }else{
                        innerHtml = "<tr><td><span style=\"color:green; font-size:16px;\">No record!</span></td></tr>";
                        $("#statistic_list").html(innerHtml);
                        end_view("Loading...");
                    }
                }
            });

        }
    });
}

function navigateMember(table, page, totalpage) {
    $("#" + table + " table").css("display", "none");
    $("#" + table + "Page" + page).css("display", "table");

    if (page == 1) $("#" + table + "_pre").css("display", "none");
    else $("#" + table + "_pre").css("display", "inline");
    if (page == totalpage) $("#" + table + "_nex").css("display", "none");
    else $("#" + table + "_nex").css("display", "inline");
}

function nextNavMember(table, totalpage) {
    var page = (parseInt($("#" + table + "_pager").val()) + 1);
    $("#" + table + " table").css("display", "none");
    $("#" + table + "Page" + page).css("display", "table");

    if (page == 1) $("#" + table + "_pre").css("display", "none");
    else $("#" + table + "_pre").css("display", "inline");
    if (page == totalpage) $("#" + table + "_nex").css("display", "none");
    else $("#" + table + "_nex").css("display", "inline");

    $("#" + table + "_pager").val(page);
}

function prevNavMember(table, totalpage) {
    var page = (parseInt($("#" + table + "_pager").val()) - 1);
    $("#" + table + " table").css("display", "none");
    $("#" + table + "Page" + page).css("display", "table");

    if (page == 1) $("#" + table + "_pre").css("display", "none");
    else $("#" + table + "_pre").css("display", "inline");
    if (page == totalpage) $("#" + table + "_nex").css("display", "none");
    else $("#" + table + "_nex").css("display", "inline");

    $("#" + table + "_pager").val(page);
}

function viewRateResult(rating) {
    var full = (rating.toString().split('.').length > 1) ? parseInt(rating.toString().split('.')[0]) : rating;
    var half = (rating.toString().split('.').length > 1) ? parseInt(rating.toString().split('.')[1].substring(0, 1)) : 0;
    var empty = 5 - full;
    if (half >= 5) empty--;

    var innerHtml = "";
    for (var i = 0; i < full; i++)
    innerHtml += "<img height=\"20\" width=\"20\" src=\"../../Content/images/star_full.gif\">";
    if (half >= 5) innerHtml += "<img height=\"20\" width=\"20\" src=\"../../Content/images/star_half.gif\">";
    for (var i = 0; i < empty; i++)
    innerHtml += "<img height=\"20\" width=\"20\" src=\"../../Content/images/star_none.gif\">";

    return innerHtml;
}

function changeProfilePassword() {
    if ($.trim($("#profile_pwd").val()).length == 0) {
        $("#profileError").attr("innerHTML", "Please fill your password!");
        window.location = "#";
        return;
    } else {
        $("#profileError").attr("innerHTML", "");

        $.ajax({
            url: "/Handle/iniSession",
            type: "POST",
            data: ({
                act: "iniSession"
            }),
            success: function (data) {
                $.ajax({
                    url: serverpath+'/requestAuthentication',
                    type: "POST",
                    data: ({
                        action: "requestAuthentication",
                        username: data,
                        password: $("#profile_pwd").val()
                    }),
                    datatype: "JSON",
                    success: function (data) {
                        if (data.status == "success") window.open("/Developer/ChangePassword", "_blank");
                        else {
                            $("#profileError").attr("innerHTML", "Incorrect password!");
                            window.location = "#";
                        }
                    }
                });
            }
        });
    }
}

function getCategory() {
    $.ajax({
        url: serverpath+'/getCategory',
        type: "POST",
        data: ({
            action: "getCategory",
            area: area
        }),
        datatype: "JSON",
        success: function (data) {

            if (data.status == "success") {
                var jsonobj = (data.result);

                for (key in jsonobj) {
                    if (pagename == "DVUPMAP" && jsonobj[key].ID == "0") continue;
                    $("#catOption").append("<option value=\"" + jsonobj[key].ID + "\">" + jsonobj[key].Name + "</option>");
                }
            }
        }
    });
}

function getRegion() {
    $.ajax({
        url: serverpath + '/getRegion',
        type: "POST",
        data: ({
            area: area
        }),
        success: function (data) {
            $("#SelectCountryDiv").html(data);
        }
    });
}

function getPrice() {
    $.ajax({
        url: serverpath + '/getPrice',
        type: "POST",
        data: ({
            area: area
        }),
        success: function (data) {
            $("#prg_price").html(data);
        }
    });
}

function checkUserVerification() {

    var token = jQuery.url.param("token");

//    if (token == undefined) {
//        $("#signFn_table").attr("innerHTML", "<tr><td class=\"error_text\" align=\"center\">Account verification error, please contact us with your comment!</td></tr>");
//        return;
//    }

    if (token != undefined && token.length > 0) {
        $.ajax({
            url: serverpath+'/checkUserVerification',
            type: "POST",
            data: ({
                action: "checkUserVerification",
                token: token
            }),
            datatype: "JSON",
            success: function (data) {
                if (data.status != "success") {
                    $("#signFn_table").attr("innerHTML", "<tr><td class=\"error_text\" align=\"center\">Account verification error, please contact us with your comment!</td></tr>");
                    $("#category").attr("innerHTML", "Fail to verify account");
                } else $("#contentImg_end_dev").css("display", "inline");
            }
        });
    } else {
        $("#contentImg_end_dev").css("display", "inline");
    }
}

function setAppStatus(app_id, app_status) {
    block_view("Loading...");
    $.ajax({
        url: serverpath+'/setAppStatus',
        type: "POST",
        data: ({
            action: "setAppStatus",
            appid: app_id,
            appstatus: app_status
        }),
        datatype: "JSON",
        success: function (data) {
            end_view("Loading...");
        }
    });
}

function getEditApp() {
    var appid = jQuery.url.param("app");

    if (appid == undefined || appid == "") return;
    else block_view("Loading...");

    document.title = "Edit My Application | Insyde Market";
    $("#category").attr("innerHTML", "Edit My Application - Step 1/2");
    $("#pathAreaSet").attr("innerHTML", "Home > Account Center > Edit Apps");
    $.ajax({
        url: serverpath + '/getAppDetail',
        type: "POST",
        data: ({
            action: "getAppDetail",
            appid: appid,
            area: area
        }),
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") {
                var jsonobj = data.result;

                if (jsonobj.device.length > 0) {
                    $("[name='device']").each(function () {
                        for (i = 0; i < jsonobj.device.length; i++) {
                            if (jsonobj.device[i] == $(this).val()) {
                                $(this).attr("checked", true);
                            }
                        }
                    });
                }
                //alert(jsonobj.name);
                $("#prg_title").val(jsonobj.name);

                //language
                $("#prg_lang").val(jsonobj.area);
                //description
                $("#prg_desc").val(jsonobj.description.replace(/<br \/>/gi, '\n').replace(/<br\/>/gi, '\n'));

                //category
                $.ajax({
                    url: serverpath + '/getCategory',
                    type: "POST",
                    data: ({
                        action: "getCategory",
                        area: area
                    }),
                    datatype: "JSON",
                    success: function (data) {

                        if (data.status == "success") {
                            var json = (data.result);

                            for (key in json) {
                                if (json[key].Name == jsonobj.category) $("#catOption").val(json[key].ID);
                            }
                        }
                    }
                });

                //price
                $("#prg_price").val(jsonobj.price);
                if (jsonobj.price == 0) $("#prg_price").attr("disabled", "true");

                //$("#prg_file_name").attr("innerHTML", jsonobj);
                $("#icon_preview_image").attr("src", jsonobj.icon);
                $("#icon_preview").show();
                //$("#preview_file_name").attr("innerHTML", jsonobj.icon);

                var scnList = jsonobj.screenShot.split(',');
                var innerHtml = "";
                for (var i = 0; i < scnList.length; i++) {
                    $("#scn_file" + (i + 1) + "_preview_image").attr("src", scnList[i]);
                    $("#scn_file" + (i + 1) + "_preview").show();
                    $("#scn_file" + (i + 1) + "_name").attr("innerHTML", scnList[i]);
                }

                /*
                $("#prg_apk_tr").css("display", "none");
                $("#prg_apk_ltd_tr").css("display", "none");
                $("#prg_icon_tr").css("display", "none");
                $("#prg_icon_ltd_tr").css("display", "none");
                $("#prg_scn1_tr").css("display", "none");
                $("#prg_scn1_ltd_tr").css("display", "none");
                $("#prg_scn2_ltd_tr").empty();
                $("#prg_scn2_ltd_tr").append($("#prg_scn1_ltd_tr").attr("innerHTML"));
                $("#prg_scn2_ltd_tr").css("display", "table-row");
                */

                //  $("#prg_title_tr").css("display", "none");
                $("#prg_title").attr("readonly", true);
                $("#prg_web_tr").css("display", "none");
                $("#prg_email_tr").css("display", "none");
                $("#prg_agree_tr").css("display", "table-row");
            }
            end_view("Loading...");
        }
    });
}

function update(description, price, area, apkurl, category, screenshot, icon) {
    //block_view("Updating...");
    var appid = jQuery.url.param("app");
	alert(screenshot);
    $.ajax({
        url: serverpath+'/update',
        type: "POST",
        async: false,
        data: ({
            action: "update",
            appid: appid,
            description: description,
            price: price,
            area: area,
            apkurl: apkurl,
            apkhash: "",
            apksize: "",
            category: category,
            version: "",
            os: "",
            hardware: "",
            platform: "",
            screenshot: screenshot,
            icon: icon
        }),
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") {
                $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td class=\'error_text\' style='color:green;'>Your program has been updated successfully!</td></tr></table>");
            } else {
                $("#resultDiv").attr("innerHTML", "<table style='margin-left:30px;'><tr><td class=\'error_text\'>" + data.result.ErrMsg + "!</td></tr></table>");
            }
        }
    });

    //end_view("Updating...");
}

function generateReport() {
    block_view("Generating...");
    $.ajax({
        url: "/Handle/iniSession2",
        type: "POST",
        data: ({
            act: "iniSession2"
        }),
        success: function (data) {
		/*
            $.ajax({
                url: serverpath+'/',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    var jsonobj = data.result;
*/
                    var userid = data;//jsonobj[0].user_id;
                    var status = "";
                    if ($("#status_yes").is(":checked")) status = "YES";
                    else if ($("#status_no").is(":checked")) status = "NO";
                    var startdate = $("#start_date").val();
                    var enddate = $("#end_date").val();

                    $.ajax({
                        url: serverpath+'/getCheckoutHistory',
                        type: "POST",
                        data: ({
                            action: "getCheckoutHistory",
                            userid: userid,
                            status: status,
                            startdate: startdate,
                            enddate: enddate
                        }),
                        datatype: "JSON",
                        success: function (data) {
                            if (data.status == "success") {
                                //data = '{"status":"success","result":[{"app_id":21,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":2.74,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":199,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":0.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":249,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":1.31,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":310,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":3.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":371,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":4.85,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":21,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":2.74,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":199,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":0.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":249,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":1.31,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":310,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":3.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":371,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":4.85,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":21,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":2.74,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":199,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":0.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":249,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":1.31,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":310,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":3.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":371,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":4.85,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":21,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":2.74,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":199,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":0.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":249,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":1.31,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":310,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":3.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":371,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":4.85,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":21,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":2.74,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":199,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":0.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":249,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":1.31,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":310,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":3.72,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02},{"app_id":371,"app_icon":"http:\/\/www.insydemarket.com\/icon1.jpg","app_name":"Focus Well","rating":4.85,"download_count":36,"update_date":[],"version_number":"1.0.0.3","status":1,"price":49.02}]}';
                                var now = new Date();
                                $.download('/Handle/export', 'fname=checkout_' + getTime(now) + '&format=xls&userid=' + userid+"&status="+status+"&startdate="+startdate+"&enddate="+enddate);
                            }
                            end_view("Generating...");
                        }
                    });
                //}
            //});
        }
    });
}

function checkout() {

    if ($.trim($("#chk_amount").val()).length == 0) {
        $("#chkError").attr("innerHTML", "Please fill your checkout amount");
        return;
    }

    if (parseInt($("#chk_amount").val()) < 100) {
        $("#chkError").attr("innerHTML", "Your checkout amount must not less than $USD100!");
        return;
    }

    if (parseInt($("#chk_amount").val()) > parseInt($("#chk_balanceSpan").attr("innerHTML"))) {
        $("#chkError").attr("innerHTML", "Your checkout amount must less your balance!");
        return;
    }

    $("#chk_send").attr("disabled",true);

    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        data: ({
            act: "iniSession"
        }),
        success: function (data) {
            $.ajax({
                url: serverpath+'/getUserProfileByUserName',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                success: function (data) {
                    var jsonobj = data.result;
                    var userid = jsonobj[0].user_id;
                    var amount = $("#chk_amount").val();

                    $.ajax({
                        url: serverpath+'/checkout',
                        type: "POST",
                        data: ({
                            action: "checkout",
                            userid: userid,
                            amount: amount
                        }),
                        datatype: "JSON",
                        success: function (data) {
                            $("#form_table").css("display", "none");
                            $("#result_form").css("display", "inline");
                            $("#chk_result").attr("innerHTML", data.result);
                            getCheckoutHistory();
                        }
                    });
                }
            });
        }
    });
}

function blog(url) {
   window.open(url,"_blank");
/*
  $.ajax({
  url: "/Handle/",
  type: "POST",
  data: "act=iniSession",
  success: function(data) {
  if(data=="guest")
  openLoginDialog();
  else
  window.open(url,"_blank");
  }
  });
  */
  
}

function news(url) {
   window.open(url,"_blank");

	/*
  $.ajax({
  url: "/Handle/",
  type: "POST",
  data: "act=iniSession",
  success: function(data) {
  if(data=="guest")
  openLoginDialog();
  else
  window.open(url,"_blank");
  }
  });
  */
  
}

function upgrade() {
    if ((!$("#upgrade_payment_bank").is(":checked")) && (!$("#upgrade_payment_paypal").is(":checked"))) {
        $("#upgradeError").attr("innerHTML", "Please select your payment type!");
        return;
    }

    //payment bank
    if ($("#upgrade_payment_bank").is(":checked")) {
        if ($.trim($("#upgrade_bankname").val()).length == 0) {
            $("#upgradeError").attr("innerHTML", "Please fill your bank name!");
            return;
        }

        if ($.trim($("#upgrade_billacc").val()).length == 0) {
            $("#upgradeError").attr("innerHTML", "Please fill your bill account!");
            return;
        }
    }

    //payment paypal
    if ($("#upgrade_payment_paypal").is(":checked")) {
        if ($.trim($("#upgrade_paypal").val()).length == 0) {
            $("#upgradeError").attr("innerHTML", "Please fill your paypal ID!");
            return;
        }
    }

    if ($("#upgrade_swift_tr").css("display") == "table-row" && $.trim($("#upgrade_swift").val()).length == 0) {
        $("#upgradeError").attr("innerHTML", "Please fill your SWIFT code!");
        return;
    }

    if ($("#upgrade_aba_tr").css("display") == "table-row" && $.trim($("#upgrade_aba").val()).length == 0) {
        $("#upgradeError").attr("innerHTML", "Please fill your ABA code!");
        return;
    }

    if ($.trim($("#upgrade_coun").val()).length == 0 || $.trim($("#upgrade_area").val()).length == 0 || $.trim($("#upgrade_phone").val()).length == 0) {
        $("#upgradeError").attr("innerHTML", "Please fill your phone number!");
        return;
    }

    $.ajax({
        url: "/Handle/iniSession",
        type: "POST",
        async: false,
        data: ({
            act: "iniSession"
        }),
        success: function (data) {
            $.ajax({
                url: serverpath+'/getUserProfileByUserName',
                type: "POST",
                data: ({
                    action: "getUserProfileByUserName",
                    username: data
                }),
                datatype: "JSON",
                async: false,
                success: function (data) {
                    if (data.status == "success") {
                        var jsonobj = data.result;

                        var userid = jsonobj[0].user_id;
                        var firstname = jsonobj[0].first_name;
                        var lastname = jsonobj[0].last_name;
                        var nickname = jsonobj[0].email;
                        var email = jsonobj[0].email;
                        var company = jsonobj[0].company;
                        var address = jsonobj[0].address;
                        var postcode = jsonobj[0].postcode;
                        var phonenumber = $("#upgrade_coun").val() + "-" + $("#upgrade_area").val() + "-" + $("#upgrade_phone").val();
                        var paypadid = $("#upgrade_paypal").val();
                        var area = jsonobj[0].area;
                        var sex = jsonobj[0].gender;
                        var ddegree = 2;
                        var mdegree = jsonobj[0].mdegree;
                        var picture = jsonobj[0].picture;
                        var country = jsonobj[0].country;
                        var timezone = jsonobj[0].timezone;
                        var website = jsonobj[0].website;
                        var bankname = $("#upgrade_bankname").val();
                        var billaccount = $("#upgrade_billacc").val();
                        var bankaba = $("#upgrade_aba").val();
                        var bankswift = $("#upgrade_swift").val();
                        var notice1 = jsonobj[0].notice1;
                        var notice2 = jsonobj[0].notice2;
                        var status = jsonobj[0].status;
                        var paymenttype = 0;
                        if ($("#upgrade_payment_bank").is(":checked")) paymenttype = 1;
                        if ($("#upgrade_payment_paypal").is(":checked")) paymenttype = 2;

                        $.ajax({
                            url: serverpath+'/setUserProfile',
                            type: "POST",
                            data: ({
                                action: "setUserProfile",
                                userid: userid,
                                email: email,
                                firstname: firstname,
                                lastname: lastname,
                                nickname: nickname,
                                company: company,
                                phone: phonenumber,
                                timezone: timezone,
                                postcode: postcode,
                                country: country,
                                website: website,
                                bankname: bankname,
                                billaccount: billaccount,
                                notice1: notice1,
                                notice2: notice2,
                                status: status,
                                ddegree: ddegree,
                                mdegree: mdegree,
                                address: address,
                                paypadid: paypadid,
                                area: area,
                                sex: sex,
                                picture: picture,
                                bankaba: bankaba,
                                bankswift: bankswift,
                                paymenttype: paymenttype
                            }),
                            datatype: "JSON",
                            async: false,
                            success: function (data) {
                                if (data.status == "success") {
                                    $("#upgradeResult").attr("innerHTML", "Congratulations, you can upload paid apps now!");
                                    $("#upgrade_result_table").css("display", "block");
                                    $("#upgrade_table").css("display", "none");

                                } else {
                                    $("#upgradeError").attr("innerHTML", "Fail to upgrade your account, please try again later!");
                                }
                            }
                        });
                    }
                }
            });
        }
    });
}

function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

function guid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}

function ismail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (regex.test(email)) return true;
    else return false;
}
