var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){ alert ("GET FAIL");}
    }
  }
  else
    return false
  page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
  }
  page_request.open('GET', url, true)
  page_request.send(null)
}

function addrandom(url){

  var ran_number=Math.floor(Math.random()*5000);
 var newUrl;
  qp=url.indexOf("?");
 if ( qp == -1  ){
    newUrl=url+"?"+ran_number;
 }else{
    newUrl=url+"&"+ran_number;
 }
 return newUrl;
}

function ajaxpagepost(url, containerid,formid){
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){ alert ("GET FAIL");}
    }
  }
  else
    return false
  page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
  }

  page_request.open('POST', url, true)
  page_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  var qs=setQueryString(formid)
  page_request.send(qs)
}

function setQueryString(formid){
    var queryString="";
    frm = document.getElementById(formid);
    var numberElements =  frm.elements.length;
    for(var i = 0; i < numberElements; i++)  {
            if(i < numberElements-1)  {
                queryString += frm.elements[i].name+"="+
                               encodeURIComponent(frm.elements[i].value)+"&";
            } else {
                queryString += frm.elements[i].name+"="+
                               encodeURIComponent(frm.elements[i].value);
            }

    }
   return queryString;
}

function CreateDiv() {
    //取得主頁面body的物件
    var bobj = parent.document.body;
    var bodyHeight = bobj.scrollHeight;
    var bodyWidth = bobj.scrollWidth;

    var newdiv=document.createElement('div');
    newdiv.id="haha";
    newdiv.style.cssText="float:left;position:absolute;left:0px;top:0px;width:"+bodyWidth+"px;height:"+bodyHeight+"px;filter:Alpha(Opacity=30);-moz-opacity: 0.3;background-color:#000000;z-index:10;"
    bobj.appendChild(newdiv);
    CreateMsg();

}

function CreateMsg() {
  var bobj = parent.document.body;
  var bodyWidth = bobj.scrollWidth;
  var cHeight = bobj.clientHeight;
  var cWidth = bobj.clientWidth;
  var leftX = (bodyWidth-664)/2;
  var topY = 100;

  var msg=document.createElement('div');
  msg.id="haha2"; //inner div
  msg.style.cssText="float:left;text-align:center;border:1px solid ;position:absolute;left:"+leftX+"px;top:"+topY+"px;height:450px;filter:Alpha(Opacity=100);-moz-opacity: 1.0;background-color:#FFFFFF;z-index:101;"
  bobj.appendChild(msg);

  CreateContent();
}

function CreateContent() {
  var url = "/contactUs-Utf8.php";

  var myAjax = new Ajax.Request(url,{
    method: 'post',
    onComplete: function(response) {
      $('haha2').innerHTML = response.responseText;
    }
  });
}

function CloseAllDiv() {
  bobj = parent.document.body;

  var newdiv = parent.document.getElementById('haha');
  bobj.removeChild(newdiv);
  var msg = parent.document.getElementById('haha2');
  bobj.removeChild(msg);
}

function searchPage(url, containerid){
  form = document.getElementById("SearchForm");

  text = form.spec_search_text.value;
  if (form.spec_search_radio[1].checked == true) radio = "prod";
  else radio = "store";

  url = url+"?r="+radio+"&t="+text;

  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){ alert ("GET FAIL");}
    }
  }
  else
    return false
  page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
  }
  page_request.open('GET', url, true)
  page_request.send(null)
}

function loadpage(page_request, containerid){
  if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
}


function processGetPost() {
  var myajax=ajaxpack.ajaxobj
  var myfiletype=ajaxpack.filetype
  if (myajax.readyState == 4) {
    if (myajax.status==200 || window.location.href.indexOf("http")==-1) {
      if (myfiletype=="txt") {
        var rStr = myajax.responseText
        var aStr = rStr.split("=@=");
        alert(aStr[0]);
        window.location = aStr[1];
      }
      //else
        //alert(myajax.responseXML)
    }
  }
}

function getLoginPostStr() {
  form = document.getElementById("loginForm");
  account = form.account.value;
  password = form.password.value;
  if (account == "") {
    alert('請輸入您的帳號！！');
    return false
  }
  if (password == "") {
    alert('請輸入您的密碼！！');
    return false
  }
  if (account != "" && password != "") {
    var poststr = "account="+ encodeURI(account) + "&password=" + encodeURI(password);
    return poststr
  }
}

function getForgetPostStr() {
  form = document.getElementById("forgetForm");
  id = form.id.value;
  if (id == "") {
    alert('請輸入您的身份證字號！！');
    return false
  }
  else {
    var poststr = "id="+ encodeURI(id);
    return poststr
  }
}

function getRegisterPostStr() {
  form = document.getElementById("registerForm");
  userid = form.userid.value;
  email = form.email.value;
  if (userid == "" || email == "") {
    alert('請輸入您的帳號及EMAIL！！');
    return false
  }
  else {
    var poststr = "userid="+ encodeURI(userid) + "&email="+ encodeURI(email);
    return poststr
  }
}

function getEpaperPostStr() {
  form = document.getElementById("epaperForm");
  epaper = form.epaper.checked
  email = form.email.value
  var poststr = "email="+ encodeURI(email) + "&epaper="+ encodeURI(epaper);
  return poststr
}

function getMailPostStr() {
  form = document.getElementById("MailBoxForm");
  content = form.returnContent.value
  storeid = form.storeid.value
  catalog = form.catalog.value
  var poststr = "content="+ encodeURI(content) + "&storeid="+ encodeURI(storeid) + "&catalog="+ encodeURI(catalog);
  return poststr
}

