
function getCategorynext(id) {
    var parentid = $("#"+id).val();
    // var spanid =
    /*if (parentid =='') {
        $("#"+id+"span").html("");
        return false;
    }*/
    $.post("./getallinfo.php", { parentid:parentid,id:id},
    function(data){
        //alert(data);
        if (data != 0) {
             //$("#"+id+"span").html("");
            $("#"+id+"span").html(data);
        }/*else {
            $("#"+id+"span").html("");
        }*/
    });
}
function getaaaa(selectid) {
    var parentid  = $("#"+selectid).val();
    //alert(parentid);
    /*if (parentid =='') {
        $("#"+spanid +"next").html("");
        return false;
    }*/
    var spanidarray =selectid.split('_');
    var spanid = spanidarray[0];
    //alert(spanid);
    $.post("./getcategory.php", { parentid:parentid,id:selectid},
     function(data){
        //alert(data);
        if (data != 0) {
            $("#"+spanid +"next").html(data);
        }/*else {
            $("#"+spanid +"next").html("");
        }*/
    });
}
function getlocation(selectid) {
    //alert('good');
    var parentid  = $("#"+selectid).val();
    /*if (parentid =='') {
        $("#"+spanid +"next").html("");
        return false;
    }*/
    //alert(parentid);
    var spanidarray =selectid.split('_');
    var spanid = spanidarray[0];
    //alert(spanid);
    $.post("./getlocation_next.php", { parentid:parentid,id:selectid},
     function(data){
        //alert(data);
        if (data != 0) {
            $("#"+spanid +"next").html(data);
        } /*else {
            $("#"+spanid +"next").html("");
        }*/
    });
}



function getLocationnext(id) {
    var parentid = $("#"+id).val();
   /* if (parentid =='') {
         $("#"+id+"span").html("");
        return false;
    }*/
    // var spanid =
    $.post("./getlocation.php", { parentid:parentid,id:id},
    function(data){
        //alert(data);
        if (data != 0) {
            $("#"+id+"span").html(data);
        }/*else {
             $("#"+id+"span").html("");
        }*/
    });
}

function submitinfo() {
    //var buyertype = $(":radio:checked").val();
    var buyertype = $(":radio[name='BuyerType']:checked").val();
    var companyname = $("#companyname").val();
    var username = $("#username").val();
    var el = document.getElementsByTagName('select');
    var len = el.length;
    for (var i=2; i<len; i++) {
        var v = el[i].value;
        if (v  == 1 || v == 2) {
            var category = el[i-1].value;
            //alert(category);
            break;
        }
    }
    var location = el[len-1].value;
    //alert(location);
    var address = $("#address").val();
    var contactname =$("#contactname").val();
    var contactname1 ="";
    var contactname2 = $("#contactname2").val();
    if ($("#sex").val() == 1) contactname1 = "Mr";
    else contactname1 = "Miss";
    var contactitle = contactname2;
    var sex = $("#sex").val();
    var phone1 = $("#phone1").val();
    var phone2 = $("#phone2").val();
    var phone3 = $("#phone3").val();
    var phone = phone1+"-"+phone2+"-"+phone3 ;
    var fax1 = $("#phone12").val();
    var fax2 = $("#phone22").val();
    var fax3 = $("#phone23").val();
    var fax =fax1+"-"+fax2+"-"+fax3;
    var msn = $("#msn").val();
    var skype = $("#skype").val();
    var website = $("#website").val();
    var introduce = $("#introduce").val();
	$.post("./update_buyer.php", { Username:username,
	                               BuyerType:buyertype,
	                               CompanyName:companyname,
								   Category:category,
								   Address:address,
								   ContactName:contactname,
								   ContacTitle:contactitle,
								   Phone:phone,
								   Fax:fax,
								   Sex:sex,
								   LocationId:location,
								   Msn:msn,
								   Skype:skype,
								   Website:website,
								   Introduce:introduce
	},function(data) {
		 alert(data);
		 $("#editprofile").click();
		//$("#as").html(data);
	});
}

function sendbuyinglead() {
    // alert("sssss");
    var bdays = $("#bdays").val();
    var title = $("#title").val();
	var Keyword1 = $("#Keyword1").val();
	var Keyword2 = $("#Keyword2").val();
	var Keyword3 = $("#Keyword3").val();
    //alert(title);
    var description = $("#description").val();
    //var pic1 =$("#pic1").val(); 
    var el = document.getElementsByTagName('select');
    var len = el.length;
    var category = el[len-1].value; 
    if(title == "") {
        alert("Please enter subject!");
        //exit;
        return false;;
    }
	if(Keyword1 == "" && Keyword2 == "" && Keyword3 == "") {
        alert("Please enter a keyword!");
        //exit;
        return false;;
    }
	
    if(description == "") {
        alert("Please enter description!");
        //exit;
        return false;
    }
    if (category == "") {
        alert("Please select the category");
    } else{
        $.post("./sendbuyinglead.php", { AvailableDays:bdays,Title:title,Description:description,Category:category,Keyword1:Keyword1,Keyword2:Keyword2,Keyword3:Keyword3},
        function(data) {
            if (data == 1) {
                alert('Saves successfully!');
                $("#myinquiries").click();
            }else {
                eval(data);
            }
        });
    }
}

function login_sendbuyinglead() {
    // alert("sssss");
    var bdays = $("#bdays").val();
    var title = $("#title").val();
    //alert(title);
    var description = $("#description").val();
    //var pic1 =$("#pic1").val(); 
    var el = document.getElementsByTagName('select');
    var len = el.length;
    var category = el[len-2].value; 
    if (category == "") {
        alert("Please select the category!");
    } else{
        $.post("./sendbuyinglead.php", { AvailableDays:bdays,Title:title,Description:description,Category:category},
        function(data) {
            if (data == 1) {
                alert('Saves successfully!');
                location.href = './index.php';
            }else {
                eval(data);
            }
        });
    }
}
function deleteinboxchecked (name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deleteinbox.php", { id:numstr},
            function(data){
                //alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                $("#Inbox").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}

function deleteiInboxById (num) {
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deleteinbox.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                     $("#Inbox").click();
                }else {
                    alert("false");
                }
            });
        }else {

        }
    }
}
function replyinbox(num) {
    //alert(num);
    var num = num;
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to edit it !")) {
            $.post("./editinbox.php", {id:num},function(data){
                //alert(data);
                $("#mydiv").html(data);});
        }else {

        }
    }

}
function updateInbox(num) {
    //alert(num);
    var title = $("#title").val();
    var message = $("#message").val();
    var replynow = $("#replynow").val();
    if (replynow == ''){
        alert(" The replynow must't be empty!");
    }
    else {
        if (window.confirm("ready to reply it !")) {
            $.post("./updateeditinbox.php", {title:title ,message:message ,replynow:replynow ,id:num},function(data){
                //alert(data);
                if (data == 1) {
                    alert("post successfully!");
                    $("#Inbox").click();
                }             
            });
        }else {

        }
    }   
}

function deletesentmessagechecked(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deletesentmessage.php", { id:numstr},
            function(data){
                alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                     $("#sentmessage").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}
function deletesentmessageById (num) {
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deletesentmessage.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                    $("#sentmessage").click();
                }else {
                    alert("false");
                }
            });
        }else {
        }
    }
}

function viewsentmessage(num) {
    //alert(num);
    var num = num;
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to edit it !")) {
            $.post("./viewsentmessage.php", {id:num},function(data){
                //alert(data);
                $("#mydiv").html(data);});
        }else {

        }
    }

}

function deletecompany(num){
    //alert(num);
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deletecompany.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                    $("#collectioncompany").click();
                }else {
                    alert("false");
                }
            });
        }else {
        }
    }
}

function deletecompanybychecked(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deletecompany.php", { id:numstr},
            function(data){
                //alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                     $("#collectioncompany").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}

function deleteproduct(num){
    //alert(num);
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deletecompany.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                    $("#collectionproduct").click();
                }else {
                    alert("false");
                }
            });
        }else {
        }
    }
}

function deleteproductbychecked(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deletecompany.php", { id:numstr},
            function(data){
                //alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                     $("#collectionproduct").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}


function deletesellinglead(num){
    //alert(num);
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deletecompany.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                    $("#collectionsellinglead").click();
                }else {
                    alert("false");
                }
            });
        }else {
        }
    }
}

function deletesellingleadbychecked(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deletecompany.php", { id:numstr},
            function(data){
                //alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                     $("#collectionsellinglead").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}



function deletecollectionbuyinglead(num){
    //alert(num);
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deletecompany.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                    $("#collectionbuyinglead").click();
                }else {
                    alert("false");
                }
            });
        }else {
        }
    }
}

function deletebuyingleadbychecked(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    //alert(numstr);
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deletecompany.php", { id:numstr},
            function(data){
                //alert(data);
                 if (data == 1){
                     alert("delete successfully! ");
                     $("#collectionbuyinglead").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}

function sendemail_seller() {
    var email = $("#email").val();
    //alert(username);
    //alert("ssss");
    if (email == '') {
        alert("Please input your email address!");
    }else {
        $.post("./sendemail_seller.php",{email:email},function (data) {
			$("#infos").html(data);
        })       
    }
}
function getreturn(name) {
    if (name =="editprofile" ) {
        $("#editprofile").click();
    }
    if (name =="postnewinquiry" ) {
        $("#myinquiries").click();
    }
    if (name =="editinbox" ) {
        $("#Inbox").click();
    }
    if (name =="eidtinquiry" ) {
        $("#myinquiries").click();
    }
    if (name =="viewsentmessage" ) {
        $("#sentmessage").click();
    }
    if (name =="editproduct" ) {
        $("#Productslist").click();
    }
    if (name =="postnewproduct" ) {
        $("#PostNewProduct").click();
    }
}
function clearaddress() {
    $("#pic1").val("") ;
}

function deleteproductlistchecked (name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    var numstr = '';
    for (var i=0; i<len; i++) {
        if ((el[i].type=="checkbox") && (el[i].name==name) && (el[i].checked == true)) {
            var num= el[i].value;
            numstr =numstr+num+"_";
        }
    }
    if (numstr != ""){
        if (window.confirm("ready to delete it or them !")){
            $.post("./deleteproduct.php", { id:numstr},
            function(data){
                 if (data == 1){
                     alert("delete successfully! ");
                $("#Productslist").click();
                }
            });
        }else {
            //alert("good");
        }
    }
}
function deleteproductlistById (num) {
    var num = num;
    //alert(num);
    if( num == ''){
        alert("there is no data!");
    }
    else {
        if (window.confirm("ready to delete it !")) {
            $.post("./deleteproduct.php", {id:num},function(data){
                //alert(data);
                if (data == 1){
                    alert("delete successfully!");
                     $("#Productslist").click();
                }else {
                    alert("false");
                }
            });
        }else {

        }
    }
}