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

function sendVideoChatInvitation(nickName,culture){
    
    $.post(
        "/sendmsg?type=1&nickname="+nickName+"&video=1",
        function(data){
           if(data.indexOf("done:")==0){
              if(culture=="en"){
                alert ("Your video chat invitation has been sent to "+nickName+" succesfully, please wait for "+nickName+" to accept your invitation");
              }else{
                alert ("您的视频聊天邀请已经成功发送给"+nickName+"，请等待"+nickName+"接受您的邀请并开始在线视频聊天。");
              }
           }else if(data=="duplicated"){
              if(culture=="en"){
                alert ("Please wait patiently for " +nickName+ " to accept your online video chat invitation and not sending the same invitation repeatedly, otherwise you may be blocked by "+nickName+" and can no longer contact with each other.");
              }else{
                alert ("请耐心等待"+nickName+"接受您的视频聊天邀请，不要重复多次发送同一邀请，否则您有可能被"+nickName+"列入屏蔽名单并无法继续保持联系。");
              }
           }else{
              if(culture=="en"){
                alert ("You can not video chat with "+nickName+" currently due to following reason:\n\n "+data);
              }else{
                alert ("由于以下原因您暂时无法与"+nickName+"进行在线视频聊天：\n\n"+data);
              }
           } 
        }               
       );
}

function sendTextChatInv(nickName,culture){
     
     $.post(
        "/sendmsg?type=1&nickname="+nickName,
        function(data){
           if(data.indexOf("done:")==0){
              if(culture=="en"){
                alert ("Your chat invitation has been sent to "+nickName+" succesfully, please wait for "+nickName+" to accept your invitation");
              }else{
                alert ("您的聊天邀请已经成功发送给"+nickName+"，请等待"+nickName+"接受您的邀请并开始在线聊天。");
              }
           }else if(data=="duplicated"){
              if(culture=="en"){
                alert ("Please wait patiently for " +nickName+ " to accept your chat invitation and not sending the same invitation repeatedly, otherwise you may be blocked by "+nickName+" and can no longer contact with each other.");
              }else{
                alert ("请耐心等待"+nickName+"接受您的聊天邀请，不要重复多次发送同一邀请，否则您有可能被"+nickName+"列入屏蔽名单并无法继续保持联系。");
              }
           }else{
              if(culture=="en"){
                alert ("You can not chat with "+nickName+" currently due to following reason:\n\n "+data);
              }else{
                alert ("由于以下原因您暂时无法与"+nickName+"进行在线聊天：\n\n"+data);
              }
           } 
        }               
       );
    
    
}




function sendChatInvitation(nickName,culture,video){

  if(video==1){    
    
      var str=culture=="zh"?"您希望进行视频聊天吗？此项服务需要聊天双方至少有一方为白金会员。\n\n点击OK进行视频聊天，点击Cancel前往普通聊天室。":"Do you want to use our Video Chat Service? This requires at least one part must be Platinum Member.\n\nClick OK to go to Video Chart Room, Cancel to go to Regular Text Chat Room.";
      if(confirm(str)){
          sendVideoChatInvitation(nickName,culture);
      }else{
          sendTextChatInv(nickName,culture);
      }

   }else{
    sendTextChatInv(nickName,culture);
   }
}

function PopUpIsBlocked(culture){
   var mine = window.open("about:blank","","directories=no,height=10,width=10,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
   if(mine){
         var popUpsBlocked = false;   
         mine.close();  
   }   
   else{
       if(culture=="zh"){
        var str="本网站的某些功能需要使用弹出式窗口，但您的浏览器已经对我们的弹出窗口进行了拦截。请解除对弹出窗口的拦截或添加本网站至排除列表。\n\nFireFox用户可以选择工具->选项->内容，并对拦截弹出窗口设置进行更改。\nIE用户可选择工具->弹出窗口拦截->弹出窗口拦截设置，以变更其设置。\n\n其他浏览器请参照其在线帮助。";      }else{
        var str="Our website is using pop-up window to provide some services, but it has been blocked by your browser. Please turn off pop-up blocker or add our website to the exception list of the pop-up blocker.\n\nFor Firefox users, please go to Tools->Options->Content and edit pop-up blocker setting.\nFor IE users, please go to Tools->Pop-up Blocker->Pop-up Blocker Settings and change the configuration.\n\nFor all the other browsers, please refer to online help." 
      }
       alert (str);
       var popUpsBlocked = true 
   }    
   return popUpsBlocked;
}

function openchatwindow(url){
        
         window.open(url,'',"location=0,status=0,scrollbars=0,width=300,height=420,toolbar=0,menubar=0,directories=0,resizable=1");  
}
 
 
function openvideochatwindow(url){
         if(getScreenWidth()<1100){
             window.open(url,'',"location=0,status=0,scrollbars=0,width=1020,height=820,toolbar=0,menubar=0,directories=0,resizable=1");   
         }else{
             window.open(url,'',"location=0,status=0,scrollbars=0,width=1040,height=820,toolbar=0,menubar=0,directories=0,resizable=1");  
         }
         
} 
 

// script by Josh Fraser (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/)

function calculate_time_zone() {
    var rightNow = new Date(); 
    var temp = rightNow.toGMTString();   
    var rightNowGMT = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));     
    var std_time_offset = rightNow - rightNowGMT ;
    return std_time_offset;
    }             
    
   
   
 //get standardarid zip code  
 

 function checkPostCodeValidity(postcode,countryName)

  {   

        if(countryName=="CA")
              
        {
            postcode=postcode.replace(" ","");

            var regPatern=/^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/;

            if(regPatern.test(postcode))
            {      
                    postcode=postcode.substr(0,3)+" "+postcode.substr(3,3);
                     
                    return postcode.toUpperCase();

            }else

            {      
                    return false;

            }

        }

        
        if(countryName=="CN")

        {

            var regPatern=/(^\d{6,6}$)/;

            if(regPatern.test(postcode))

            {     

                     return postcode.toUpperCase();   

            }else

            {

                    return false;

            }

        }
        
        

        if(countryName=="US")

        {

            var regPatern=/(^\d{5,5}$)|(^\d{5}-\d{4}$)/;

            if(regPatern.test(postcode))

            {     

                     return postcode.toUpperCase();   

            }else

            {

                    return false;

            }

        }

        

         if(countryName=="AU")

        {

            var regPatern=/(^\d{3,4}$)/;

            if(regPatern.test(postcode))

            {     

                     return postcode.toUpperCase();   

            }else

            {

                    return false;

            }

        }

        

        if(countryName=="GB")

        {

                

                 // Permitted letters depend upon their position in the postcode.

                  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1

                  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2

                  var alpha3 = "[abcdefghjkstuw]";                                // Character 3

                  var alpha4 = "[abehmnprvwxy]";                                  // Character 4

                  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5





                  // Array holds the regular expressions for the valid postcodes

                  var pcexp = new Array ();



                  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA

                  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));



                  // Expression for postcodes: ANA NAA

                  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));



                  // Expression for postcodes: AANA  NAA

                  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));



                  // Exception for the special postcode GIR 0AA

                  pcexp.push (/^(GIR)(\s*)(0AA)$/i);



                  // Standard BFPO numbers

                  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);



                  // c/o BFPO numbers

                  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);



                  // Load up the string to check

                  var postCode = postcode;



                  // Assume we're not going to find a valid postcode

                  var valid = false;



                      // Check the string against the types of post codes

                      for ( var i=0; i<pcexp.length; i++) {

                        if (pcexp[i].test(postCode)) {



                          // The post code is valid - split the post code into component parts

                          pcexp[i].exec(postCode);



                          // Copy it back into the original string, converting it to uppercase and

                          // inserting a space between the inward and outward codes

                          postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();



                          // If it is a BFPO c/o type postcode, tidy up the "c/o" part

                          postCode = postCode.replace (/C\/O\s*/,"c/o ");



                          // Load new postcode back into the form element

                          valid = true;



                          // Remember that we have found that the code is valid and break from loop

                          break;

                        }

                      }



                      // Return with either the reformatted valid postcode or the original invalid

                      // postcode

                      if (valid) {return postCode;} else return false;

                 

        }

       

        return postcode.toUpperCase();

  }
  
   
        function thisMovie(movieName) {
             if (navigator.appName.indexOf("Microsoft") != -1) {
                 return window[movieName];
             } else {
                 return document[movieName];
             }
        }

        function makeSound(looptime,name){
             thisMovie("mysound").callFlashSound(looptime,name);
        }                       


           function getScreenWidth(){
                var x,y;
                if (self.innerHeight) // all except Explorer
                {
                    x = self.innerWidth;
                    y = self.innerHeight;
                }
                else if (document.documentElement && document.documentElement.clientHeight)
                    // Explorer 6 Strict Mode
                {
                    x = document.documentElement.clientWidth;
                    y = document.documentElement.clientHeight;
                }
                else if (document.body) // other Explorers
                {
                    x = document.body.clientWidth;
                    y = document.body.clientHeight;
                }
                return x;
}

function getScreenHeight(){
             var x,y;
                if (self.innerHeight) // all except Explorer
                {
                    x = self.innerWidth;
                    y = self.innerHeight;
                }
                else if (document.documentElement && document.documentElement.clientHeight)
                    // Explorer 6 Strict Mode
                {
                    x = document.documentElement.clientWidth;
                    y = document.documentElement.clientHeight;
                }
                else if (document.body) // other Explorers
                {
                    x = document.body.clientWidth;
                    y = document.body.clientHeight;
                }
                return y;
}
        