var xmlHttp;
var action;
var host = "http://digitalhub.ph/";

function GetXmlHttpObject() {
   var xmlHttp=null;
   try {
   // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e) {
   // Internet Explorer
      try {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function stateChanged() {
     if (xmlHttp.readyState==4) {
        if (action == "contact") {                    
            document.getElementById("contact_error").style.display = "block";
            document.getElementById("contact_error").innerHTML = xmlHttp.responseText ;       
        }
        else if (action == "inquire") {                    
            document.getElementById("inquire_error").style.display = "block";
            document.getElementById("inquire_error").innerHTML = xmlHttp.responseText ;       
        }     
     }  
}

function contact_submit() {
   document.getElementById("contact_error").style.display = "none";

   action = "contact";
   xmlHttp=GetXmlHttpObject();

   var fname = document.contact_form.fname.value;
   var lname = document.contact_form.lname.value;
   var email = document.contact_form.email.value;
   var phone = document.contact_form.phone.value;
   var comment = document.contact_form.comment.value;
   
   if (fname == "" ){
      document.getElementById("contact_error").style.display = "block";
      document.getElementById("contact_error").innerHTML = "First Name is Blank.";
   }else if (lname == "") {
      document.getElementById("contact_error").style.display = "block";
      document.getElementById("contact_error").innerHTML = "Last Name is Blank.";
   }else if (email == "") {
      document.getElementById("contact_error").style.display = "block";
      document.getElementById("contact_error").innerHTML = "Email is Blank.";
   }else if (comment == "") {
      document.getElementById("contact_error").style.display = "block";
      document.getElementById("contact_error").innerHTML = "Comment is Blank.";
   }else {
      
      var url="http://digitalhub.ph/contact-submit/?fname=" + fname + "&lname=" + lname + "&email=" + email + "&phone=" + phone + "&comment=" + comment + "&rand=" + Math.random();

      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
   }
}


function inquire_submit() {
   document.getElementById("inquire_error").style.display = "none";

   action = "inquire";
   xmlHttp=GetXmlHttpObject();

   var fname = document.inquire_form.fname.value;
   var lname = document.inquire_form.lname.value;
   var email = document.inquire_form.email.value;
   var phone = document.inquire_form.phone.value;
   var title = document.inquire_form.title.value;
   var comment = document.inquire_form.comment.value;
   
   if (fname == "" ){
      document.getElementById("inquire_error").style.display = "block";
      document.getElementById("inquire_error").innerHTML = "First Name is Blank.";
   }else if (lname == "") {
      document.getElementById("inquire_error").style.display = "block";
      document.getElementById("inquire_error").innerHTML = "Last Name is Blank.";
   }else if (email == "") {
      document.getElementById("inquire_error").style.display = "block";
      document.getElementById("inquire_error").innerHTML = "Email is Blank.";
   }else if (phone == "") {
      document.getElementById("inquire_error").style.display = "block";
      document.getElementById("inquire_error").innerHTML = "Phone Number is Blank.";
   }else if (comment == "") {
      document.getElementById("inquire_error").style.display = "block";
      document.getElementById("inquire_error").innerHTML = "Comment is Blank.";
   }else {
      
      var url="http://digitalhub.ph/inquire-submit/?fname=" + fname + "&lname=" + lname + "&email=" + email + "&phone=" + phone + "&title=" + title + "&comment=" + comment + "&rand=" + Math.random();

      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
   }
}



function showTrailer(str){
    $("#inquire-holder").fadeIn('slow');
    if(screen.height >= 1050){
    document.getElementById("inquire-holder-inner").style.marginTop = "250px";   
    }else{
    document.getElementById("inquire-holder-inner").style.marginTop = "100px";
    } 
}

function closetrailerplayer(){
    $("#inquire-holder").fadeOut('slow');
}

function displaynews(catid){
     window.location = "http://digitalhub.ph/news/?catid="+catid;
  
}


    
function displayarchives(year,month){
     window.location = "http://digitalhub.ph/news/?year="+year+"&month="+month;    
}

