var overlay="";

function handleError() {
    return true;
}

function Initialize()
{
  window.onerror = handleError;
  overlay=GetObject("overlay");
  overlay.style.zIndex=-1;
  rotate();
  SetHeight();
}

function IsIE()
{
  return (navigator.appName=="Microsoft Internet Explorer");
}


function Overlay()
{
  overlay=GetObject("overlay");
  overlay.style.zIndex=100;
}

var previousSub=0;

function DisplaySubmenus(main_id,submenu_id)
{
  var referredObj=GetObject(main_id);
  var subMenuObj=GetObject(submenu_id);
  var iFrameObj=GetObject("divIframe");

  if (iFrameObj) {
  iFrameObj.style.width="1px";
  iFrameObj.style.height="1px";
  iFrameObj.style.display="none";
  }

  var previousSubObj=GetObject(previousSub);
  if (previousSubObj) {
    previousSubObj.style.display="none";
  }

  if (subMenuObj) {

    var topAdd=0;
    var leftAdd=0;

    if (window.Iterator) {//mozilla
      topAdd=31;
      leftAdd=0;
    } else if (document.documentElement && typeof document.documentElement.style.maxHeight!="undefined") {//ie7
      topAdd=31;
      leftAdd=0;
    } else if (document.compatMode && document.all) {//ie6
      topAdd=31;
      leftAdd=0;
    } else {//others
      topAdd=30;
      leftAdd=0;
    }

    subMenuObj.style.top=(GetPosY(referredObj)+topAdd)+"px";
    subMenuObj.style.left=(GetPosX(referredObj)+leftAdd)+"px";
    subMenuObj.style.zIndex=subMenuObj.style.zIndex+1;
    subMenuObj.style.display="inline";

    iFrameObj.style.position="absolute";
    iFrameObj.style.left =subMenuObj.offsetLeft+"px";
    iFrameObj.style.top =subMenuObj.offsetTop+"px";
    iFrameObj.style.width =subMenuObj.offsetWidth+"px";
    iFrameObj.style.height =subMenuObj.offsetHeight+"px";
    iFrameObj.style.display="block";

    subMenuObj.style.visibility ="visible";
  }

  previousSub=submenu_id;
}


function HighlightMain(id)
{
  menuObj=GetObject(id);
  menuObj.style.background="#237cb8";
}

function LowlightMain(id)
{
  menuObj=GetObject(id);
  menuObj.style.background="#125582";
}

function GetBodyHeight()
{
  var y = 0;
  if (self.innerHeight) {
    y = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    y = document.documentElement.clientHeight;
  } else if (document.body) {
    y = document.body.clientHeight;
  }
  return y;
}

function SetHeight()
{
  var bodyHeight=GetBodyHeight();

  var contentObj=GetObject("content");
  var contentHeight=GetHeight(contentObj);

  var contentSideLObj=GetObject("m_l");
  var contentSideLHeight=GetHeight(contentSideLObj);

  var contentSideRObj=GetObject("m_r");
  var contentSideRHeight=GetHeight(contentSideRObj);

  var useHeight=0;
  if (contentSideRHeight>contentHeight) {
    useHeight=contentSideRHeight;
  } else {
    useHeight=contentHeight;
  }

  if (useHeight+536 < bodyHeight) {
    contentObj.style.height=(useHeight+(bodyHeight-useHeight-536)) + "px";
    contentSideRObj.style.height=contentObj.style.height;
    contentSideLObj.style.height=contentObj.style.height;
  } else {
    contentObj.style.height=useHeight+"px";
    contentSideRObj.style.height=contentObj.style.height;
    contentSideLObj.style.height=contentObj.style.height;
  }
}

var current_subsub=0;
function ShowSubSubmenu(submenu_id,subsubmenu_id)
{

  var iFrameObj=GetObject("divIframe");
  var submenuBgObj=GetObject("submenu_bg");
  var menusObj=GetObject("menu");


  iFrameObj.style.width="1px";
  iFrameObj.style.height="1px";
  iFrameObj.style.display="none";

  if (current_subsub!=0) {
    current_subsub.style.visibility="hidden";
  }

  var subsubmenu_obj=GetObject(subsubmenu_id);
  var submenu_obj=GetObject(submenu_id);

  if (!subsubmenu_obj) {
    current_subsub=0;
    return;
  }

  subsubmenu_obj.style.left=(GetPosX(submenu_obj)+1)+'px';
  subsubmenu_obj.style.top=(GetPosY(submenu_obj)+29)+'px';
  subsubmenu_obj.style.visibility="visible";

  if (window.Iterator) {//mozilla
  var divIFrame2Obj=GetObject("divIframe2");

  divIFrame2Obj.style.width="1px";
  divIFrame2Obj.style.height="1px";
  divIFrame2Obj.style.display="none";

  divIFrame2Obj.style.position="absolute";
  divIFrame2Obj.style.top =193+"px";
  divIFrame2Obj.style.height =30+"px";
  divIFrame2Obj.style.left ="22px";
  divIFrame2Obj.style.width ="850px";
  divIFrame2Obj.style.display="inline";
  }

  iFrameObj.style.position="absolute";
  iFrameObj.style.top =subsubmenu_obj.offsetTop+"px";
  iFrameObj.style.height =subsubmenu_obj.offsetHeight+"px";
  iFrameObj.style.left =subsubmenu_obj.offsetLeft+"px";
  iFrameObj.style.width =subsubmenu_obj.offsetWidth+"px";
  iFrameObj.style.display="block";

  submenu_obj.style.visibility="visible";
  submenuBgObj.style.visibility="visible";
  current_subsub = subsubmenu_obj;
}

/*
AJAX: Returns the XmlHttpObject
*/
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 Subscribe()
{
  var email=GetObject("newsletterEmail");
  var fullname=GetObject("newsletterName");
  var query=GetObject("newsletterQuery");

  var nlStatus=GetObject("nl_status");

  email=email.value.trim();
  if (email=="") {
    alert('Please enter your Email Address');
    return;
  }
  fullname=fullname.value.trim();
  if (fullname=="") {
    alert('Please enter your Mame');
    return;
  }

  query=query.value.trim();

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert("You're browser does not support AJAX");
    return;
  }

  var url=__BASE_URL__+"/php/subscribe.php?email="+email+"&fullname="+fullname+"&query="+query;
  xmlHttp.onreadystatechange=SubscriptionResult;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function SubscriptionResult()
{
  if (xmlHttp.readyState==4) {
    var nlStatus=GetObject("nl_status");
    var result=xmlHttp.responseText;
    var email=GetObject("newsletterEmail");
    email.value="";

    if (result=="__NO_EMAIL__") {
      return;
    }
    if (result=="__INVALID_EMAIL__") {
      return;
    }
    if (result=="__DATABASE_ERROR__") {
      return;
    }
    if (result=="__INVALID_EMAIL_SETTINGS__") {
      return;
    }
    if (result=="__INVALID_NEWSLETTER_SETTINGS__") {
      return;
    }
    if (result=="__SUBSCRIPTION_EXISTS__") {
      window.location=__WEBPAGES_URL__+"newsletter_subscription_exists.php";
      return;
    }
    if (result=="__SUBSCRIPTION_SUCCEED__") {
      window.location=__WEBPAGES_URL__+"newsletter_subscription_succeed.php";
      return;
    }
    if (result=="__SUBSCRIPTION_FAILED__") {
      window.location=__WEBPAGES_URL__+"newsletter_subscription_failed.php";
      return;
    }
  }
}

function Feedback(formObj)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert("You're browser does not support AJAX");
    return;
  }

  var messageObj=GetObject("message");
  var namaObj=GetObject("name");
  var emailObj=GetObject("email");
  var phoneObj=GetObject("phone");
  var enquiryObj=GetObject("enquiry");
  var invi_fieldObj=GetObject("invi_field");

  var nama=namaObj.value.trim();
  var email=emailObj.value.trim();
  var phone=phoneObj.value.trim();
  var enquiry=enquiryObj.value.trim();
  var invi_field=invi_fieldObj.value.trim();

  if (nama=="") {
    messageObj.style.color="#b40505";
    messageObj.innerHTML="Please fill in your name";
    return;
  }

  if ((email=="") || (!email.match(__regexEmailAddress__))) {
    messageObj.style.color="#b40505";
    messageObj.innerHTML="Please fill in your email correctly";
    return;
  }

  if (enquiry=="") {
    messageObj.style.color="#b40505";
    messageObj.innerHTML="Please fill in your enquiry";
    return;
  }

  messageObj.style.color="blue";
  messageObj.innerHTML="Your feedback is being processed.";

  nama=encodeURI(nama);
  email=encodeURI(email);
  phone=encodeURI(phone);
  enquiry=encodeURI(enquiry);
  invi_field=encodeURI(invi_field);

  xmlHttp.open("POST",__BASE_URL__+"/php/feedback_action.php",true);
  xmlHttp.onreadystatechange=DisplayFeedbackResult;

  var params="nama="+nama+"&email="+email+"&phone="+phone+"&enquiry="+enquiry+"&invi_field="+invi_field;
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(params);
}

function DisplayFeedbackResult()
{
  if ((xmlHttp.readyState==4) && (xmlHttp.status==200)) {
    var message=xmlHttp.responseText.trim();
    var messageObj=GetObject("message");

    if (message!="") {
      messageObj.style.color="#b40505";
      messageObj.innerHTML=message;
    } else {
      window.location=__BASE_URL__+"/feedback_success.php";
    }
  }
}

function showExtra(spanId)
{
  var noOfClient = 12;

  for (i=1;i<=noOfClient;i++)
  {
      spanName1 = 'client' + i + '_1';
      spanName2 = 'client' + i + '_2';

      //eval("document.getElementById('" + spanName1 + "').style.display = 'none'");
      //eval("document.getElementById('" + spanName2 + "').style.display = 'none'");
  }

  spanName1 = 'client' + spanId + '_1';
  spanName2 = 'client' + spanId + '_2';
  showLink = 'showLink' + spanId;
  
  if (eval("document.getElementById('" + showLink + "').innerHTML == 'More Info&gt;&gt;'"))
  {
     for (i=1;i<=noOfClient;i++)
     {
         showLinkCurrent = 'showLink' + i;
         //eval("document.getElementById('" + showLinkCurrent + "').innerHTML='More Info>>'");
     }

     eval("document.getElementById('" + spanName1 + "').style.display = 'block'");
     eval("document.getElementById('" + spanName2 + "').style.display = 'block'");
     eval("document.getElementById('" + showLink + "').innerHTML='<< Less'");
  }
  else
  {

     for (i=1;i<=noOfClient;i++)
     {
         showLinkCurrent = 'showLink' + i;
         //eval("document.getElementById('" + showLinkCurrent + "').innerHTML='More Info>>'");
     }

     eval("document.getElementById('" + spanName1 + "').style.display = 'none'");
     eval("document.getElementById('" + spanName2 + "').style.display = 'none'");
     eval("document.getElementById('" + showLink + "').innerHTML='More Info>>'");

  }

  return false;

}
