/******************************************************************************
* eshopcicScript.js                                                          *
* ------------------                                                          *
*                                                                             *
* SECURED PAYMENT INTEGRATION IN PAGES                                        *
*                                                                             *
*******************************************************************************
*                                                                             *
* Copyright 2000-2004 Isotools, all right reserved                            *
*                                                                             *
******************************************************************************/


function displaySecuredOrderModes(amount, bChecked)
{
	var html  = "<td align='left' class='fontColorStandardText fontFamilyStandardText fontSizeNormal'>";

	html += "<input type='hidden' name='date'		value='" + htmlEncode(getCurrentDate()) + "'>";
	html += "<input type='hidden' name='montant'	value='" + amount + "EUR'>";
	html += "<input type='hidden' name='basketCN'	value='" + cookieName + "'>";
	html += "<input type='hidden' name='coordCN'	value='" + coordCookie + "'>";
	html += "<input type='hidden' name='lgue'		value='" + userLang + "'>";
	
	var checked = (bChecked)?" CHECKED" : "";

	html += "<input name='orderMode' type='radio' value='securedpayment'" + checked + ">"+thesaurus.eshopcic_securedOrder;
	html += "</td>";
	
	return html;	
}


function validateSecuredOrder()
{
	// expiration date for cookies
	var exp = new Date();
	exp.setTime(exp.getTime() + (86400 * 1000 * 30));


	// make email body and save it in a cookie
	//orderID = "XXXX";
	var strOrder = makeOrderMail('securedPayment');
	replace (strOrder, "\n", "<br>");
	strOrder = escape(strOrder);
	deleteCookie("mailOrder");
	setCookie("mailOrder", strOrder, exp);

	// record email to send order
	var orderRecipient = emailClient;
	deleteCookie("orderRecipient");
	setCookie("orderRecipient", escape(orderRecipient), exp);
}


function showInstructionsSecured()
{
	var html = thesaurus.eshopcic35;
	return html;
}


function getSecuredOrderID(search)
{
	var infoArray = search.split("&");

	var i;
	for (i=0 ; i< infoArray.length ; i++)
	{
		var tmp = infoArray[i].split("=");
		if (tmp[0] == "reference" || tmp[0] == "order_ref")
			return tmp[1];
	}

	return "???";
}

// utils
function getCurrentDate()
{
	var date = new Date();
	
	var strDay = "" + date.getDate();
	if (strDay.length == 1) strDay = "0" + strDay;

	var strMonth = "" + (date.getMonth() + 1);
	if (strMonth.length == 1) strMonth = "0" + strMonth;

	var strYear = "" + date.getFullYear ();

	var strHour = "" + (date.getHours());
	if (strHour.length == 1) strHour = "0" + strHour;;

	var strMin = "" + (date.getMinutes());
	if (strMin.length == 1) strMin = "0" + strMin;

	var strSec = "" + (date.getSeconds());
	if (strSec.length == 1) strSec = "0" + strSec;;

	var strDate = strDay + "/" + strMonth + "/" + strYear + ":" + strHour + ":" + strMin + ":" +strSec

	return strDate;
}

function htmlEncode( str )
{
	str = str.replace(/&/g, "&amp;" ) ;
	str = str.replace(/</g, "&lt;" ) ;
	str = str.replace(/>/g, "&gt;" ) ;
	str = str.replace(/\"/g, "&quot;" ) ;
	str = str.replace(/'/g, "&#x27;" ) ;
	return str ;
}

function makeOrderID()
{

}