﻿var ID_COOKIE_NAME = 'ECOSMEMID';
var CTRY_COOKIE_NAME = 'ECOSCTRY';

function validate(lang,shopperid) {
 
  var isOk = false;
  if(!shopperid || shopperid == '' || shopperid == null || shopperid == 'null') {
    if(lang == 'zh_TW')
      alert('請輸入編碼');
    else if (lang == 'zh_CN')
	  alert('请输入编码');
	else
	  alert('Please enter your id');  
	 document.main.shopperid.focus();  
  }else{
    isOk = true;
  } 
  return isOk;
}


function submitShopperId(lang,url)
{
  var shopperid = document.main.shopperid.value;
  if (validate(lang,shopperid)){
    createCookie(ID_COOKIE_NAME, shopperid, '');
    document.main.action = 'http://www.ecoswayaus.com/ecosway/Redirect.jsp?shopperid=' + shopperid + '&mallind=AU&action=GENERAL&common_locale=' + lang+'&nextUrl=' + url;
    document.main.submit();
  }
}

function shopperIdChecking(lang,url)
{	
	var memberId = readCookie(ID_COOKIE_NAME);
	var shopperIdUrl;
	var newWin;
	if(memberId == '' || memberId == null || memberId == 'null') {
	   shopperIdUrl = "aust/";
	   if (lang == "zh_TW")
	     shopperIdUrl+="zh_au";
	   else if (lang == "zh_CN")	  
	     shopperIdUrl+="tw_au";
	   else
	   	 shopperIdUrl+="en_au";
	   shopperIdUrl+="/ShopperId.html?nextUrl="+url;	 
	   newWin = window.open(shopperIdUrl,'blank','width=440,height=200,toolbar=no,statusbar=no,resizable=no,scrollbars=no');	
	   newWin.focus();
	}else{
       if (url.indexOf("ProductsMain_") >= 0 || url.indexOf("MemberRegisterBO_") >= 0){
	      if (url.indexOf("?") >= 0){
		     url+="&"; 
		  }else{
		     url+="?";  
		  } 
		  url+= "common_locale=" + lang;
	   }	
	   window.location = url;
	}
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie() {   
    createCookie(ID_COOKIE_NAME,"",-1);
}


function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}