/*!
\file url.js
\brief function to manage url in niss web site
\author ssa
\date 03/04/2006
\par Modification
\li .
*/

/*!
\fn function sz_fGetCustomer()
\brief get niss customer name
\author ssa
\date 03/04/2006
\param void
\return sz_Customer.
\par Modification
\li .
*/
function sz_fGetCustomer() {
	var sz_Customer="";

	if(sz_Customer=="") {
		try {
			/// Try to read the customer into pathname
			/// "http://test.ssa.devs0000.com/Diva" ==> "Diva"
			sz_Customer=sz_fGetCustomerPathname();
		} catch(E) { }
	} // if

	if(sz_Customer=="") {
		/// Try to read the customer into location
		/// "http://niss.demo.com" ==> "Diva"
		try {
			sz_Customer=sz_fGetCustomerFile();
		} catch(E) { }
	} // if

	if(sz_Customer=="") {
		/// Try to read the customer into location
		/// "http://test.diva.ssa.devs0000.com" ==> "Diva"
		try {
			sz_Customer=sz_fGetCustomerHostname();
		} catch(E) { }
	} // if

	return(sz_Customer);
} // sz_fGetCustomer

/*!
\fn function sz_fGetCustomerPathname()
\brief get niss customer name
\author ssa
\date 03/04/2006
\param void
\return sz_Customer.
\par Modification
\li .
*/
function sz_fGetCustomerPathname() {
	var sz_Customer="";

	/// Specifies the file or object path. 
	sz_Pathname=parent.location.pathname;

	var a_Pathname=sz_Pathname.split("/");

	if(a_Pathname.length==0) {
		/// Delete forward slash
		sz_Customer=sz_ftrim(sz_Pathname,47);
	} else {
		sz_Customer=sz_ftrim(a_Pathname[1],47);
	}

	/// diva => Diva
	sz_Customer=sz_fGetCustomerDiretory(sz_Customer);
//alert("sz_fGetCustomerPathname:"+sz_Customer);

	return(sz_Customer);
} // sz_fGetCustomerPathname

/*!
\fn function sz_fGetCustomerHostname()
\brief get niss customer name into hostname
\author ssa
\date 03/04/2006
\param void
\return sz_Customer.
\par Modification
\li .
*/
function sz_fGetCustomerHostname() {
	var sz_Customer="";
	var sz_Hostname="";
	var i_IndexUrl=1;
	var sz_Reg=new RegExp("[.]", "g");

	/// Specifies the file or object path. 
	sz_Hostname=parent.location.hostname;

	/// Index dans l'url
	if(sz_Hostname.indexOf("recettage")==-1) {
		/// diva.neopod.fm-ged.com ==> diva (1)
		i_IndexUrl=0;
	} else {
		/// recettage.diva.neopod.fm-ged.com ==> diva (2)
		i_IndexUrl=1;
	}

	var a_Url=sz_Hostname.split(sz_Reg);

	/// diva => Diva
	sz_Customer=sz_fGetCustomerDiretory(a_Url[i_IndexUrl]);
//alert("sz_fGetCustomerPathname:"+sz_Customer);

	return(sz_Customer);
} // sz_fGetCustomerHostname

/*!
\fn function sz_fGetCustomerDiretory(the_sz_Customer)
\brief diva => Diva
\author ssa
\date 10/03/2008
\param the_sz_Customer
\return .
\par Modification
\li .
*/
function sz_fGetCustomerDiretory(the_sz_Customer) {
	return(the_sz_Customer.substr(0,1).toUpperCase()+the_sz_Customer.substr(1).toLowerCase());
} /* sz_fGetCustomerDiretory */

/*!
\fn function sz_fGetCustomerFile()
\brief get customer by file
\author ssa
\date 03/04/2006
\param void
\return sz_Customer
\par Modification
\li .
*/
function sz_fGetCustomerFile() {
	var sz_Customer="";

	/// The array is not defined !
	if(typeof(a_UrlDefine)=="undefined") { return(sz_Customer); }	

	/// The element is not found.
	if(typeof(a_UrlDefine[parent.location.host])=="undefined") { return(sz_Customer); }	

	sz_Customer = a_UrlDefine[parent.location.hostname];

	/// diva => Diva
	sz_Customer=sz_fGetCustomerDiretory(sz_Customer);

	return(sz_Customer);
} // sz_fGetCustomerFile()

/*!
\fn sz_fGetLanguage()
\brief get language into url
\author ssa
\date 10/03/2008
\param .
\return .
\par Modification
\li .
*/
function sz_fGetLanguage() {
	var a_Param=window.location.search.substr(1).split("&");
	var sz_Language="";
	var a_Param;
	var a_Data;
  
	try {
		for(i=0; i<a_Param.length; i++) {
			a_Data=a_Param[i].split("=");
			if(a_Data.length==2) {
				a_Param[a_Data[0]]=a_Data[1];		
			} // if
		} // for

		if(typeof(a_Param["sz_Language"])!="undefined") {
			sz_Language = a_Param["sz_Language"];
		} else {
			sz_Language="";
		}
	} catch(E) {
		sz_Language="";
	}
		
	return(sz_Language);	
} // sz_fGetLanguage()

/*****************************************************
	url.js
*****************************************************/
