

/// Author: Luke Rocco	\n
/// Date: June 23, 2006	\n
///	Version: 0.0.0.1	\n


//Request object to be used by other methods
var request = null;

//Method used to generate a valid request object to be used by the other methods.
function GetRequest()
{
	try
	{
		request = new XMLHttpRequest();	
	}//try
	catch ( XMLHttpException )
	{
		try
		{			
			request = new ActiveXObject( "Msxml2.XMLHTTP" );		
		}//try
		catch ( msxmlException )
		{
			try
			{				
				request = new ActiveXObject( "Microsoft.XMLHTTP	" );			
			}//try
			catch ( microsoftException )
			{				
				request = null;			
			}//catch
		}//catch
	}//catch
	
	if ( request == null )
	{		
		alert( "Error while craeting the Request Object" );		
	}//if
	
}//GetRequest


//Method that replaces the InnerHtml of a Tag with the passed values		[	IE version	  ]
function ReplaceInnerHTML( elementName, text ) 
{
	if ( elementName != null) 
	{
		var newNode = document.createTextNode( text );		
		document.getElementById( elementName ).innerHTML = text;
	}//if
}//ReplaceText


//Method that replaces the InnerHtml of a Tag with the passed values		[	FIREFOX	  ]
function ReplaceFireHTML( elementName, text ) 
{
	if ( elementName != null) 
	{
		var element = document.getElementById( elementName );
		var newNode = document.createTextNode( text );		
		element.innerHTML = newNode;
	}//if
}//ReplaceText

//Method used to Update a Tag passed as a parameter
function GetData( openType , currentUrl , replaceTag )
{	
	GetRequest();
	
	request.open( openType , currentUrl , true );
	request.onreadystatechange = 
		function()
		{
			if ( request.readyState == 4 )
			{
				var newText = request.responseText;
				//alert( newText );
				ReplaceInnerHTML(  replaceTag , newText );
			}//if
		}//handler
	
	request.send( null );	
}//RequestList


// Retrieves the data from the passed sources, merges the XML with the XSL and returns the resultant data in the tag
// specified by the replace Tag.
function GetXMLData( openType , xmlUrl , xslUrl , replaceTag )
{
	GetRequest();
	
	request.open( openType, xmlUrl, true );
	request.onreadystatechange = 
		function()
		{		
			if ( request.readyState == 4 )
			{			
			
			//Cross Browser Implementation
				if ( window.ActiveXObject )
				{	
					//alert ( "Internet Explorer Browser" );
				
					//Load the xml from the Response Text recieved.
					var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async="false";
					xmlDoc.loadXML( request.responseText );
					
					//Load the XSL file from the passed parameter location
					var xslDoc = new ActiveXObject("Microsoft.XMLDOM");
					xslDoc.async = false;
					xslDoc.load( xslUrl );
													
					//Transform the XML Document with the retrieved XSL and store the results in the result variable
					var result = xmlDoc.transformNode( xslDoc );				
					
					//Print the result variable in the appropriate tag ( passed by the replaceTag paramter )
					ReplaceInnerHTML( replaceTag, result );
					//alert ( request.responseText );
					
					
				}//if Browser is IE
				
				else if ( document.implementation && document.implementation.createDocument )
				{
					//alert ( "Mozilla FireFox Browser" );
									
					//Create new XSLT Processor
					var processor = new XSLTProcessor();
					
					//Load the XSL file from the passed parameter location
					var xslDoc = document.implementation.createDocument("","",null);
					xslDoc.async = false;
					xslDoc.load ( xslUrl );
					
					//alert ( request.responseText );
					
					//Import the Stylesheet to the processor
					processor.importStylesheet( xslDoc );
					
					var parser = new DOMParser();
					var xmlDoc = parser.parseFromString( request.responseText , 'application/xml' );
					
					//Transform the XML Document with the retrieved XSL and store the results in the result variable
					var result = processor.transformToDocument( xmlDoc );
					
					var serializer = new XMLSerializer();
					var output = serializer.serializeToString( result );
				
					//Print the result variable in the appropriate tag ( passed by the replaceTag paramter )	
					ReplaceInnerHTML( replaceTag, output );					
					
					//alert( output );
					
				}//else if Browser is Mozilla
				else
				{
					alert ( "Browser Error. Could not parse XML Feed" );
				}//else
				
				
			}//if
		}//handler
		
	request.send( null );	
	
	
}//GetXMLData



/*
	if ( window.ActiveXObject )
	{			
		var object  
		body = 'Bob' + document.getElementById( elementName );		
		
	}//if Internet Explorer
	else if ( document.implementation && document.implementation.createDocument )
	{	
		var element = document.getElementById( elementName );
		var serializer = new XMLSerializer();		
		body = serializer.serializeToString( element );
	}//else if Browser is Mozilla
	else
	{
		header = "Error while loading data";
		body = "An Error occured during the loading of the List.";
	}//else
*/

//End of File

// File - WorldInfoScript.js	// Author - Luke Rocco	// Date - 25/08/2006

var infoURL = "http://www.gfi.se/downloads/Ajax/Handler/WorldInfo.aspx";

function ChangeCountry()
{
	document.getElementById( "HiddenSubDivision" ).value = 0;
	ProcessCountry();
}//ChangeCountry

function ProcessCountry()
{
	//alert( infoURL );
	
	var listbox = document.getElementById( "cmbCountries" );
	
	if ( ( listbox.selectedIndex > -1 ) && ( listbox.options[ listbox.selectedIndex ].value != null ) )
	{
		
		var index = listbox.selectedIndex;						//alert( index );		
		var country = 	listbox.options[ index ].value;			//alert( country );
		
		var tempUrl = ( infoURL + "?name=" + country );
		
		document.getElementById( "HiddenCountry" ).value = index;		
		//alert( document.getElementById( "HiddenCountry" ).value );
				
		GetRequest();
		
		request.open( "GET" , tempUrl , true );
		request.onreadystatechange = 
				function()
				{
					if ( request.readyState == 4 )
					{						GetList( request.responseText );							}//if
				}//handler
	
		request.send( null );	
	
    }//if
    else{		alert( "Error" );	    }//else
    
   //alert( infoURL );
    
}//ProcessCountry

function GetList( newText )
{
	if ( newText != "NONE" )
	{
		EnableSubDivision();
	
		var tempArr = newText.split(",");
		
		document.getElementById( "SubDivisionTitle" ).innerHTML = tempArr[1] + ": *";
		
		var tempUrl = infoURL + "?country="+ tempArr[2] + "&type=" + tempArr[0];
		
		//alert ( tempUrl );
		
		GetRequest();
		
		request.open( "GET" , tempUrl , true );
		request.onreadystatechange = 
				function()
				{
					if ( request.readyState == 4 )
					{						SetList( request.responseText );							}//if
				}//handler	
		request.send( null );	
		
	}//if
	else	DisableSubDivision();
	
}//function

function SetList( newText )
{
	if ( newText != "NONE" )
	{
		//alert ( newText + ";" );
		
		var listbox = document.getElementById( "cmbState" );
		var tempArr = newText.split(":");
		
		//alert ( document.getElementById( "HiddenSubDivision" ).value );
		
		//var selected = document.getElementById( "HiddenSubDivision" ).value;
		
		listbox.disabled = false;
		listbox.visible = true;
				
		ClearListBox( listbox );		
				
		for ( var i = 0; i <= tempArr.length; i++ )
		{			
			if ( tempArr[i] != null ){
				var option = tempArr[i].split("|");
				listbox.options[i] = new Option ( option[1] , option[0] );					
			}//if
		}//for
		
		var hiddenValue = document.getElementById( "HiddenSubDivision" ).value;
		
		if ( hiddenValue  != "" )
		{
			//alert( hiddenValue );
			
			if ( isNaN( hiddenValue ) )
			{						
				for ( var i = 0; i < listbox.options.length; i++ )
				{	
					var selected = listbox.options[i].value;					
					if ( ( selected != null ) && ( selected == hiddenValue ) )						
					{				listbox.selectedIndex = i;				}//if					
				}//for		
			}//if
			else if ( !isNaN( hiddenValue ) )			
			{	
				if ( hiddenValue > -1 )
				{		listbox.selectedIndex = hiddenValue ;		}//if
				else
				{		listbox.selectedIndex = 0;			}
			}//else if
			
		}//if
						
	}//if
	else	DisableSubDivision();
}//SetList

function EnableSubDivision()
{
	var subDivRow = document.getElementById( "SubDivision" );
	subDivRow.className = "";
	//alert ( subDivRow );
	
	ClearListBox( document.getElementById( "cmbState" ) );
	
}//EnableSubDivision

function DisableSubDivision()
{
	ClearListBox( document.getElementById( "cmbState" ) );
	
	document.getElementById( "HiddenSubDivision" ).value = 0;
	
	var subDivRow = document.getElementById( "SubDivision" );
	subDivRow.className = "hiddenSubDivision";
	//alert ( subDivRow );
	
}//DisableSubDivision

function ClearListBox( listbox )
{
	for ( var i = listbox.options.length -1 ; i >= 0 ; i-- )
	{		listbox.options[ i ] = null;		}//for
		
	listbox.selectedIndex = -1;
}//ClearListBox

function SetSubDivision()
{
	document.getElementById( "HiddenSubDivision" ).value = document.getElementById( "cmbState" ).selectedIndex;
	//alert ( "Saved Space = " + document.getElementById( "HiddenSubDivision" ).value );
	//alert ( "Selected Index = " + document.getElementById( "cmbState" ).selectedIndex );
}//SetSubDivision

function LoadValues()
{	

	SetPreviousForm();
	
	try{
		var selectedCountry = document.getElementById( "HiddenCountry" ).value;
		var selectedDivision = document.getElementById( "HiddenSubDivision" ).value;
	}
	catch(err){}
	
	//alert ( "Stored Country :-   " + selectedCountry );
	
	//alert( "Before :-   " + document.getElementById( "cmbCountries" ).selectedIndex  );
	
	if ( document.getElementById( "HiddenCountry" ).value != "" )
	{
		document.getElementById( "cmbCountries" ).selectedIndex = selectedCountry;
	}//if
		
	//alert ( "After :-   " + document.getElementById( "cmbCountries" ).selectedIndex );
		
	ProcessCountry();
	
	//alert ( "Stored State :-   " + selectedDivision );
	
	//alert( "Before :-   " + document.getElementById( "cmbState" ).selectedIndex  );
	
	//document.getElementById( "cmbState" ).selectedIndex = selectedDivision;
	//document.getElementById( "HiddenSubDivision" ).value = selectedDivision;
	
	//alert ( "After :-   " + document.getElementById( "cmbState" ).selectedIndex );
}//LoadValues



/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */


function SetPreviousForm()
{
	var previousForm = document.getElementById( "previousForm" );				
	
	//alert ( previousForm.vale );
	
	if ( previousForm.value == "register" ) EnableRegister();
	
	if ( previousForm.value == "login" ) EnableLogin();
	
	
}//SetPreviousForm

function EnableRegister()
{

//		protected System.Web.UI.WebControls.Label Label1;
	var loginForm = document.getElementById( "loginForm" );
	loginForm.className = "hiddenSubDivision";
	
	var registerForm = document.getElementById( "registerForm" );
	registerForm.className = "";

	document.getElementById( "previousForm" ).value = "register";			
	//alert ( document.getElementById( "previousForm" ).value );
	
	document.getElementById( "login_hdnHshVal" ).value = "";
	
	try{
		if( document.getElementById( "txtFirstName" ) )
		{
			document.getElementById( "txtFirstName" ).focus();
		}
		else if( document.getElementById( "txtCompany" ) )
		{
			document.getElementById( "txtCompany" ).focus();
		}
	}catch(err){}
	
}//enableRegister

function EnableLogin()
{

	var loginForm = document.getElementById( "loginForm" );
	loginForm.className = "";
	
	var registerForm = document.getElementById( "registerForm" );
	registerForm.className = "hiddenSubDivision";

	document.getElementById( "previousForm" ).value = "login";			
	//alert ( document.getElementById( "previousForm" ).value );
	
	document.getElementById( "login_hdnHshVal" ).value = "";
	document.getElementById( "login_txtUsername" ).focus();
	
}//enableLogin


/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */


function popUp(URL)
{
	day = new Date();			
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=646,height=486');");
}//popUp
			
			
			
