
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!");
    }
 }
}

function showstatechange (cobj)
{
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      cobj.innerHTML = xmlhttp.responseText;
   }
}

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);
}

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);
}

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);
}

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);
}

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);
}

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 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);
}



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;
}

function showManual(osType, id)
{
  if (id == '5'){
    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 web_mocall_number_source(NumType,keyValue,DesID)
{
  var serverPage = "web_mocall_number_source.php?NumType="+NumType+'&keyValue='+keyValue;

   xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 &&  xmlhttp.status == 200) {
         document.getElementById(DesID).innerHTML = xmlhttp.responseText;
         return false;
      }
      return false;
   }
   xmlhttp.send(null);

}
function addTelephoneBook(objID, serverPage)
{
	xmlhttp.open("GET", serverPage);
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      	var returnvalue = xmlhttp.responseText;

      	if(returnvalue=='Success'){
      		document.getElementById("bgDiv").style.display="none";
      		document.getElementById("msgDiv").style.display="none";
      		document.getElementById("msgTitle").style.display="none";
      	}else{
      		document.getElementById('td_returnContent').innerHTML = '<font color="red">'+returnvalue+'</font>';
      	}

      }
   }
   xmlhttp.send(null);
}

function Login_moCall(type)
{
	if(type == "download")
	{
	  document.frm9.action = HOST_DIR+'/user/login_do.php?erro=from';
      document.frm9.submit();
	}
	else
	{
		document.frm9.action = HOST_HTTPS_DIR+'/shop/login_shop.php?erro=shop';
		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');
	}
}



/////////////Help Ajax///////////////////////////////

function changebg(id,Color) {
	    document.getElementById(id).style.background = Color;
	}
function changeborder(id,Color) {
	    document.getElementById(id).style.border = Color;
	}
function setvalue(id){
	document.getElementById(id).value = '';
}
function show_handset_do(serverPage,type)
{	
	document.getElementById('Model_list').innerHTML ='<select class="MoInput" style="width:150px;" name="Model" id=""><option value="">Processing...</option></select>';
	xmlhttp.open("GET", serverPage);
   	xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      	if(type == '1'){
      		document.getElementById('Model_list').innerHTML = xmlhttp.responseText;
      	}if(type == '2'){
      		document.getElementById('Model_list2').innerHTML = xmlhttp.responseText;
      	}//else{
      		//document.getElementById('FAQ_content').innerHTML = xmlhttp.responseText;
      	//}
      }
   }
   xmlhttp.send(null);
}

function show_faq_do(serverPage,type)
{	
	xmlhttp.open("GET", serverPage);
   	xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      	if(type == '3'){
      		document.getElementById('FAQ_content').innerHTML = xmlhttp.responseText;
      	}
      }
   }
   xmlhttp.send(null);
}

function ajax_do_handset(serverPage)
{	
	xmlhttp.open("GET", serverPage);
   	xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      		document.getElementById('search_h_videos').innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}
function ajax_do_platform(serverPage)
{	
	xmlhttp.open("GET", serverPage);
   	xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      		document.getElementById('search_p_videos').innerHTML = xmlhttp.responseText;
      }
   }
   xmlhttp.send(null);
}


function showlist(id){
	var lid = 't_'+id;
	var hid = document.getElementById('H_list').value;
	var mid = document.getElementById('M_list').value;
	var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid='+mid;
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display ='block';
		window.location.href = url;
	}else{
		document.getElementById(id).style.display ='none';
	}
}

function showlistBak(id){
	var lid = 't_'+id;
	var hid = document.getElementById('H_list').value;
	var mid = document.getElementById('M_list').value;
	var signPlus = document.getElementById("plus");
    var signMinus = document.getElementById("minus");
	var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid='+mid;
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display ='block';
		window.location.href = url;
		signPlus.style.display = 'none';
        signMinus.style.display = 'block';
	}else{
		document.getElementById(id).style.display ='none';
		signMinus.style.display = 'none';
        signPlus.style.display = 'block';
	}
	
	
}

function change_state(hv){
	var signPlus = document.getElementById("plus");
    var signMinus = document.getElementById("minus");
    
    if(signMinus.style.display=="none")
    {
      signPlus.style.display = 'none';
      signMinus.style.display = 'block';
    }
    else
    { 
      signMinus.style.display = 'none';
      signPlus.style.display = 'block';
    }
}

function showplatform(id){
	var lid = 't_'+id;
	var signPlus = document.getElementById("plus");
    var signMinus = document.getElementById("minus");
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display ='block';
		signPlus.style.display = 'none';
        signMinus.style.display = 'block';
	}else{
		document.getElementById(id).style.display ='none';
		signMinus.style.display = 'none';
        signPlus.style.display = 'block';
	}
}

function showplatformBak(id){
	var lid = 't_'+id;
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display ='block';
	}else{
		document.getElementById(id).style.display ='none';
	}
}

function showchat(id){
	if(id == 'chat'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('email').style.display = 'none';
		document.getElementById('phone').style.display = 'none';
		document.getElementById('left_chat').style.background = '#E3EEF2';
		document.getElementById('left_email').style.background = '#FFFFFF';
		document.getElementById('left_phone').style.background = '#FFFFFF';
		document.getElementById('left_span_chat').style.color = '#D5273F';
		document.getElementById('left_span_email').style.color = '#63B8C7';
		document.getElementById('left_span_phone').style.color = '#63B8C7';
	}else if(id == 'email'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('chat').style.display = 'none';
		document.getElementById('phone').style.display = 'none';
		document.getElementById('left_chat').style.background = '#FFFFFF';
		document.getElementById('left_email').style.background = '#E3EEF2';
		document.getElementById('left_phone').style.background = '#FFFFFF';
		document.getElementById('left_span_chat').style.color = '#63B8C7';
		document.getElementById('left_span_email').style.color = '#D5273F';
		document.getElementById('left_span_phone').style.color = '#63B8C7';
	}else{
		document.getElementById(id).style.display = 'block';
		document.getElementById('email').style.display = 'none';
		document.getElementById('chat').style.display = 'none';
		document.getElementById('left_chat').style.background = '#FFFFFF';
		document.getElementById('left_email').style.background = '#FFFFFF';
		document.getElementById('left_phone').style.background = '#E3EEF2';
		document.getElementById('left_span_chat').style.color = '#63B8C7';
		document.getElementById('left_span_email').style.color = '#63B8C7';
		document.getElementById('left_span_phone').style.color = '#D5273F';

	}
}

function show_info(id){
	var mid = id;
	var hid = '';
	document.getElementById('main_videos').style.display = 'none';
	document.getElementById('search_h_videos').style.display = 'block';
	var serverpage = 'ajax_sarech_handset.php?hid='+hid+'&mid='+mid;
	ajax_do_handset(serverpage);
}
function show_faq_text(link){
	var serverpage = '../FAQs/'+link;
	//var id = 'left_'+link;
	var arry = new Array('My Account','Top-up','Registration','Payment and Billing','Tips and Tricks','MO-Call General','MO-Call Download','Mobile Internet','Roaming','mobile-troubleshooting','MO-Call PC General','MO-Call PC Download','Instant Messaging','Making Calls','pc-troubleshooting');
	var len = arry.length;
	for(var i=0;i<len;i++){
		if(arry[i] == link){
			//alert('left_'+arry[i]);
			//document.getElementById('left_'+arry[i]).className ='currentFaqs';
			document.getElementById('left_'+arry[i]).style.background = '#E3EEF2';
			document.getElementById('left_'+arry[i]).style.color = '#ff99cc';
		}else{
			document.getElementById('left_'+arry[i]).style.background = '#FFFFFF';
			document.getElementById('left_'+arry[i]).style.color = '#63B8C7';
		}
	}
	show_faq_do(serverpage,'3');
	
}

function show_handset(mid,type){
	var serverpage = 'ajax_show_handset.php?mid='+mid+'&type='+type;
	show_handset_do(serverpage,type);
}
function do_handset(id){
	if(id == '1'){
		var hid = document.getElementById('H_list').value;
		var mid = document.getElementById('M_list').value;
		if(hid!='' && mid!=''){
			document.getElementById('main_videos').style.display = 'none';
			document.getElementById('search_h_videos').style.display = 'block';
			var serverpage = 'ajax_sarech_handset.php?hid='+hid+'&mid='+mid;
			ajax_do_handset(serverpage);
		}
	}else{
		var hid = '';
		var mid = document.getElementById('M2_list').value;
		var m_type = document.getElementById('model_type').value;
		if(mid!=''){
			hid = document.getElementById('H2_list').value;
		}
		if(m_type == 'Type Model Here'){
			m_type = '';
		}
		//alert(m_type);
			var serverpage = 'ajax_sarech_handset.php?hid='+hid+'&mid='+mid+'&type='+m_type;
			ajax_do_handset(serverpage);
		
	}
}
function do_platform(){
	var pid = document.getElementById('platformid').value;
	if(pid != ''){
		var url = 'playvideo.php?pid='+pid;
		window.location.href = url;
	}else{
		window.location.href = 'platform.php';
	}
}
function show_Man(link){
	window.location.href = link;
}
function search_handset(){
	var hid = document.getElementById('H_list').value;
	var mid = document.getElementById('M_list').value;
	if(mid != ''){
		if(hid != ''){	
			var pid = hid.split('_');
			var mid = document.getElementById('M_list').value;
			var url = 'playvideo.php?HandsetID='+pid[0]+'&HandsetName='+pid[1]+'&MID='+pid[2]+'&platform_id='+pid[3];
			//var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid='+mid;
			//var url = 'playvideo.php?mn='+mid+'&pid='+pid[1];
			window.location.href = url;
		}else{
			 var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid='+mid;
			 window.location.href = url;
			}
	}else{
	    alert("Please select a manufacturer and model.");
	}
	//if(hid !=''){
	//	var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid=';
	//	window.location.href = url;
	//}
}
function Find_Handset(){
	var keyword = document.getElementById('ModelLike').value;
    url = 'search_handset.php?ModelLike=' + keyword;
	window.location.href = url;
}
function go_platform(){
	window.location.href = 'platform.php';
}




/*------ways ajax-----*/
function show_handset_ways(mid){
	var serverpage = 'ajax_show_handset_ways.php?mid='+mid;
	show_handset_ways_do(serverpage);
}

function show_handset_ways_do(serverPage){	
	document.getElementById('H_list').innerHTML ='<option value="">Processing...</option>';
	xmlhttp.open("GET", serverPage);
   	xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var handsets = xmlhttp.responseText;
			var hlistObj = document.getElementById('H_list');
			var hids = new Array();
			var hands = handsets.split('|@|');
			for(var i=0;i<hands.length-1; i++){
				var hs = hands[i].split('__');
				hlistObj.options[i]=new Option(hs[1],hs[0]); 
			}
      }
   }
   xmlhttp.send(null);
}

/*------softwaredownloads ajax-----*/
function showManufacturer(id){
	//var lid = 't_'+id;
	//var hid = document.getElementById('H_list').value;
	//var mid = document.getElementById('M_list').value;
	//var url = 'index.php?HandsetID='+hid+'&ModelLike=&mid='+mid;
	if(document.getElementById(id).style.display == 'none'){
		document.getElementById(id).style.display ='block';
		//window.location.href = url;
	}else{
		document.getElementById(id).style.display ='none';
	}
}



function MouseOverColor(method,servicename,play) {
	document.getElementById(method).className ='playvideoMouseOver';
	document.getElementById(servicename).className ='serviceNameOver';
	document.getElementById(play).className ='playOver';
}
function MouseOutColor(method,servicename,play) {
	document.getElementById(method).className ='playvideoMouseOut';
	document.getElementById(servicename).className ='serviceNameOut';
	document.getElementById(play).className ='playOut';
}
