﻿function checkLoginInput()
{

   if($.trim($("#loginUserName").val())=="")
   {
      alert("Please Input Member ID!");
      $("#loginUserName").focus();
      return false;
   }
   
    if($.trim($("#loginPassWord").val())=="")
   {
      alert("Please Input Password!");
      $("#loginPassWord").focus();
      return false;
   }
   
   if($.trim($("#loginSofeCode").val())=="")
   {
      alert("Please Input Security code!");
      $("#loginSofeCode").focus();
      return false;
   }
   
    $.blockUI({
        message:'<h1>Please wate a minute...</h1>',
        css:{ border: 'none',padding: '15px',backgroundColor: '#fff','-webkit-border-radius': '10px','-moz-border-radius': '10px', opacity: .8, color: '#000'}
        });  
       
    setTimeout(submit,2000); 
}

function submit()
{

    $.ajax({
           type:"get",
           url:"/Register/checkUserLogin.ashx",
           data:{"type":"login","loginUserName":$.trim($("#loginUserName").val()),"loginPassWord":$.trim($("#loginPassWord").val()),"loginSofeCode":$.trim($("#loginSofeCode").val()),"rand=":Math.random()},       
           success:function(msg){
               var errorMessage="";
               var success="0";
               switch(msg)
               {
                  case "Sclear":
                     errorMessage="Please refresh the page!";
                     break;
                  case "Serror":
                     errorMessage="Security code is wrong!";
                     break;
                  case "sessionnulll":
                     errorMessage="sessionnull";
                     break;
                  case "-1":
                     errorMessage="Abnormal system error!";
                     break;
                  case "0":
                     errorMessage="Username or password is incorrect!";
                     break;
                  case "1":
                     errorMessage="Username unaudited!";
                     break;
                  case "2":
                     errorMessage="Users are locked!";
                     break; 
                  case "3":
                     errorMessage="Username does not exist!";
                     break;
                  case "off":
                     errorMessage="Server is under maintenance, Please try again later!";
                     break;
                  default:
                     success="1";
                     break;
               }
               
               if(success=="0")
               {
                  alert(errorMessage);
               }
               else
               {
                    location.href='/';
               }
               return false;
           },
           error:function(msg){
                alert(msg);
                location.reload();
           }
           
       });
    $.unblockUI();
}

function changeSofeCode()
{
   document.getElementById("myLoginSofeCodeImg").src=document.getElementById("myLoginSofeCodeImg").src+"?rnd="+Math.random();
}

function searchClick()
{      


   var keyWord=($.trim($("#keyWord").val())).replace(/\s/g,"_");
   //$("#lbl").text(keyWord);

   if(keyWord=="")
   {
      alert("Please input keyword(s)!");
      $("#keyWord").focus();
      return false;
   }
   
   var searchType=$("select[@name='searchType'] option:selected").text();
   //var searchType=$("select[@name='searchType'] option[@selected]").text();
   //alert(searchType);
   var myUrl="";
   
   switch(searchType)
   {
       case "Products":
         myUrl="http://www.china-ogpe.com/search_product_china_"+keyWord+".html";
         break;
       case "Distributors Wanted":
         myUrl="http://www.china-ogpe.com/searchdistributorwanted.aspx?keyWord="+keyWord+"&type=search";
         break;
       case "Trade Offers":
         myUrl="http://www.china-ogpe.com/searchoffer.aspx?keyWord="+keyWord+"&type=search";
         break;
       case "Companies":
         myUrl="http://www.china-ogpe.com/searchcompany.aspx?keyWord="+keyWord+"&type=search";
         break;
        case "Glossary":
         myUrl="http://www.china-ogpe.com/viewglossary.aspx?keyWord="+keyWord+"&type=search";
         break;
       case "Products1":
         myUrl="http://www.china-ogpe.com/search_product_china_"+keyWord+".html";
         break;
       case "Distributors Wanted1":
         myUrl="http://www.china-ogpe.com/searchdistributorwanted.aspx?keyWord="+keyWord+"&type=search";
         break;
       case "Trade Offers1":
         myUrl="http://www.china-ogpe.com/searchoffer.aspx?keyWord="+keyWord+"&type=search";
         break;
       case "Companies1":
         myUrl="http://www.china-ogpe.com/searchcompany.aspx?keyWord="+keyWord+"&type=search";
         break;
        case "Glossary1":
         myUrl="http://www.china-ogpe.com/viewglossary.aspx?keyWord="+keyWord+"&type=search";
         break;
       default:
         myUrl="http://www.china-ogpe.com/search_product_china_"+keyWord+".html";
         break;
   }


   location.href=myUrl;
  
   return false;
}

//产品比较添加收藏夹
function add2Favorite(Type)
{
    var Obj=document.getElementsByName("selectedId");
    
    var myID='';
    
    for(var i=0;i < Obj.length;i++)
    {
       if(Obj[i].checked)
       {
          myID = myID + Obj[i].value+',';
       }
    }
    
    if(myID=="")
    {
       alert("Please Select!");
    }
    else
    {
        $.ajax({
           type:"get",
           url:"/saveCompareFavorites.aspx",
           data:"myID="+myID+"&Type="+Type+"&rand="+Math.random(),
           error:function(){alert("Sorry,Read data error!");},
           success:function(msg){
             if(msg=="No")
             {
                alert("Please login!");
             }
             else if(msg=="Yes")
             {
                alert("Sorry,Did not find the data you want to!");
             }
             else
             {
                alert("Save Data Success!");
             }
           }
        });
    }
}

//search ad product
function advancedProduct()
{
    var keyWord=$.trim($("#word").val());
    //alert(keyWord);
    //$("select[@name='searchType'] option:selected").text();
    var cateID=$("#ctl00_ContentPlaceHolder1_ddlBigProductSort").find("option:selected").val();
    var subCateID=$("#ctl00_ContentPlaceHolder1_ddlSmallProductSort").find("option:selected").val();
    if(keyWord=="")
    {
        alert("Please input keyword");
        return false;
    }
    if(cateID==0)
    {
        alert("Please select catelog");
        return false;
    }
    var PrID=$("#ctl00_ContentPlaceHolder1_ddlprovice").find("option:selected").text();
    if(PrID=="All Provinces")
    {
       PrID="";
    }
    //alert("CatalogID:"+cateID+" ; "+"Smallid:"+subCateID);
    location.href="searchproduct.aspx?keyWord="+keyWord+"&bigSortId="+cateID+"&smallSortId="+subCateID+"&pro="+PrID;
    return false;
}

//search offer
function advancedOffer()
{
   var keyWord=$.trim($("#word").val());
   var cateID=$("#ctl00_ContentPlaceHolder1_ddlBigProductSort").find("option:selected").val();
   //var PrID=$("$ctl00$ContentPlaceHolder1_ddlprovice").find("option:selected").text();
   var smallID=$("#ctl00_ContentPlaceHolder1_ddlSmallProductSort").find("option:selected").val();
       if(keyWord=="")
    {
        alert("Please input keyword");
        return false;
    }
    if(cateID==0)
    {
        alert("Please select catelog");
        return false;
    }
    var PrID=$("#ctl00_ContentPlaceHolder1_ddlprovice").find("option:selected").text();
    if(PrID=="All Provinces" || PrID=="")
    {
       PrID="0";
    }
    location.href="searchoffer.aspx?keyWord="+keyWord+"&bigId="+cateID+"&smallID="+smallID+"&pro="+PrID;
   return false;
}

function advancedDis()
{
   var keyWord=$.trim($("#word").val());
   var PrID=$("#ctl00_ContentPlaceHolder1_ddlprovice").find("option:selected").text();
   if(keyWord=="")
   {
        alert("Please input keyword");
        return false;
    }
    var PrID=$("#ctl00_ContentPlaceHolder1_ddlprovice").find("option:selected").text();
    if(PrID=="All Provinces" || PrID=="")
    {
       PrID="0";
    }
   location.href="searchdistributorwanted.aspx?keyWord="+keyWord+"&pro="+PrID;
   return false;
}

function advancedCom()
{
   var keyWord=$.trim($("#word").val());
   var PrID=$("#ctl00_ContentPlaceHolder1_ddlprovice").find("option:selected").text();
   if(keyWord=="")
   {
        alert("Please input keyword");
        return false;
    }
    
   if(PrID=="All Provinces")
   {
      PrID="0";
   }
   
   if(PrID=="")
   {
      PrID="0";
   }

   //location.href="searchcompany.aspx?keyWord="+keyWord+"&PrID="+PrID;
   location.href="searchcompany.aspx?keyWord="+keyWord+"&pro="+PrID;
   return false;
}
