/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
	Check the language cookie
 */
function checkLang(value){
	if(getCookie("lang") == null){
		setCookie('lang',value,'','','','');
	}
	else if (getCookie("lang") == value){
		return true;
	}
	else
		return false;
}

/**
	Check the Registration Form
 */
function checkEmptyReg(form1){
	var returnVal = true;				
	if ((document.form1.Card_number.value).length == 0){
		alert("You have to populate the Card number!" );
		document.form1.Card_number.focus(); 
		returnVal = false;
	}
	else if ((document.form1.Title.value).length == 0){
		alert("You have to specify the Title!" );
		document.form1.Title.focus();
		returnVal = false;
	}				
	else if ((document.form1.firstname.value).length == 0){
		alert("You have to specify your first name!" );
		document.form1.firstname.focus();
		returnVal = false;
	}				
	else if ((document.form1.lastname.value).length == 0){
		alert("You have to specify your last name!" );
		document.form1.lastname.focus();
		returnVal = false;
	}				
	else if ((document.form1.dateOfBirth.value).length == 0){
		alert("You have to specify your date of birth!" );
		document.form1.dateOfBirth.focus();
		returnVal = false;
	}			
	else if ((document.form1.email.value).length == 0){
		alert("You have to specify your email address!" );
		document.form1.email.focus();
		returnVal = false;
	}	
	else{
		returnVal = false;

		for (i=0;i<document.form1.share_detail.length;i++) {
			if (document.form1.share_detail[i].checked) {
				returnVal=true;
				break;
			}
		}		
		if (!returnVal ){
			alert("Please indicate if you do want to share your details with a third party!" );		
		}

	}
	
	return returnVal;
}

/**
 * Forgotten password page
 */

function checkEmptyEmail(form1){
	var returnVal = true;
	
	if ((document.form1.transIdent.value).length == 0){
		alert("You have to populate the Card Number!" );
		document.form1.transIdent.focus(); 
		returnVal = false;
	}
	
	return returnVal;
}

function formsubmitEmail(form1){
	if (checkEmptyEmail(form1)){
		document.form1.submit();
	}
}

/**
 * Login page
 */
function checkEmpty(form1){
	var returnVal = true;				
	if ((document.form1.userID.value).length == 0){
		alert("You have to populate the UserID!" );
		document.form1.userID.focus(); 
		returnVal = false;
	}
	else if ((document.form1.password.value).length == 0){
		alert("You have to populate the Password!" );
		document.form1.password.focus();
		returnVal = true;
	}				
	return returnVal;
}

function formsubmit(form1){
	if (checkEmpty(form1)){
		document.form1.submit();
	}
}


/**
 * Links from Main menus
 */
function summary(){
	    self.parent.main.location.replace("DemoSummary.jsp");
		self.parent.menu.location.replace("DemoMenuSummary.jsp");    
}

function transaction() {
		self.parent.main.location.replace("DemoTransaction.jsp");
		self.parent.menu.location.replace("DemoMenuTransaction.jsp");    
}

function yourDetail() {

	 

		self.parent.main.location.replace("DemoYourDetail.jsp");
		self.parent.menu.location.replace("DemoMenuDetails.jsp");

	 
}

function currentPromotion(){
		self.parent.main.location.replace("DemoCurrentPromotion.jsp");
		self.parent.menu.location.replace("DemoMenuCurrent.jsp");
}

function contact() {
		self.parent.main.location.replace("DemoContact.jsp");
		self.parent.menu.location.replace("DemoMenuContact.jsp");
}

function help() {
		self.parent.main.location.replace("DemoHelp.jsp");
		self.parent.menu.location.replace("DemoMenuHelp.jsp");    
}

function closewindow() {
	self.parent.location.replace("../servlet/DemoLogoutServlet");
}

/**
	Transactions
*/
function formSubmitTrans(form1){
	document.form1.submit();
}

function transactionDetails( path, transID) { 

	var url = path + '/servlet/DemoTransactionServlet?transID='+transID+'&methodName=getTransDetails';
	window.open(url,'campaign','width=450,height=200,scrollbars=yes');
}

/**
 * Your details
 */
var changedDetails = false;
var ask_to_save = true;

function saveDetails(){
	ask_to_save = false;
	document.form1.submit();
}

function resetDetails(){
	ask_to_save = false;
	document.form1.reset();
}

function setChanged(changed){
	changedDetails = changed;
}

function detectChanges(){
	if (ask_to_save){
		if(confirm("Do you want to save changes ? ")){
			document.form1.submit();	
		}
	}

}
/*
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}

MM_reloadPage(true);
*/