
var G_sPopupUrl = "";
var SupportCenter = "";
var sHost = window.location.hostname;

  if (sHost == 'www.mega.com') {
  	SupportCenter = "https://support.mega.com/scripts/slxweb.dll";
  }
  else {
	SupportCenter = "http://w-jjeweb6:1030/scripts/slxweb.dll";
  }

//-------------------//
//  Launch Download  //
//-------------------//
function launchDownload(sUrl)
{
	G_sPopupUrl = sUrl;
	setTimeout("openWindow()", 1500);
}


//---------------//
//  Open Window  //
//---------------//
function openWindow()
{
	win = window.open(G_sPopupUrl, 'winDownload');
	
	if (! win)
	{
		alert("Your login was successful.\n\nAll files are now unlocked for downloading.\n\nYou are using a Popup Blocker so you will need to reselect   \nthe file you want to download.");
	}
}


//-------------//
//  RB Window  //
//-------------//

function RBWindow(scc, spw, sll, sau)
{
var viewport;

	var url = SupportCenter + '/view?name=custmainpage&contactname=' + scc
	

	viewport = window.open(url, null, "top=10,left=10,width=750,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}


function openLogout()
{
	var viewport;


	var url =  SupportCenter + '/action?name=custlogout'

	viewport = window.open(url, null, null);
	viewport.close();
}


//----------------//
//  Check Spaces  //
//----------------//
function checkSpaces(sNum)
{
	var sReturn = "";
	
	// Note: the character array must be identical to the array in Utility.GetEncodedArray()
	var aChars = Array('¤','¤','¤','¤','¤','¤','¤','¤','¤','¤','0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',',','.',';',':','!','?','_','-');
	var i;
	
	for (i=0; i < sNum.length; i+=2)
	{
		sReturn = sReturn + aChars[sNum.substring(i,i+2)];
	}
	
	return sReturn;
}


//---------------------//
//  Test Request Data  //
//---------------------//
function testRequestData(sFormName)
{
	sForm = eval("document." + sFormName);
	
	if ( sForm.CustomerId0.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.CustomerId0.focus( );
		return false;
	}
	else if ( sForm.CustomerId1.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.CustomerId1.focus( );
		return false;
	}
	else if ( sForm.CustomerId2.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.CustomerId2.focus( );
		return false;
	}
	else if ( sForm.CustomerId3.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.CustomerId3.focus( );
		return false;
	}
	else if ( sForm.email.value.length < 1 || ! (sForm.email.value.match(/[\w-]+@[\w-]+\.\w+/)) )
	{
		alert('Please enter a valid Email address.   \n\nExample: support@mega.com');
		sForm.email.focus( );
		return false;
	}
	else if ( sForm.firstname.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.firstname.focus( );
		return false;
	}
	else if ( sForm.lastname.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.lastname.focus( );
		return false;
	}
	else if ( sForm.company.value.length < 1 )
	{
		alert('All fields are required.   ');
		sForm.company.focus( );
		return false;
	}
	
	return true;
}


//---------------------//
//  Test Contact Data  //
//---------------------//
function testContactData(sFormName)
{
	sForm = eval("document." + sFormName);
	
	if ( sForm.subject.value.length < 1 )
	{
		alert('The Subject and the Description are required.   ');
		sForm.subject.focus( );
		return false;
	}
	else if ( sForm.description.value.length < 1 )
	{
		alert('The Subject and the Description are required.   ');
		sForm.description.focus( );
		return false;
	}
	
	sForm.fakeButtonOk.disabled = true;
	
	return true;
}


//---------------------//
//  Test Profile Data  //
//---------------------//
function testProfileData(sFormName)
{
	sForm = eval("document." + sFormName);
	
	if ( sForm.codeClient.value.length < 1 )
	{
		alert('Customer ID is required.   ');
		sForm.codeClient.focus( );
		return false;
	}
	else if ( sForm.nom.value.length < 1 )
	{
		alert('Last name and First name are required.   ');
		sForm.nom.focus( );
		return false;
	}
	else if ( sForm.prenom.value.length < 1 )
	{
		alert('Last name and First name are required.   ');
		sForm.prenom.focus( );
		return false;
	}
	else if ( sForm.email.value.length < 1 || ! (sForm.email.value.match(/[\w-]+@[\w-]+\.\w+/)) )
	{
		alert('Please enter a valid Email address.   \n\nExample: support@mega.com');
		sForm.email.focus( );
		return false;
	}
	else if ( sForm.password.value.length < 5 )
	{
		alert('Password is required and must be at least 5 characters.   ');
		sForm.password.focus( );
		return false;
	}
	
	return true;
}
