/*---------------------------------------------------------------------------*/
/*	Functions																 */
/*---------------------------------------------------------------------------*/
function	isCameraMember()
{
	if ( CAM == 1 && IJM == 0 ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	isPrinterMember()
{
	if ( CAM == 0 && IJM == 1 ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	isPerfectMember()
{
	if ( CAM == 1 && IJM == 1 ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	isCameraMemberOrPerfectMember()
{
	if ( CAM == 1 ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	isPrinterMemberOrPerfectMember()
{
	if ( IJM == 1 ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	authorizeCameraMember()
{
	if ( !isCameraMember() ) {
		location.href = "/error/authorization.html";
	}
}
/*---------------------------------------------------------------------------*/
function	authorizePrinterMember()
{
	if ( !isPrinterMember() ) {
		location.href = "/error/authorization.html";
	}
}
/*---------------------------------------------------------------------------*/
function	authorizePerfectMember()
{
	if ( !isPerfectMember() ) {
		location.href = "/error/authorization.html";
	}
}
/*---------------------------------------------------------------------------*/
function	authorizeCameraMemberAndPerfectMember()
{
	if ( !isCameraMemberOrPerfectMember() ) {
		location.href = "/error/authorization.html";
	}
}
/*---------------------------------------------------------------------------*/
function	authorizePrinterMemberAndPerfectMember()
{
	if ( !isPrinterMemberOrPerfectMember() ) {
		location.href = "/error/authorization.html";
	}
}
/*---------------------------------------------------------------------------*/
function	canDownloadCameraApplication()
{
	if ( !isCameraMemberOrPerfectMember() ) {
		location.href = "/error/authorization.html";
	}
	else {
		document.cookie = "cameraapplication=ok; path=/";
	}
}
/*---------------------------------------------------------------------------*/
function	canDownloadPrinterApplication()
{
	if ( !isPrinterMemberOrPerfectMember() ) {
		location.href = "/error/authorization.html";
	}
	else {
		document.cookie = "printerapplication=ok; path=/";
	}
}
/*---------------------------------------------------------------------------*/
function	getParamValue( paramName )
{
	if ( location.search.length > 0 ) {
		var query = location.search.substring( 1 );
		
		if ( query.indexOf( paramName + "=" ) != -1 ) {
			pramamValueStartIndex	= query.indexOf( paramName + "=" ) + paramName.length + 1;
			pramamValueEndIndex		= query.indexOf( "&", pramamValueStartIndex );
			
			if ( pramamValueEndIndex == -1 ) {
				pramamValueEndIndex = query.length;
			}
			
			return unescape( query.substring( pramamValueStartIndex, pramamValueEndIndex ) );
		}
	}
	
	return "";
}
/*---------------------------------------------------------------------------*/
function	getCookieValue( cookieName )
{
	if ( document.cookie.length > 0 ) {
		if ( document.cookie.indexOf( cookieName + "=" ) != -1 ) {
			cookieValueStartIndex	= document.cookie.indexOf( cookieName + "=" ) + cookieName.length + 1;
			cookieValueEndIndex		= document.cookie.indexOf( ";", cookieValueStartIndex );
			
			if ( cookieValueEndIndex == -1 ) {
				cookieValueEndIndex = document.cookie.length;
			}
			
			return unescape( document.cookie.substring( cookieValueStartIndex, cookieValueEndIndex ) );
		}
	}
	
	return "";
}
/*---------------------------------------------------------------------------*/
function	isFromDJ()
{
	if ( getParamValue( "from" ) != "" ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	isValidCigcontentCookie()
{
	if ( getCookieValue( "cigcontents" ) == "ok" ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
function	hasSSOCookie()
{
	if ( getCookieValue( "nbe_j_al" ) != "" && getCookieValue( "jnbeSession" ) != "" ) {
		return true;
	}
	else {
		return false;
	}
}
/*---------------------------------------------------------------------------*/
/*	Routine																	 */
/*---------------------------------------------------------------------------*/
// DJ control
// -------------------- start 
if ( isFromDJ() ) {
	location.href = "https://" + location.host + "/pe/f/djReception.do?d=static&url="
					+ encodeURIComponent( location.protocol + "//" + location.host + location.pathname + location.search )
					+ "&from=" + getParamValue( "from" );
}
else if ( !isValidCigcontentCookie() || !hasSSOCookie() ) {
	location.href = "https://" + location.host + "/pe/f/djReception.do?d=static&url="
					+ encodeURIComponent( location.protocol + "//" + location.host + location.pathname + location.search );
}
// -------------------- end

// service control
// -------------------- start 
var	myck			= document.cookie;
var	sc_cookie_name	= "p4=";

var	PA	= 0;	// 0 = false, 1 = true
var	PB	= 0;	// 0 = false, 1 = true

if ( myck != "" ) {
	var sc_start = myck.indexOf( sc_cookie_name );
	
	if ( sc_start != -1 ) {
		sc_start += sc_cookie_name.length;
		
		var	sc_cookie_val	= myck.substring( sc_start, sc_start + 1 );
		sc_cookie_val		= parseInt( sc_cookie_val, 16 );			// convert String(16 adic) -> Number(10 adic)
		var	sc_atr_val		= ( sc_cookie_val & 3 );					// mod 3
		
		if ( sc_atr_val == 0 ) {
			PA = 0;
			PB = 0;
		}
		else if ( sc_atr_val == 1 ) {
			PA = 1;
			PB = 0;
		}
		else if ( sc_atr_val == 2 ) {
			PA = 0;
			PB = 1;
		}
		else if ( sc_atr_val == 3 ) {
			PA = 1;
			PB = 1;
		}
	}
}
// -------------------- end


// check member type
// -------------------- start
var	mt_cookie_name = "p4=";

var	CAM = 0;	// 0 = false , 1 = true
var	IJM = 0;	// 0 = false , 1 = true

if ( myck != "" ) {
	var mt_start = myck.indexOf( mt_cookie_name );
	
	if ( mt_start != -1 ) {
		mt_start += mt_cookie_name.length;
		
		var mt_cookie_val	= myck.substring( mt_start, mt_start + 1 );
		mt_cookie_val		= parseInt( mt_cookie_val,16 );				// convert String(16 adic) -> Number(10 adic)
		var	mt_atr_val		= ((mt_cookie_val >> 2) & 3);				// bit shift & mod 3
		
		if ( mt_atr_val == 0 ) {
			CAM = 0;
			IJM = 0;
		}
		else if ( mt_atr_val == 1 ) {
			CAM = 1;
			IJM = 0;
		}
		else if ( mt_atr_val == 2 ) {
			CAM = 0;
			IJM = 1;
		}
		else if ( mt_atr_val == 3 ) {
			CAM = 1;
			IJM = 1;
		}
	}
}
// -------------------- end
