/* 
 * Hazid Technologies Ltd
 * 
 * Copyright 2010 Hazid Technologies
 * 
 * Date: 2010-09-06 12:00:00 +0000 
 * Revision: 1
 */
  function menuAjax(url)
  {          
    MenuCallBackAjax("#top_seperator", url);              
  }
      
  function processPostAjax(url, parameters) {
    PostCallBackAjaxWithRedirect("#div_content", url, parameters)     
  }
      
  function processRSSAjax(url, parameters) {
    PostCallBackAjax("#rssOutput", url, parameters);     
  }
  
  function processFullRSSAjax(url, parameters) {
    PostCallBackAjax("#div_content", url, parameters);
  }
       
  function homeProcessAjax(url) {
    HomeCallBackAjax("#div_content", url);    
  }
                  
  function processAjax(url) {
    CallBackAjax("#div_content", url);    
  }
     
  function HomeCallBackAjax(divName, url)
  {
    $.ajax({
      url: url,
      type: "GET",
      dataType: "html",
      success: function(html, textStatus)
      {        
         $(divName).html(html);
         //$("div[title*=.mp4]").flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}});
         $('#player').each(function(index) {$(this).flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}})});
         //flowplayer("player", "flowplayer-3.2.4.swf");
         document.title = document.originalTitle;
         showRSS('HAZID'); 
      }      
    });
  }
      
  function CallBackAjax(divName, url)
  {
    $.ajax({
      url: url,
      type: "GET",
      dataType: "html",
      success: function(html, textStatus)
      {        
         $(divName).html(html);
         //$("div[title*=.mp4]").flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}});
         $('#player').each(function(index) {$(this).flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}})});
         //flowplayer("player", "flowplayer-3.2.4.swf");
         document.title = document.originalTitle;   
      }      
    });
  }
  
  function MenuCallBackAjax(divName, url)
  {
    $.ajax({
      url: url,
      type: "GET",
      dataType: "html",
      success: function(html, textStatus)
      {        
         $(divName).html(html);
         //$("div[title*=.mp4]").flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}});
         //$('#player').each(function(index) {$(this).flowplayer("flowplayer-3.2.4.swf")});
         //flowplayer("player", "flowplayer-3.2.4.swf");   
      }      
    });
  }
  
  function PostCallBackAjaxWithRedirect(divName, url, parameters)
  {
    $.ajax({
      url: url,
      type: "POST",
      data: parameters,
      dataType: "html",
      success: function(html, textStatus)
      {        
         $(divName).html(html);
         processAjax('mail_result.html');                 
      }      
    });
  }
  
  function PostCallBackAjax(divName, url, parameters)
  {
    $.ajax({
      url: url,
      type: "POST",
      data: parameters,
      dataType: "html",
      success: function(html, textStatus)
      {        
         $(divName).html(html);
         //$("a[href*=.mp4]").flowplayer("flowplayer-3.2.4.swf", {clip: {autoPlay: false, autoBuffering: true}});        
      }      
    });
  }
      
  function processProductsAjax(url) {
    CallBackAjax("#div_products_area", url);        
  }
  
  function processMiniViewAjax(url) {
    CallBackAjax("#product_mini_view", url);           
  }
    
  function getAskQuestionFormData(obj) 
  { 
    if(obj.email.value != "" && 
       obj.name.value != "" && 
       obj.message.value != "")
       {      
          var poststr = "name=" + escape(encodeURI(
          obj.name.value)) +"&email=" +
          escape(encodeURI(obj.email.value))
          + "&message=" +
          escape(encodeURI(obj.message.value));
                              
          processPostAjax('ask_a_question.php', poststr);
       }
       else
       {
         $("#captchaStatus").html("Please fill out all required fields");
         Recaptcha.reload();
       }
  }
  
  function getRequestDemoFormData(obj)
  {
    if(obj.name.value != "" && 
       obj.email.value != "" && 
       obj.telephone.value != "" && 
       obj.country.value != "")
       {
          var poststr = "name=" + escape(encodeURI(
          obj.name.value)) + "&email=" +
          escape(encodeURI(obj.email.value))
          + "&address=" +
          escape(encodeURI(obj.address.value)) + "&telephone=" +
          escape(encodeURI(obj.telephone.value)) + "&county=" +
          escape(encodeURI(obj.county.value)) + "&country=" +
          escape(encodeURI(obj.country.value)) + "&comment=" +
          escape(encodeURI(obj.comment.value));
                              
          processPostAjax('request_a_demo.php', poststr);
       }
       else
       {
         $("#captchaStatus").html("Please fill out all required fields");
         Recaptcha.reload();
       }
  }
  
  function getOtherContactFormData(obj)
  {
    if(obj.name.value != "" && 
       obj.email.value != "" && 
       obj.reason.value != "")
       {
          var poststr = "name=" + escape(encodeURI(
          obj.name.value)) + "&email=" +
          escape(encodeURI(obj.email.value))
          + "&address=" +
          escape(encodeURI(obj.address.value)) + "&telephone=" +
          escape(encodeURI(obj.telephone.value)) + "&county=" +
          escape(encodeURI(obj.county.value)) + "&country=" +
          escape(encodeURI(obj.country.value)) + "&reason=" +
          escape(encodeURI(obj.reason.value)) + "&comment=" +
          escape(encodeURI(obj.comment.value));
                              
          processPostAjax('other_contact.php', poststr);
       }
       else
       {
         $("#captchaStatus").html("Please fill out all required fields");
         Recaptcha.reload();
       }
  }
  
  function showRSS(str)
  {          
    if (str.length==0)
    {
      var postStr = "feed=HAZID";
      
      processRSSAjax('getRSS.php', postStr);            
    }
    else
    {
      var postStr = "feed=" + str;
      
      processRSSAjax('getRSS.php', postStr); 
    }          
  }
  
  function showFullRSS(str)
  {          
    if (str.length==0)
    {
      var postStr = "feed=HAZID";
      
      processFullRSSAjax('news.php', postStr);            
    }
    else
    {
      var postStr = "feed=" + str;
      
      processFullRSSAjax('news.php', postStr); 
    }          
  }

  function showAbout()
  {
    processAjax('about.html');
    menuAjax('about_us_menu.html');    
  }
  
  function showProducts()
  {
    processAjax('products.html');  
    menuAjax('product_menu.html');     
  }
  
  function showContact()
  {
    processAjax('contact.html');
    menuAjax('contact_menu.html');    
  }
  
  function showProductsInfo()
  {
    processProductsAjax('products_videos.html');
    updateProductsTitle('Product Information');    
  }
  
  function showProductsBenefits()
  {
    processProductsAjax('products_benefits.html');
    updateProductsTitle('Benefits');
  }
  
  function showProductsWorkflow()
  {
    processProductsAjax('products_workflow.html');
    updateProductsTitle('Workflow');
  }
  
  function showProductsFeatures()
  {
    processProductsAjax('products_features.html');
    updateProductsTitle('Features');
  }
  
  function showActionManagementMiniView()
  {
    processMiniViewAjax('action_management_mini_view.html');
  }
  
  function showDesignReviewMiniView()
  {
    processMiniViewAjax('design_review_mini_view.html');
  }
  
  function showIntelligentPHAMiniView()
  {
    processMiniViewAjax('intelligent_pha_mini_view.html');
  }
  
  function showKnowledgePHAMiniView()
  {
    processMiniViewAjax('knowledge_pha_mini_view.html');
  }
  
  function showManagementOfChangeMiniView()
  {
    processMiniViewAjax('management_of_change_mini_view.html');
  }
  
  function showPidViewerMiniView()
  {
    processMiniViewAjax('pid_viewer_mini_view.html');
  }
       
  function showPHiAMiniView()
  {
    processMiniViewAjax('phia_mini_view.html');
  }
     
  function showTitles()
  {
    homeProcessAjax('titles.html');
    menuAjax('empty.html');
  }
       
  function AjaxHandler(x)
  {
    switch(x)
    {
      case "#products":
      showProducts();
      break;
      case "#about":
      showAbout();
      break;
      case "#contact":
      showContact();
      break;
      case "#home":
      showTitles();
      break;
      case "#casestudies":
      processAjax('case_studies.html');
      break;
      case "#history":
      processAjax('history.html');
      break;
      case "#managerialteam":
      processAjax('managerial_team.html');
      break;  
      case "#partners":
      processAjax('partners.html');
      break;
      case "#faq":
      processAjax('faq.html');
      break; 
      case "#demo":
      processAjax('request_a_demo.html');
      break; 
      case "#othercontact":
      processAjax('other_contact.html');
      break; 
      case "#question":
      processAjax('ask_a_question.html');
      break;   
      case "#designreview":
      processAjax('design_review.html');
      break; 
      case "#phia":
      processAjax('phia.html');
      break; 
      case "#actionmanagement":
      processAjax('action_management.html');
      break; 
      case "#services":
      processAjax('services.html');
      break;
      case "#rssnews":
      showFullRSS('HAZID');
      break;
      default:
      showTitles();
      break;
    }
  }
  
  function validateCaptcha()
  {
      challengeField = $("input#recaptcha_challenge_field").val();
      responseField = $("input#recaptcha_response_field").val();
      //alert(challengeField);
      //alert(responseField);
      //return false;
      var html = $.ajax({
      type: "POST",
      url: "ajax.recaptcha.php",
      data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
      async: false
      }).responseText;
   
      //alert(html);
         
      if(html == "success")
      {
          $("#captchaStatus").html(" ");
          // Uncomment the following line in your application
          return true;
      }
      else
      {
          $("#captchaStatus").html("Your captcha is incorrect. Please try again");
          Recaptcha.reload();
          return false;
      }
  }
         
  function updateProductsTitle(arg)
  {
    document.getElementById('products_title').innerHTML = "&nbsp;Products - " + arg;
  }      
