﻿var CPH_Path = "ctl00_CPHMain_";

// Website Url -----------------------------------------------
function url()
{
var URLString = "http://www.azurri.com/";
//var URLString = "http://azurridev.azurri.local/";
//var URLString = "http://localhost:1167/azurri/";
return URLString;
}
// -----------------------------------------------------------

// Show / Hide Navigation Divs -------------------------------

function ShowDiv (DivID, ListItemID, BackgroundColor)
{ 
    if (DivID != "")
    {
        document.getElementById( DivID ).style.visibility = 'visible';
    }
    
    if (ListItemID != "")
    {
        if (BackgroundColor != "")
        {
            document.getElementById( ListItemID ).style.backgroundColor = BackgroundColor;
        }
        document.getElementById( ListItemID ).style.color = '#000000'
    }
    
}

function HideDiv (DivID, ListItemID)
{ 
    if (DivID != "")
    {
        document.getElementById( DivID ).style.visibility = 'hidden';
    }
    
    if (ListItemID != "")
    {
        document.getElementById( ListItemID ).style.backgroundColor = ''
    }
}

// -----------------------------------------------------------

// No Enter Button -------------------------------------------
function noenter(e)
{
    if(window.event) // IE
    {
      //alert('You have pressed ' + e.keyCode + ' in IE');
      return !(e.keyCode == 13);
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
      //alert('You have pressed ' + e.which + ' in Mozilla');
      return !(e.which == 13);
    }
    //return !(window.event && window.event.keyCode == 13); 
}
// -----------------------------------------------------------



// Check browser support for ajax -----------------------------
function ajaxCheckBrowserSupport()
{
 var xmlHttp;
try
  {  
  // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest();  
  }
catch (e)
  {  
  // Internet Explorer  
  try
    {    
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    }
      catch (e)
            {    
            try
                {      
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
                }
            catch (e)
                {      
                alert("Your browser does not support AJAX!");
                return false;      
                }    
            }
  }
return xmlHttp;
}


// --------------------------------------------------------------

// ajax Check Cat Code Availability ---------------------------
function ajaxCheckCatCodeAvailability(CatCode, MyCatCode)
{
  var xmlHttp = ajaxCheckBrowserSupport();
  
  xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if (xmlHttp.status == 200)
            {
                var RequestXMLString = xmlHttp.responseText;
                
                try //Internet Explorer
                {
                    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async="false";
                    xmlDoc.loadXML(RequestXMLString);
                }
                catch(e)
                {
                    try //Firefox, Mozilla, Opera, etc.
                    {
                        parser=new DOMParser();
                        xmlDoc=parser.parseFromString(RequestXMLString,"text/xml");
                    }
                    catch(e) 
                    {
                        alert(e.message)
                    }
                }
                try 
                {
                    var nodes  = xmlDoc.getElementsByTagName("CatCodeResponse");
	                if (nodes != null)
	                {
		                try
		                {
			                var XMLValue = nodes[0].childNodes[0].nodeValue;
			                document.getElementById("ctl00_CPHMain_TxtAvailability").value = unescape(XMLValue);
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
                		
		                catch (E)
		                {
			                document.getElementById("ctl00_CPHMain_TxtAvailability").value = "" ;
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
	                }
                }
                catch(e) 
                {
                    alert(e.message)
                }
            }
        }
    }
   
  var XMLString = '<Category CC="' + CatCode + '" MYCC="' + MyCatCode + '" />';
  
  document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'visible';
  document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'visible';
  
  var Path = url(); 
  xmlHttp.open("POST", Path + "azurriadmin/CheckCatAvailability.aspx", true);
  xmlHttp.setRequestHeader("Content-Type", "text/xml") ;
  xmlHttp.send(XMLString);
  
}
// ------------------------------------------------------------

// ajax Check Sub Cat Code Availability ----------------------
function ajaxCheckSubCatCodeAvailability(SubCatCode, MySubCatCode)
{
  var xmlHttp = ajaxCheckBrowserSupport();
  
  xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if (xmlHttp.status == 200)
            {
                var RequestXMLString = xmlHttp.responseText;
                
                try //Internet Explorer
                {
                    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async="false";
                    xmlDoc.loadXML(RequestXMLString);
                }
                catch(e)
                {
                    try //Firefox, Mozilla, Opera, etc.
                    {
                        parser=new DOMParser();
                        xmlDoc=parser.parseFromString(RequestXMLString,"text/xml");
                    }
                    catch(e) 
                    {
                        alert(e.message)
                    }
                }
                try 
                {
                    var nodes  = xmlDoc.getElementsByTagName("SubCatCodeResponse");
	                if (nodes != null)
	                {
		                try
		                {
			                var XMLValue = nodes[0].childNodes[0].nodeValue;
			                document.getElementById("ctl00_CPHMain_TxtAvailability").value = unescape(XMLValue);
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
		                catch (e)
		                {
			                document.getElementById("ctl00_CPHMain_TxtAvailability").value = "" ;
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
	                }
                }
                catch(e) 
                {
                    alert(e.message)
                }
            }
        }
    }
  var XMLString = '<SubCategory SCC="' + SubCatCode + '" MYSCC="' + MySubCatCode + '" />';
  
  document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'visible';
  document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'visible';
  
  var Path = url(); 
  xmlHttp.open("POST", Path + "azurriadmin/CheckSubCatAvailability.aspx", true);
  xmlHttp.setRequestHeader("Content-Type", "text/xml") ;
  xmlHttp.send(XMLString);
  
}
// ------------------------------------------------------------

// ajax Check Sub Cat Code Availability ----------------------
function ajaxCheckUsername(Username, MyUsername)
{
    
    
  var xmlHttp = ajaxCheckBrowserSupport();
  
  xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if (xmlHttp.status == 200)
            {
                var RequestXMLString = xmlHttp.responseText;
                
                try //Internet Explorer
                {
                    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async="false";
                    xmlDoc.loadXML(RequestXMLString);
                }
                catch(e)
                {
                    try //Firefox, Mozilla, Opera, etc.
                    {
                        parser=new DOMParser();
                        xmlDoc=parser.parseFromString(RequestXMLString,"text/xml");
                    }
                    catch(e) 
                    {
                        alert(e.message)
                    }
                }
                try 
                {
                    var nodes  = xmlDoc.getElementsByTagName("UsernameResponse");
	                if (nodes != null)
	                {
		                try
		                {
			                var XMLValue = nodes[0].childNodes[0].nodeValue;
			                document.getElementById("ctl00_CPHMain_TxtUsernameMsg").value = unescape(XMLValue);
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
		                catch (e)
		                {
			                document.getElementById("ctl00_CPHMain_TxtUsernameMsg").value = "" ;
			                
			                document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'hidden';
                            document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'hidden';
		                }
	                }
                }
                catch(e) 
                {
                    alert(e.message)
                }
            }
        }
    }
    
  //if(Username == "")
  //{
    //alert("Please enter a Username");
    //return false;
  //}  
   
  var XMLString = '<Username UN="' + Username + '" MUN="' + MyUsername + '" />';
  var Path = url(); 
  
  document.getElementById("ctl00_CPHMain_DivLoaderTransparant").style.visibility = 'visible';
  document.getElementById("ctl00_CPHMain_DivLoaderBox").style.visibility = 'visible';

  xmlHttp.open("POST", Path + "azurriadmin/CheckUsername.aspx", true);
  xmlHttp.setRequestHeader("Content-Type", "text/xml") ;
  xmlHttp.send(XMLString);
  
}
// ------------------------------------------------------------

// Custom Validation on Edit Update Category -------------------
function CatValidate ( src, arg )
{
    switch (arg.Value)
    {
    case "Current Category Code" : arg.IsValid = true;
    break;
    case "Category Available" : arg.IsValid = true;
    break;
    default : arg.IsValid = false;
    }
}
// -------------------------------------------------------------

// Custom Validation on Edit Update Category -------------------
function SubCatValidate ( src, arg )
{
    switch (arg.Value)
    {
    case "Current Category Code" : arg.IsValid = true;
    break;
    case "Sub Category Available" : arg.IsValid = true;
    break;
    default : arg.IsValid = false;
    }
}
// -------------------------------------------------------------

// ----------------------------------------------------------

// Custom Validation on Username -------------------------------
function UsernameValidate ( src, arg )
{
    switch (arg.Value)
    {
    case "Current Username" : arg.IsValid = true;
    break;
    case "Username Available" : arg.IsValid = true;
    break;
    case "New User" : arg.IsValid = false;
    break;
    default : arg.IsValid = false;
    }
}
// -------------------------------------------------------------

function ClearForm(Form)
{
    switch (Form)
    {
        case "azurri24" :
            document.getElementById(CPH_Path + "TxtUsername").value = "";
            document.getElementById(CPH_Path + "TxtPassword").value = "";
        break;
        case "azurriDirect" :
            document.getElementById(CPH_Path + "TxtName").value = "";
            document.getElementById(CPH_Path + "TxtJobTitle").value = "";
            document.getElementById(CPH_Path + "TxtCompany").value = "";
            document.getElementById(CPH_Path + "TxtAddress").value = "";
            document.getElementById(CPH_Path + "TxtEmail").value = "";
            document.getElementById(CPH_Path + "TxtTelephone").value = "";
            document.getElementById(CPH_Path + "TxtEnquiry").value = "";
        break;
        case "azurri" :
            document.getElementById(CPH_Path + "TxtName").value = "";
            document.getElementById(CPH_Path + "TxtJobTitle").value = "";
            document.getElementById(CPH_Path + "TxtCompany").value = "";
            document.getElementById(CPH_Path + "TxtAddress").value = "";
            document.getElementById(CPH_Path + "TxtEmail").value = "";
            document.getElementById(CPH_Path + "TxtTelephone").value = "";
            document.getElementById(CPH_Path + "TxtEnquiry").value = "";
        break;
        default :
            // ---------------
    }
    return false;
}
function CheckFileExt()
{
    var DownloadField = document.getElementById(CPH_Path + "FUDownload").value;
    if (DownloadField != "")
    {
        if (DownloadField.lastIndexOf(".pdf") == -1)
        {
        alert("Please upload only pdf documents");
        return false;
        }
    }
    
}