
//---------languages supported by our site
var langCookieName = "mt_lang";
var langs = new Array("eng","chs","cht", "spn", "fr", "ru","jp","kr");
var paths = new Array("", "/chinese/simplified", "/chinese/traditional", "/spanish", "/french", "/russian","/japanese","/Korean");
//------------------------Settings
var AbsolutePath = 'http://mahjongtime.com'; 
var domainName = 'mahjongtime.com';

//----------------deposit ----
var txbAmountID="";
var labelCreditsID="";
//-----------------------

switch(window.location.hostname)
{
	case 'localhost': 

		AbsolutePath = 'http://localhost/Mahjong.Web'; 

		domainName = 'localhost';
		break;
	case 'cluster.qa.novowebsoft.com': 
		AbsolutePath = 'http://cluster.qa.novowebsoft.net/mahjongtime.com'; 
		domainName = 'cluster.qa.novowebsoft.com';
		break;
	case 'qa.novowebsoft.com': 
		AbsolutePath = 'http://qa.novowebsoft.com/mahjongtime.com'; 
		domainName = 'qa.novowebsoft.com';
		break;
	case '192.168.0.101': 
		AbsolutePath = 'http://192.168.0.101/Mahjong.Web'; 
		domainName = '192.168.0.101';
		break;
}
var testimonialsImages = 7;
//-------------------------------------
function SetFocus(obj_id)
{
	cur_obj = document.getElementById(obj_id);
	if(cur_obj != null)
	{
		cur_obj.focus();
	}
}

function StringFormat(str)
{
  for(i = 1; i < arguments.length; i++)
  {
    str = str.replace('{' + (i - 1) + '}', arguments[i]);
  }
  return str;
}

function TrimEnd(str)
{
  if (str.length>0)
  {
      if (str.substr(str.length-1)=='|') 
          str = str.substr(0,str.length-1);
  }
  return str;
}

// ======== Check for our affiliates: IncomeAccess, CJ, PapperJam. ========
var partnerId;
partnerId = getQueryStringParam("partnerId");
if (partnerId != "")
{
	var currDate = new Date();
    var expdate = currDate.getTime();  
    expdate += 86400*1000 ; //expires in 24 hours( in milliseconds)
    currDate.setTime(expdate);
	if(getCookie("incomeAccess")!="")
	    {deleteCookie("incomeAccess","/");}
	if(getCookie("PARTNER_LINK")!="")
	    {deleteCookie("PARTNER_LINK","/");}
	setCookie("partnerId", partnerId, currDate);
}
//check for income access affiliates
var btag;
btag = getQueryStringParam("btag");
if (btag != "")
{
	var currDate = new Date();
    var expdate = currDate.getTime(); 
    expdate += 86400*1000 ; //expires in 24 hours(in milliseconds)
    currDate.setTime(expdate);
    if(getCookie("partnerId")!="")
	    {deleteCookie("partnerId","/");}
	setCookie("incomeAccess", btag, currDate);
}
// --- CJ link: http://mahjongtime.com/index.html?PID=2210202&AID=10426550&SUBID=mt_cj
var pid = getQueryStringParam("PID");
var aid = getQueryStringParam("AID");
var subid = getQueryStringParam("SUBID"); // optional
if (aid != "" && pid != "")
{
	var currDate = new Date();
    var expdate = currDate.getTime(); 
    expdate += 60*86400*1000 ; //expires in 60 days(in milliseconds)
    currDate.setTime(expdate);
    if(getCookie("partnerId")!="")
        deleteCookie("partnerId","/");

    if(getCookie("incomeAccess")!="")
        deleteCookie("incomeAccess","/");
   
    var partnerLink=StringFormat("{0}|{1}|{2}|{3}","CJ",aid,pid,subid);
    setCookie("PARTNER_LINK", TrimEnd(partnerLink), currDate);
}
// -- PapperJam link: http://mahjongtime.com/index.html?source=893&subid=43545
pid = getQueryStringParam("source");
subid = getQueryStringParam("subid"); 
if (pid != "" && subid != "" && aid=="")
{
	var currDate = new Date();
    var expdate = currDate.getTime(); 
    expdate += 60*86400*1000 ; //expires in 60 days(in milliseconds)
    currDate.setTime(expdate);
    if(getCookie("partnerId")!="")
        deleteCookie("partnerId","/");
    if(getCookie("incomeAccess")!="")
        deleteCookie("incomeAccess","/");
   
   var partnerLink=StringFormat("{0}|{1}|{2}","JAM",pid,subid);
   setCookie("PARTNER_LINK", TrimEnd(partnerLink), currDate);
}

// ====== End affiliates section ======
function setCookie(name, value, expires) 
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") + "; path=/" + 
        ((domainName == "mahjongtime.com") ? "; domain=" + domainName : "");
}

function getCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = "";
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) 
	{
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function deleteCookie(name, path) 
{
   if (getCookie(name))
   {
       var expires = new Date();
       expires.setTime(expires.getTime()+((-1)*24*60*60*1000));
       setCookie(name, "", expires);
   }
}

function getQueryStringParam(paramName)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) 
	{
		var pair = vars[i].split("=");
		if (pair[0] == paramName) 
		{return pair[1];}
	}
	return "";
}

function PaySameAsAbove()
{	
	document.getElementById('txb_PayAddress1').value = document.getElementById('txb_PrimAddress1').value;	
	document.getElementById('txb_PayAddress2').value = document.getElementById('txb_PrimAddress2').value;
	document.getElementById('txb_PayCity').value = document.getElementById('txb_PrimCity').value;
	document.getElementById('ddl_PayState').options[document.getElementById('ddl_PrimState').selectedIndex].selected =true;
	document.getElementById('txb_PayProvince').value = document.getElementById('txb_PrimProvince').value;	
	document.getElementById('txb_PayPostalCode').value = document.getElementById('txb_PrimPostalCode').value;
	document.getElementById('ddl_PayCountry').options[document.getElementById('ddl_PrimCountry').selectedIndex].selected =true;
}

function AccountSameAsAbove()
{
	document.getElementById('txb_AccHonorific').value = document.getElementById('txb_PrimHonorific').value;
	document.getElementById('txb_AccFirstName').value = document.getElementById('txb_PrimFirstName').value;
	document.getElementById('txb_AccMiddleName').value = document.getElementById('txb_PrimMiddleName').value;
	document.getElementById('txb_AccLastName').value = document.getElementById('txb_PrimLastName').value;
	document.getElementById('txb_AccSuffix').value = document.getElementById('txb_PrimSuffix').value;
	document.getElementById('txb_AccTitle').value = document.getElementById('txb_PrimTitle').value;
	document.getElementById('txb_AccPhone').value = document.getElementById('txb_PrimPhone').value;
	document.getElementById('txb_AccFax').value = document.getElementById('txb_PrimFax').value;
	document.getElementById('txb_AccEmail').value = document.getElementById('txb_PrimEmail').value;
}

function TechSameAsAbove()
{
	document.getElementById('txb_TechHonorific').value = document.getElementById('txb_PrimHonorific').value;
	document.getElementById('txb_TechFirstName').value = document.getElementById('txb_PrimFirstName').value;
	document.getElementById('txb_TechMiddleName').value = document.getElementById('txb_PrimMiddleName').value;
	document.getElementById('txb_TechLastName').value = document.getElementById('txb_PrimLastName').value;
	document.getElementById('txb_TechSuffix').value = document.getElementById('txb_PrimSuffix').value;
	document.getElementById('txb_TechTitle').value = document.getElementById('txb_PrimTitle').value;
	document.getElementById('txb_TechPhone').value = document.getElementById('txb_PrimPhone').value;
	document.getElementById('txb_TechFax').value = document.getElementById('txb_PrimFax').value;
	document.getElementById('txb_TechEmail').value = document.getElementById('txb_PrimEmail').value;	
}

//---------------------------------------for create tour

/*var Distribution = new Array();
var winnersCount;
function WinnersChange()
{
	var txb_WinnersCount = document.getElementById('txb_WinnersCount');
	winnersCount = txb_WinnersCount.value;
	//window.alert(roundsNum%1);
	
	var DistributionTable = document.getElementById('DistributionTable');
	deleteCount = DistributionTable.rows.length;
	for(i=0; i<deleteCount; i++)
		{DistributionTable.deleteRow(0);} 							
	for(i=0; i<winnersCount; i++)
	{
		//window.alert(i+'-'+Percents.length);
		if(Distribution.length <= i)
			{Distribution[i] = 0;}
		newRow = DistributionTable.insertRow(0);
		newCell = newRow.insertCell(0); 						
		newCell.innerHTML = '<INPUT TYPE="text" NAME="Distribution'+i+'" VALUE="'+Distribution[i]+'" onchange="DistributionChange('+i+')" CLASS="textboxes">';
	}	
	DistributionsChange();		
}

function DistributionChange(i)
{			
	Distribution[i] = document.getElementById('Distribution'+i).value;
	DistributionsChange();
}

function DistributionsChange()
{
	var txb_Distribution = document.getElementById('txb_Distribution');	
	txb_Distribution.value = "";
	for(i=0; i<winnersCount-1; i++)
	{
		txb_Distribution.value += Distribution[winnersCount-i-1]+'|';
	}								
	txb_Distribution.value += Distribution[0];
}*/

//-------------------------------for Tanya
		var ImgCount = 30;
		var LTiles = new Array(ImgCount);
		var RTiles = new Array(ImgCount);	
		LTiles[0] = 'Mah jong -Wind East';
		RTiles[0] = 'Mahjong -Bamboo 1';
		LTiles[1] = 'Mah jong -Bamboo 5';
		RTiles[1] = 'Mahjong -Dot 1';
		LTiles[2] = 'Mah jong -Dot 5';
		RTiles[2] = 'Mahjong -Wind East';
		LTiles[3] = 'Mah jong -Dragon Green';
		RTiles[3] = 'Mahjong -Bamboo 5';
		LTiles[4] = 'Mah jong -Wind South';
		RTiles[4] = 'Mahjong -Dot 5';
		LTiles[5] = 'Mah jong -Character 5';
		RTiles[5] = 'Mahjong -Dragon Green';
		LTiles[6] = 'Mah jong -Bamboo 2';
		RTiles[6] = 'Mahjong -Wind South';
		LTiles[7] = 'Mah jong -Dot 9';
		RTiles[7] = 'Mahjong -Character 5';
		LTiles[8] = 'Mah jong -Dot 6';
		RTiles[8] = 'Mahjong -Bamboo 2';
		LTiles[9] = 'Mah jong -Dot 2';
		RTiles[9] = 'Mahjong -Dot 2';
		LTiles[10] = 'Mah jong -Dragon Red';
		RTiles[10] = 'Mahjong -Dragon Red';
		LTiles[11] = 'Mah jong -Bamboo 3';
		RTiles[11] = 'Mahjong -Bamboo 3';
		LTiles[12] = 'Mah jong -Dot 7';
		RTiles[12] = 'Mahjong -Dot 7';
		LTiles[13] = 'Mah jong -Character 3';
		RTiles[13] = 'Mahjong -Character 3';
		LTiles[14] = 'Mah jong -Dragon White';
		RTiles[14] = 'Mahjong -Dragon White';
		LTiles[15] = 'Mah jong -Character 7';
		RTiles[15] = 'Mahjong -Character 7';
		LTiles[16] = 'Mah jong -Bamboo 4';
		RTiles[16] = 'Mahjong -Bamboo 4';
		LTiles[17] = 'Mah jong -Wind West';
		RTiles[17] = 'Mahjong -Wind West';
		LTiles[18] = 'Mah jong -Dot 3';
		RTiles[18] = 'Mahjong -Dot 3';
		LTiles[19] = 'Mah jong -Bamboo 6';
		RTiles[19] = 'Mahjong -Bamboo 6';
		LTiles[20] = 'Mah jong -Character 2';
		RTiles[20] = 'Mahjong -Character 2';
		LTiles[21] = 'Mah jong -Wind North';
		RTiles[21] = 'Mahjong -Wind North';
		LTiles[22] = 'Mah jong -Bamboo 8';
		RTiles[22] = 'Mahjong -Bamboo 8';
		LTiles[23] = 'Mah jong -Dot 3';
		RTiles[23] = 'Mahjong -Dot 3';
		LTiles[24] = 'Mah jong -Dot 4';
		RTiles[24] = 'Mahjong -Dot 4';
		LTiles[25] = 'Mah jong -Character 6';
		RTiles[25] = 'Mahjong -Character 6';
		LTiles[26] = 'Mah jong -Bamboo 7';
		RTiles[26] = 'Mahjong -Bamboo 7';
		LTiles[27] = 'Mah jong -Character 9';
		RTiles[27] = 'Mahjong -Character 9';
		LTiles[28] = 'Mah jong -Bamboo 3';
		RTiles[28] = 'Mahjong -Bamboo 3';
		LTiles[29] = 'Mah jong -Dot 8';
		RTiles[29] = 'Mahjong -Bamboo 9';
		LTiles[30] = 'Mah jong -Bamboo 9';
		RTiles[30] = 'Mahjong -Character 8';
		LTiles[31] = 'Mah jong -Character 8';
		RTiles[31] = 'Mahjong -Dot 9';
		var LImgArray = new Array(ImgCount);
		var RImgArray = new Array(ImgCount);
		var ImgArray = new Array(2);
		ImgArray[0] = LImgArray;
		ImgArray[1] = RImgArray;	
		var TilesArray = new Array(2);
		TilesArray[0] = LTiles;
		TilesArray[1] = RTiles;					
		
		function ImgsLoad()
		{
			for(i=0; i<ImgCount; i++)
			{
				LImgArray[i] = new Image();								
				LImgArray[i].src = AbsolutePath+'/Images/'+(i+1)+'l.gif';				
				RImgArray[i] = new Image();								
				RImgArray[i].src = AbsolutePath+'/Images/'+(i+1)+'r.gif';
				//window.alert(ImgArray[i].height+'asdf');
			}
		}
		
		function InsertImgs() 
		{ 			
	
			var MainTable = document.getElementById('MainTable');
			var Tables = new Array(2);
			Tables[0] = document.getElementById('LeftTable');			
			Tables[1] = document.getElementById('RightTable');			 
			//window.alert('adf');
			
			deleteCount = Tables[0].rows.length;		
			for(i=0; i<deleteCount; i++)
			{ 
				for(j=0; j<2; j++)
				{
					Tables[j].deleteRow(0); 
				}
			} 
			//window.alert(LeftTable.rows.length);
			//setTimeout(1000);
			//window.alert(RImgArray[0].height);
			var imgHeight = (RImgArray[0].height==0)?51:RImgArray[0].height;
			var rowsCount = Math.ceil(MainTable.clientHeight/imgHeight);
			var lastImage = new Array(2);
			lastImage[0] = 1;
			lastImage[1] = 2;
			for(i=0; i<rowsCount; i++)
			{
				for(j=0; j<2; j++)
				{
					img = new Image();
					lastImage[j] = GenerateNumber(lastImage[j]);
					img.src = ImgArray[j][lastImage[j]].src;
					img.title = TilesArray[j][lastImage[j]];
					img.alt = TilesArray[j][lastImage[j]];
					newRow = Tables[j].insertRow(0);
					newCell = newRow.insertCell(0);
					newCell = newCell.appendChild(img);
				}
				/*img = new Image();				
				lastRightImage = GenerateNumber(lastRightImage);
				img.src = RImgArray[lastRightImage].src;
				img.title = "Title";
				img.alt = "Alt";
				newRow = RightTable.insertRow(0);							
				newCell = newRow.insertCell(0); 						
				newCell = newCell.appendChild(img);*/
			}			
		}		
		 					 
		function GenerateNumber(lastImage)
		{
			var toRet;
			do
			{
				toRet  = Math.floor(ImgCount * Math.random() );
			}
			while(toRet == lastImage);
			//-------from 0 to ImgCount
			return toRet;
		}	
		ImgsLoad();		

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CheckAffiliateRegisterForm()
{
	var bret = true
	
	var vld_FirstName = document.getElementById('vld_FirstName');
	if(document.getElementById('firstname').value.length < 1)
	{		
		vld_FirstName.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_FirstName.innerHTML = '';
	}
	
	var vld_LastName = document.getElementById('vld_LastName');
	if(document.getElementById('lastname').value.length < 1)
	{		
		vld_LastName.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_LastName.innerHTML = '';
	}
	
	var vld_Phone = document.getElementById('vld_Phone');
	if(document.getElementById('phone').value.length < 1)
	{		
		vld_Phone.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Phone.innerHTML = '';
	}
	
	var vld_Email = document.getElementById('vld_Email');
	var email = document.getElementById('email');
	if(email.value.length < 1 || !emailCheck(email.value))
	{		
		vld_Email.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Email.innerHTML = '';
	}
		
	return bret;
}

function CheckAffiliateLoginForm()
{
	var bret = true
	
	var vld_Login = document.getElementById('vld_Login');		
	if(document.getElementById('login').value.length < 1)
	{		
		vld_Login.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Login.innerHTML = '';
	}
	
	var vld_Password = document.getElementById('vld_Password');
	if(document.getElementById('password').value.length < 1)
	{		
		vld_Password.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Password.innerHTML = '';
	}
	
	return bret;
}


function CheckIndexForm()
{
	var bret = true
	
	var vld_Login = document.getElementById('vld_Login');
	if(document.getElementById('login').value.length < 1)
	{		
		vld_Login.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Login.innerHTML = '';
	}
	
	var vld_Password = document.getElementById('vld_Password');
	var pass = document.getElementById('password');
	if(pass.value.length < 1)
	{		
		vld_Password.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Password.innerHTML = '';
	}
	
	var vld_Confirm = document.getElementById('vld_Confirm');
	var conf = document.getElementById('confirm');
	if(pass.value != conf.value || conf.value.length < 1)
	{		
		vld_Confirm.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Confirm.innerHTML = '';
	}
	
	
	var vld_Email = document.getElementById('vld_Email');
	var email = document.getElementById('email');
	if(email.value.length < 1 || !emailCheck(email.value))
	{		
		vld_Email.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Email.innerHTML = '';
	}
		
	return bret;
}

function CheckHtmlLoginForm()
{
	var bret = true
		
	var vld_Password = document.getElementById('vld_Password');
	var pass = document.getElementById('password');
	if(pass.value.length < 1)
	{		
		vld_Password.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Password.innerHTML = '';
	}
	
	var vld_Confirm = document.getElementById('vld_Confirm');
	var conf = document.getElementById('confirm');
	if(pass.value != conf.value || conf.value.length < 1)
	{		
		vld_Confirm.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Confirm.innerHTML = '';
	}
	
	
	var vld_Email = document.getElementById('vld_Email');
	var email = document.getElementById('email');
	if(email.value.length < 1 || !emailCheck(email.value))
	{		
		vld_Email.innerHTML = '*';
		bret = false;
	}
	else
	{
		vld_Email.innerHTML = '';
	}
		
	return bret;
}

function emailCheck (emailStr) {

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	//alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	//alert("Ths username contains invalid characters.");
	return false;
	}
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	//alert("Ths domain name contains invalid characters.");
	return false;
	}
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	//alert("The username doesn't seem to be valid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	//alert("Destination IP address is invalid!");
	return false;
	}
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	//alert("The domain name does not seem to be valid.");
	return false;
	}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	//alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	//alert("This address is missing a hostname!");
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

var timer = 10; 

function SetTimer()
{
	window.setTimeout("timer_process()", 1000);
}

function timer_process() 
{ 							
	if(timer!= null && timer>0) 
	{ 
		var lbl_Timer = document.getElementById('lbl_Timer'); 
		timer = --timer; 
		//var m = timer/60; 
		var s = timer%60; 
		//lbl_timer.innerText = 'After ' + Math.floor(m) + ' минут ' + s + ' секунд'; 
		lbl_Timer.innerText = 'Thank you. You have successfully completed uploading. This page will be closed in ' + s + ' seconds';
		window.setTimeout("timer_process()", 1000); 
	}
	else
	{
	//window.location.reload("../Mahjong-Play.html");
	window.close();
	//document.url = "../Mahjong-Play.html";
	}
} 

function MM_openBrIntroWindow(zzz)
{
  window.open(zzz,'a','scrollbars=no,width=640,height=480');
}
				
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var urlArray = new Array(4); //for URL's, increase size as necessary
var banArray = new Array(4); //for banners, increase size as necessary
var counter = 0;
var url = "http://mahjongtime.com/Mahjong-Join-Hanukkah-Tour.html"; //initial URL

//add your necessary URL's
urlArray[0] = "http://mahjongtime.com/Mahjong-Join-Hanukkah-Tour.html";
urlArray[1] = "http://mahjongtime.com/Mahjong-Join-Hanukkah-Tour.html";
urlArray[2] = "Mahjong-SignIn.aspx";
urlArray[3] = "Mahjong-SignIn.aspx";

if(document.images) //pre-load all banner images
{
  for(i = 0; i < 4; i++)
  {
    banArray[i] = new Image(229, 165);
    banArray[i].src = "banners/banner" + (i) + ".gif";
  }
}

function changeBanner() //banner changer function
{
	
	if(counter > 3)
	   counter = 0;
	document.banner.src = banArray[counter].src; //sets a new banner

	url = urlArray[counter]; //sets a new URL to the banner
	counter++; //increase the counter for the next banner
}

//calls the changeBanner() function every 6 seconds
//change the timer as necessary (minutes * 60000) or (seconds * 1000)
function ActivateChangeBanner()
{
	var timer = window.setInterval("changeBanner()", 6000);
}			

function LoadTestimonialImage()
{
	if(document.images)
	{
		document.images["imgTestimonials"].src = "testimonials/tbanner" + GetRandom(testimonialsImages) + ".gif";
	}
	
}	
//returns a number in interval 0 - n 
function GetRandom(n)
{
	var ret = Math.floor(Math.random()*n);
	return ret;
}
//obsolete
function WindowRedirect(url)
{
	window.location = url;
}
//obsolete
function fn_GetPathBySelectedLang()
{
	var lang = getCookie('mt_lang');
	var path = 'http://www.mahjongtime.com/';
	if (lang != null)
	{
		if (lang == 'chs')
		{path = AbsolutePath + '/chinese/simplified/';}
		else if (lang == 'cht')
		{path = AbsolutePath + '/chinese/traditional/';}
	}
	return path;
}

function redirectToSelectedLang(pageLang)
{
    var cookieLang = getCookie(langCookieName);
        if (cookieLang != pageLang && pageLang == langs[0])
        {
            var isValidLang = 0;
	        for(i=0; i<langs.length; i++)
	        {
		        if (cookieLang == langs[i])
		        {
			        isValidLang = 1;
		        }
	        }
	        if (isValidLang == 1)
	        {
	           redirectWithLang(cookieLang);
	        }
        }
    else {
        var exp_date = new Date();
        exp_date.setFullYear( exp_date.getFullYear()+1 );
        setCookie(langCookieName, pageLang, exp_date)
    }
}

function redirectWithLang(lang)
{
    var exp_date = new Date();
    exp_date.setFullYear( exp_date.getFullYear()+1 );
    setCookie(langCookieName, lang, exp_date)
   // fn_RedirectByUserLang(lang);
}

function SelectLanguage_Changed(currLang)
{
	var selObj = document.getElementById("ddlLanguage");
	var selValue = selObj.value;
	var exp_date = new Date();
	exp_date.setFullYear( exp_date.getFullYear()+1 );
	setCookie(langCookieName, selValue, exp_date)
	var disp =  getQueryStringParam("disp");
	if (disp == "" && selValue != currLang)
		{fn_RedirectByUserLang(selValue);}
}

function fn_setLangCookie(lang)
{
	var found = 0;
	for(i=0; i<langs.length; i++)
	{
		if (lang == langs[i])
		{
			found = 1;
		}
	}
	if (found = 0)	{ return; }
	
	var exp_date = new Date();
	exp_date.setFullYear( exp_date.getFullYear()+1 );
	setCookie( langCookieName, lang, exp_date );
}
function fn_RedirectIndexPage(url)
{
	window.location = url+"?"+GetRandom(10000);
}
function fn_RedirectParent(url)
{
	window.opener.location = url+"?"+GetRandom(10000);
}
function fn_RedirectByUserLangAnUrl(lang, relativeUrl, parent)
{
	var rootUrl = relativeUrl;
    for (var i=0;i<langs.length; i++)
    {
        if (lang == langs[i])
        {
            rootUrl = paths[i] + rootUrl;
        }
    }
	if (parent) {
		fn_RedirectParent(AbsolutePath + rootUrl);
	} else {
    fn_RedirectIndexPage(AbsolutePath + rootUrl);
	}
}
function fn_RedirectByUserLang(lang)
{
    fn_RedirectByUserLangAnUrl(lang, "/index.html");
}

// a global month names array
var gsMonthNames = new Array(
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);

// a global day names array
var gsDayNames = new Array(
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
);

// the date format prototype
Date.prototype.format = function(f)
{
    if (!this.valueOf())
        return '&nbsp;';

    var d = this;

    return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
        function($1)
        {
            switch ($1.toLowerCase())
            {
            case 'yyyy': return d.getFullYear();
            case 'mmmm': return gsMonthNames[d.getMonth()];
            case 'mmm':  return gsMonthNames[d.getMonth()].substr(0, 3);
            case 'mm':   return (d.getMonth() + 1)/*.zf(2)*/;
            case 'dddd': return gsDayNames[d.getDay()];
            case 'ddd':  return gsDayNames[d.getDay()].substr(0, 3);
            case 'dd':   return d.getDate()/*.zf(2)*/;
            case 'hh':   return CheckTime(((h = d.getHours() % 12) ? h : 12))/*.zf(2)*/;
            case 'nn':   return CheckTime(d.getMinutes())/*.zf(2)*/;
            case 'ss':   return CheckTime(d.getSeconds())/*.zf(2)*/;
            case 'a/p':  return d.getHours() < 12 ? 'AM' : 'PM';
            }
        }
    );
}

function GetLocalTime(date, divId)
{
    var dt = Date.parse(date);
    var element;
    if (document.all)
      element = document.all[divId];
    else 
      element = document.getElementById(divId);
                  
    element.innerHTML = (new Date(dt)).format('hh:nn a/p dddd, mmmm dd');
}

function GetLocalDate(date,divId)
{
    var dt=Date.parse(date);
    var element;
    if (document.all)
      element = document.all[divId];
    else 
      element = document.getElementById(divId);    
     element.innerHTML = (new Date(dt)).format('mmmm dd, yyyy');
}

function GetLocalTimes(date)
{
   
}

function CountdownTime(startDate, divId)
{
	//alert(startDate + ' ' + divId);
	//var startDate = "October 25, 2006 13:00 PST";
	var dt = Date.parse(startDate);
	//msPerDay = 24 * 60 * 60 * 1000 ;
	var msDiff = new Date(dt).getTime() - new Date().getTime();
	var days = 0;
	var hours = 0;
	var minutes = 0;
	var seconds = 0;
	if (msDiff > 0)
	{
		msPerDay = 24 * 60 * 60 * 1000 ;
		days = msDiff / msPerDay;
		days = Math.floor(days);
		msDiff = msDiff - msPerDay * days;
		msPerHour = 60 * 60 * 1000;
		hours = msDiff / msPerHour;
		hours = Math.floor(hours);
		msDiff = msDiff - msPerHour * hours;
		msPerMinute = 60 * 1000;
		minutes = msDiff / msPerMinute;
		minutes = Math.floor(minutes);
		msDiff = msDiff - msPerMinute * minutes;
		seconds = msDiff / 1000;
		seconds = Math.floor(seconds);
	}
	hours = CheckTime(hours);
	minutes = CheckTime(minutes);
	seconds = CheckTime(seconds);
	var wordDay = ' days ';
	if (days == 1) wordDay = ' day ';
	document.getElementById(divId).innerHTML = days + wordDay + hours + ':' + minutes + ':' + seconds;
	
	t=setTimeout('CountdownTime("'+startDate+'","'+ divId +'")',1000)
}
function CheckTime(i)
{
	var ret = '';
	if (i < 10)
		ret += '0';
	return ret + i;
}

//CC-Deposit
 function setCredits()
 {
    
           var tbx_amount=document.getElementById(txbAmountID );
           var amount=tbx_amount.value;
           var creditBonus=0;
        if (amount < 25) { creditBonus = 0;}
        else if (amount < 50){creditBonus = 10; }
        else if (amount < 75){ creditBonus = 30;}
        else if (amount < 100) {creditBonus = 40;}
        else if (amount >= 100) {creditBonus = 100;}
        var label=document.getElementById(labelCreditsID );
        label.innerHTML=creditBonus;
     
        
 
 }
//end CC-Deposit

var ln;
ln = getQueryStringParam("lang");
 function oppckpp(ln)
       {
		    window.open('http://mahjongtime.com/Mahjong-Compare-Memberships.aspx?lang=' + ln,'a','scrollbars=yes,width=840,height=700');
	   }
