/**
 * This javascript file cuts the screen into 2 MMI style:
 * 
 *	the TPR style  
 *    
 *					|---------------------------------------|  
 *					|               Top MENU                |  
 *					|---------------------------------------|  
 *					|                                       |  
 *					|                                       |  
 *					|                                       |  
 *					|               Module                  |  
 *					|                                       |  
 *					|                                       |  
 *					|---------------------------------------|  
 *					|   BANNER (for test or evaluation)     |  
 *					|---------------------------------------|  
 *					
 * or the V2 style
 *   
 *					|-----|---------------------------------|  
 *					|     |         Top MENU                |  
 *					|     |---------------------------------|  
 *					| SUB |                                 |  
 *					| MENU|                                 |  
 *					|     |           Module                |  
 *					|     |                                 |  
 *					|     |                                 |  
 *					|     |                                 |  
 *					|---------------------------------------|  
 *					|   BANNER (for test or evaluation)     |  
 *					|---------------------------------------|  
 *					
 *
 *	Main part : Top Menu + Module (it is defined in an other document called index-v2.php)
 *    
 */

// Common variables used by TPR and V2 MMI style
var sz_Index_Url="";
var sz_Index_Tag="";
var sz_Index_TagHtml="";
var sz_Index_Height_Banniere="30";
var sz_Index_Height_MainPart="*"; // MainPart = Top Menu + Module
var sz_Index_Width_SubMenu="168";
var sz_Index_Width_MainPart="*";
var sz_Index_Name_Ban="SNP_ban";
var sz_Index_Name_Mod="SNP_mod";
var sz_Index_Name_Men="SNP_men";
var sz_Index_Name_SubMen="SNP_submen";
var sz_Index_Name_MainPart="SNP_mainpart";
var sz_Index_Src_Ban="../scm/SNP_ban.html";
var sz_Index_Src_MainPart="../scm/SNP_SCM_index_v2.php";
//var sz_Index_Src_MainPart_DA="../scm/SNP_SCM_index_v2_DA.php";
if ((typeof (b_DirectAccesOcr) == 'undefined') || (b_DirectAccesOcr == false))
{
	var sz_Index_Src_MainPart_DA="../scm/SNP_SCM_index_v2_DA.php";
}
else
{
	var sz_Index_Src_MainPart_DA="../SupervisionOcr/SNP_ocr_DA.php";
}
var sz_Index_Src_SubMenu="../scm/SNP_SCM_login_left.php";
var b_ShowBanner=true;
var b_submenu=true;
var sz_MMITypeParam="1";
/*
* => sz_Index_Name = Client 
*/


/*
	pathname retourne le chemin après le host : exemple :
	http://test.xxx.fm-ged.com/Diva/ => pathname="/Diva/"
				=> host=test.xxx.fm-ged.com
*/

	/*
	* MODIF : si on appele la fenetre à partir d'une autre fenetre
	*/
	if (location.search.length > 0) {
		launchString = location.search.substring(1, location.search.length);
		// Split the string at each "&"
		// and put the parts
		// (name-value pairs) into an array:
		var launchStringArray = launchString.split("&");
		// Loop through each part in turn:

		for (var i = 0; i <= launchStringArray.length - 1; i++) {
			// Get the left and right side
			// of each part (name-value pair):
			var left = launchStringArray[i].substring(0,launchStringArray[i].indexOf("="));
			var right =launchStringArray[i].substring(launchStringArray[i].indexOf("=") + 1,launchString.length);
			// If the right hand side
			// (value) is not numeric, give
			// it quotes to make it a string:

			if(isNaN(right)) {
				right = '"' + right + '"';
			}

			// Use the JavaScript eval()
			// function to declare
			// each part (name-value pair)
			// as a JavaScript variable
			// with a value assigned:
			eval("var " + left + " = " + right);
		} /* for */
	} /* if */

	var sz_Index_Name_Client="Diva";
	if (typeof(HOST)=="undefined") {
		try {
			sz_Index_Name_Client = sz_fGetCustomer()
		}
		catch(E) { 
			/* if the function don't run go to web site Diva */
			sz_Index_Name_Client="Diva";
		} /* catch */
	} else {
		sz_Index_Name_Client=PATHNAME.split("/")[1];
		sz_Index_Url=HOST;
		if(typeof(sz_Index_Name_Client) == "undefined") {
			sz_Index_Name_Client=PATHNAME.split("%2F")[1];
		}
	}

	if(sz_Index_Name_Client=="Neopod") {
		location.href="http://nls.neopost.com";
		exit;
	} /* if */

	/*
	* => sz_Index_Tag = test | recettage | neopod
	*/
	sz_Index_Tag=sz_Index_Url.split(".");
	
	/**
	 * Checks if the banner is needed
	 */	 
	switch(sz_Index_Tag[0]) {
		case "test" :
			/*
			* test.xxx.fm-ged.com Developpement 
			*/
			b_ShowBanner=true;
		break;
		case "recettage" : 
			/*
			* recettage.neopod.fm-ged.com Recettage
			*/
			b_ShowBanner=true;
		break;
		case "neopod" :
		default :
			/*
			* neopod.fm-ged.com Production 
			*/
			b_ShowBanner=false;
		break;
	} /* switch */

	/**
	 * Checks if the screen shall be cut into TPR style or V2 style	
	 */	 
	if ((typeof (i_MMI_Type) == 'undefined') || (i_MMI_Type != 2)) {
		// We cuts the screen into TPR style
		b_submenu =  false;
		sz_MMITypeParam = "1";
	} else {
		// We cuts the screen into V2 style
		b_submenu =  true;
		sz_MMITypeParam = "2";
	}

	var sz_Param="";
	if(typeof(sz_DirectAccessLoginV2)!="undefined"&&
		typeof(sz_DirectAccessPasswordV2)!="undefined"&&
		typeof(sz_DirectAccessCountryCodeV2)!="undefined") {
		sz_Param="&sz_DirectAccessLoginV2="+sz_DirectAccessLoginV2+"&sz_DirectAccessPasswordV2="+sz_DirectAccessPasswordV2+"&sz_DirectAccessCountryCodeV2="+sz_DirectAccessCountryCodeV2;
	} /* if */

	var sz_ParamAdd="";
	if(typeof(sz_DirectAccessCalledScreen)!="undefined") {
		sz_ParamAdd+="&sz_DirectAccessCalledScreen="+sz_DirectAccessCalledScreen;
	}
	if(typeof(sz_DirectAccessShowOnlyContent)!="undefined") {
		sz_ParamAdd+="&sz_DirectAccessShowOnlyContent="+sz_DirectAccessShowOnlyContent;
		if(sz_DirectAccessShowOnlyContent=="yes") {
			b_submenu=false;
			b_ShowBanner=false;
			sz_Index_Name_MainPart="SNP_mod";
		}
	}

	sz_Param+=sz_ParamAdd;

	/**
	 * Writes the main part
	 */	 	
	sz_Index_TagHtml=
	'<frame name="'+
	sz_Index_Name_MainPart+
	'" src="';
	// Check if DA is asked

	if (b_DirectAcces)
		sz_Index_TagHtml += sz_Index_Src_MainPart_DA;
	else
		sz_Index_TagHtml += sz_Index_Src_MainPart;
	sz_Index_TagHtml +='?CLIENT='+
	sz_Index_Name_Client+
	'&CAR='+
	sz_Index_Code_Client+
	'&MMITYPE='+
	sz_MMITypeParam+sz_Param+
	'" marginheight="0" marginwidth="0"/>';

	/**
	 * Add the sub menu (i.e. left menu if needed)
	 */
	if (b_submenu) {
		sz_Index_TagHtml=
		// divide the screen into Sub Menu and Main Part
		'<frameset border="0" frameborder="0" framespacing="0" cols="'+
		sz_Index_Width_SubMenu + ',' + sz_Index_Width_MainPart+
		'">'+
		// the frame of the submenu
		'<frame name="'+
		sz_Index_Name_SubMen+
		'" src="'+
		sz_Index_Src_SubMenu+
		'?CLIENT='+
		sz_Index_Name_Client+
		'&CAR='+
		sz_Index_Code_Client+
		'&MMITYPE='+
		sz_MMITypeParam+sz_ParamAdd+
		'" marginheight="0" marginwidth="0" scrolling="no" noresize/>'+
		sz_Index_TagHtml +
		'</frameset>';
	}
	/**
	 * Add the banner if needed
	 */
	if (b_ShowBanner) {
		sz_Index_TagHtml=
		'<frameset border="0" frameborder="0" framespacing="0" rows="'+
		sz_Index_Height_MainPart + ',' + sz_Index_Height_Banniere +
		'">'+
		sz_Index_TagHtml +
		'<frame name="'+
		sz_Index_Name_Ban+
		'" noresize scrolling="no"  src="'+
		sz_Index_Src_Ban+
		'"/>' +
		'</frameset>';
	}
	else
	{
		sz_Index_TagHtml=
		'<frameset border="0" frameborder="0" framespacing="0" rows="'+
		sz_Index_Height_MainPart + '">'+ sz_Index_TagHtml +'</frameset>';
	}
	
	/* 
	* Ecriture de la page index.html
	*/
	document.write(sz_Index_TagHtml);
