var HOST_HTTPS_DIR = "https://www.mo-call.hk";
var HOST_DIR = "https://www.mo-call.hk";
//var HOST_HTTPS_DIR = "http://mocallhk.morodocn.com";
//var HOST_DIR = "http://mocallhk.morodocn.com";

var $ = function(id) { return document.getElementById(id); }

var xmlhttp = false;

try { // Firefox, Opera 8.0+, Safari
 xmlhttp = new XMLHttpRequest();
}catch (e) {
 try { // Internet Explorer >=5.0
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 }catch (e) {
    try { // Internet Explorer <5.0
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch (e) {// Do not support AJAX
      alert("Your browser does not support AJAX!");
      //return false;
    }
 }
}

//By Shelley
function showstatechange (cobj)
{
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      cobj.innerHTML = xmlhttp.responseText;
   }
}

//By Shelley
function searchfaq (searchText)
{
   var serverPage = 'searchfaq.php?text=' + searchText;
   var obj = $("searchResult");

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

//By Shelley
function getrates(objID, serverPage)
{
   var obj = $(objID);
   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

//By Shelley
function getCharRates(chr)
{
  var obj = $("listrates");
  var serverPage = "listrates.php?chr=" + chr;

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

//By Shelley
function showCSC()
{
  var obj = $("showCSC");
  var serverPage = "ajax_csc_intro.php";

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

//By Shelley
function showCSCTopup()
{
  var obj = $("showCSC");
  var serverPage = "../shop/ajax_csc_intro.php";

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

//By Shelley
function generateOrderID(obj)
{
  var serverPage = "ajax_gen_orderid.php";

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 &&  xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
         return false;
      }
      return false;
   }
   xmlhttp.send(null);
}


function resendActivationCode() {
   var serverPage = "ajax_resendActivatinCode.php";

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 &&  xmlhttp.status == 200) {
         $('resendResult').innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);

   $('resendSubmit').disabled = true;
}

//By Shelley
function checkSubmitResult (str)
{
   var obj = $("checkresult");
   var serverPage = "ajax_shopprocess.php";
   alert('Going to payment...');
   xmlhttp.open("POST", serverPage, true);
   xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   //xmlhttp.setRequestHeader("Content-length", str.length);
   xmlhttp.onreadystatechange = function()
   {
      var redP = '<p style="text-align: center; font-weight: bold; color: #FF0000;">';
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
      {
         switch(xmlhttp.responseText)
         {
            case 'N':
                $("checkresult").innerHTML = '<font color="#698293">Successfully Payed. Redirecting ...</font>';
                document.location = 'shopresult.php';
                break;
            case 'I':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, there is some problem generating your order id.<br />Please try to shop again.</p>';
               break;
            case 'C':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, there is some error while SSL Certificate.<br />Please try to shop again.</p>';
               break;
            case 'A':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, there are some mistakes of your Credit Card informatin.<br />Please check.</p>';
               break;
            case 'D':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, process is declined. Please try again.</p>';
               break;
            case 'E':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, the API failed to process this order. Please try again.</p>';
               break;
            case 'F':
               $('submitbutton').disabled = false;
               $("checkresult").innerHTML = redP + 'Sorry, there are some mistakes of your Credit Card informatin. Please check.</p>';
               break;
            case 'U':
               $("checkresult").innerHTML = redP + 'Unknown error ocurred. Please try a new shop.</p>';
               break;
         }

      }
      return false;
   }

   xmlhttp.send(str);
}

// By shelley
function showManual(osType, id)
{
  if (id == '5'){
	 // insertFlash('manual_flash', '../flash/manual_uiq.swf', 550,650 );
    window.location.reload();
     return false;
  }

  var obj = $("manual_flash");
  var serverPage = "ajax_show_manual.php?os=" + osType + "&id=" + id;

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         obj.innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}

function Login_moCall(type)
{
	alert(type);
	if(type == "download")
	{
	  document.frm9.action = HOST_DIR+'/user/login_do.php?erro=from';
      document.frm9.submit();
	}
	else
	{
		document.frm9.action = HOST_DIR+'/shop/login_shop.php';
		document.frm9.submit();
	}
}
function KeyDown_Login_moCall(e){
	if(window.event){
		keynum = e.keyCode;
	}else if(e.which){
		keynum = e.keyCode;
	}

	if(keynum==13){
		Login_moCall('shop');
	}
}
function KeyDownNewReg(e){
	if(window.event){
		keynum = e.keyCode;
	}else if(e.which){
		keynum = e.keyCode;
	}

	if(keynum==13){
		document.frm2.action = '/user/login_do.php';
		document.frm2.submit();
	}
}function LoginNewReg(){
	document.frm2.action = '/user/login_do.php';
	document.frm2.submit();
}
