﻿ function doLoad(url) {
        if (window.XMLHttpRequest) {
            request = new XMLHttpRequest();
            request.onreadystatechange = processRequestChange;
            request.open("GET", url, true);
            request.send(null);
            } 
            else if (window.ActiveXObject) {
                request = new ActiveXObject("Microsoft.XMLHTTP");
                if (request) {
                    request.onreadystatechange = processRequestChange;
                    request.open("GET", url, true);
                    request.send();
            }
        }        
     }

    function processRequestChange() {
    
        if (request.readyState == 4) {
            if (request.status == 200) {
                document.getElementById("changingContent").innerHTML = request.responseText;
                InitThickBoxes()
            }
        } 
    }

    function processClick(pageID)
    {
        switch(pageID)
        {
          case "0":
           pageID = 'MainContent';
           break;
         case "1":
          pageID = 'product';
          break;
         case "2":
           pageID = 'demo';
           break;
         case "3":
           pageID = 'tryUs';
           break;
         case "4":
           pageID = 'contactus';
           break;
         case "5":
           pageID = 'sitemap';
           break;
          case "6":
           pageID = 'search';
           break;
        }
    
        if (pageID.indexOf('SingleNews')!=-1)
        {
            var flash = getFlash('prime_984x485_090115');
	        flash.animateBox();
        }
    
        var startIndex = location.href.lastIndexOf("/");
        var endIndex = location.href.lastIndexOf(".");
        var pageName = location.href.substring(startIndex+1,endIndex);
        
        var paramsIndex = pageID.lastIndexOf("?");
        var params = "";
        if  (paramsIndex!=-1)
        {
            params = pageID.substring(paramsIndex+1);
            pageID = pageID.substring(0,paramsIndex);
        }
        if (params == "")
        {
            doLoad(location.href.substring(0,startIndex+1)+pageID+".aspx?get=1");
            if (pageID != 'MainContent')
                UpdateCurrentLink(pageID+".aspx");
            else
                UpdateCurrentLink("default.aspx");
        }
        else
        {
            doLoad(location.href.substring(0,startIndex+1)+pageID+".aspx?get=1&"+params);
            if (pageID != 'MainContent')
                UpdateCurrentLink(pageID+".aspx?"+params);
            else
                UpdateCurrentLink("default.aspx?"+params);
        }
    }
    
    
    function DoSearch()
    {
        var startIndex = location.href.lastIndexOf("/");
        var endIndex = location.href.lastIndexOf(".");
        var searchText = document.getElementById('searchText').value;
        doLoad(location.href.substring(0,startIndex+1)+"SearchResults.aspx?btn=1&search="+searchText);
        UpdateCurrentLink("SearchResults.aspx?search="+searchText);
    }
    
    function definePage()
    {
        if (window.netscape) { //hide the copy to cliapboard button
            document.getElementById('copylink').style.display = 'none';
        }

        var startIndex = location.href.lastIndexOf("/");
        var endIndex = location.href.lastIndexOf(".");
        var pageName = location.href.substring(startIndex+1,endIndex);
        
        
        //http://212.98.191.142:8080/PrimeMod/
        
        
        //debugger;
        if (pageName.toLowerCase() == "default" || endIndex == -1 || endIndex<startIndex)
            pageName = "MainContent";
       
            var paramsIndex = location.href.lastIndexOf("?");
            var params = "";
            if  (paramsIndex!=-1)
            {
                params = location.href.substring(paramsIndex+1);
            }
            if (params == "")
            {
                doLoad(location.href.substring(0,startIndex+1)+pageName+".aspx?get=1");
                if (pageName!='MainContent')
                    UpdateCurrentLink(pageName+".aspx");
                else
                    UpdateCurrentLink("default.aspx");
                
                setTimeout("AnimateFlash('"+pageName+"');", 200); 

            }
            else
            {
                doLoad(location.href.substring(0,startIndex+1)+pageName+".aspx?get=1&"+params);
                 if (pageName!='MainContent')
                    UpdateCurrentLink(pageName+".aspx?"+params);
                 else
                    UpdateCurrentLink("default.aspx?"+params);
                     
                setTimeout("AnimateFlash('"+pageName+"');",200); 

            }
    }
    
    function UpdateCurrentLink(pageID)
    {
        var currLink = document.getElementById("currentLink");
        var startIndex = location.href.lastIndexOf("/");
        currLink.innerHTML = location.href.substring(0,startIndex+1)+pageID;
        currLink.href= location.href.substring(0,startIndex+1)+pageID;
    }
    
	function handleBTNClick(pageID)
	{
        processClick(pageID);
    }

    var getFlash = function ( flashId ) {
	    if (!document.createElementNS) {
		    return window[flashId];
	    }
	    else {
		    return document[flashId];
	    }
    }
    			
    function activateFlash(pageID)
    {
        var flash = getFlash('prime_984x485_090115');
	    flash.animateBox(pageID);
	    processClick(pageID.toString())
    }
    
    function allNewsClick()
    {
        var flash = getFlash('prime_984x485_090115');
	    flash.animateBox();
	    processClick('allnews');
    }
    
    function  AnimateFlash(pageName) {
        var flash = getFlash('prime_984x485_090115');
        switch(pageName)
        {
         case "product":
           flash.animateBox(1);
          break;
         case "demo":
           flash.animateBox(2);
           break;
         case "tryUs":
           flash.animateBox(3);
           break;
         case "contactus":
           flash.animateBox(4);
           break;
         case "search":
           flash.animateBox(6);
           break;
        }
    }
    
  function copyLink()
  {
     var link = document.getElementById("currentLink").href;
     CopyPlusSelect(link);
     alert('Link was successfully copied to clipboard!');
  }
  
  function CopyPlusSelect(value) {
      if (window.clipboardData)  // IE send-to-clipboard method.
            window.clipboardData.setData('Text', value);
  }

 function TryBtnClick()
 {
   var allFieldsFill = true;
   
   var necessaryFields = document.getElementById('necessaryFields');
   
   var firstName = document.getElementById('txtFirstName');
   var lastName = document.getElementById('txtLastName');
   var email = document.getElementById('txtEmail');
   var phone0 = document.getElementById('txtPhone1');
   var phone1 = document.getElementById('txtPhone2');
   var phone2 = document.getElementById('txtPhone3');
   
   var imgFirstName = document.getElementById('imgFirstName');
   var imgLastName = document.getElementById('imgLastName');
   var imgEmail = document.getElementById('imgEmail');
   var imgPhone0 = document.getElementById('imgPhone0');
   var imgPhone1 = document.getElementById('imgPhone1');
   var imgPhone2 = document.getElementById('imgPhone2');
   
   var zeroPhone = document.getElementById('zeroPhone');
   var firstPhone = document.getElementById('firstPhone');
   var secondPhone = document.getElementById('secondPhone');
  
 /*  if (firstName.value!="" && lastName.value!="" && email.value!="" && phone1.value!="" && phone2.value!="")
   {
     necessaryFields.style.display = 'none';
     imgFirstName.style.visibility = 'hidden';
     imgLastName.style.visibility = 'hidden';
     imgEmail.style.visibility = 'hidden';
     imgPhone1.style.visibility = 'hidden';
     imgPhone2.style.visibility = 'hidden';
  
   }
   else
   {
   */
    necessaryFields.style.display = '';

    if (firstName.value == '') {
        allFieldsFill = false;
    }
    else
        imgFirstName.style.visibility = 'hidden';
     
    if (lastName.value == '') {
        allFieldsFill = false;
    }
    else
        imgLastName.style.visibility = 'hidden';

    if (email.value == '') {
        allFieldsFill = false;
    }
    else
        imgEmail.style.visibility = 'hidden';
    
     var re0 = new RegExp("^[0-9]{3}$");
    
    if (phone0.value.match(re0))   {
        zeroPhone.style.display = 'none';
    }
    else {
       // imgPhone0.style.visibility = 'visible';
        allFieldsFill = false;
        zeroPhone.style.display = '';
    }
    
        
    var re = new RegExp("^[0-9]{4}$");
    
    if (phone1.value.match(re))   {
        firstPhone.style.display = 'none';
    }
    else {
       // imgPhone1.style.visibility = 'visible';
        allFieldsFill = false;
        firstPhone.style.display = '';
    }
         
    var re2 = new RegExp("^[0-9]{5}$"); 
    if (phone2.value.match(re2))   {
        secondPhone.style.display = 'none';
    }
    else {
       // imgPhone2.style.visibility = 'visible';
        allFieldsFill = false;
        secondPhone.style.display = '';
    }
    
   
   
   if (phone2.value.match(re2) && phone1.value.match(re) && phone0.value.match(re0))
   {
        imgPhone2.style.visibility = 'hidden';
   }
   
 
    if (allFieldsFill == true)
    {
       necessaryFields.style.display = 'none';
       var btn = document.getElementById('try');
       btn.click();
    }
   // }
 }
 
