if(!document.all) {
	/* NS 4.7 and below */
	if(!document.getElementById) {
		var layerSwitch = 'document.layers';
		var formSwitch = 'document.forms';
		var flgNestedForm = true;
		var openBracketSwitch = '["';
		var closeLayerBracketSwitch = '"]';
		var closeFormBracketSwitch = '"]';
		var styleSwitch = '';
		var showSwitch = 'show';
		var hideSwitch = 'hide';
	/* NS 6.0 */
	} else {
		var layerSwitch = 'document.getElementById';
		var formSwitch = 'document.getElementsByName';
		var flgNestedForm = false;
		var openBracketSwitch = '("';
		var closeLayerBracketSwitch = '")';
		var closeFormBracketSwitch = '")[0]';
		var styleSwitch = '.style';
		var showSwitch = 'visible';
		var hideSwitch = 'hidden';
	}
/* IE 5.5 and below */
} else {
	var layerSwitch = 'document.all';
	var formSwitch = 'document.all';
	var flgNestedForm = false;
	var openBracketSwitch = '["';
	var closeLayerBracketSwitch = '"]';
	var closeFormBracketSwitch = '"]';
	var styleSwitch = '.style';
	var showSwitch = 'visible';
	var hideSwitch = 'hidden';
}

/* This function returns a string representing the object for the layer passed in.
	Use the eval() function on this string to get the layer object. */
function getLayer(layerName) {
	return layerSwitch + openBracketSwitch + layerName + closeLayerBracketSwitch;
}

/* This function returns a string representing the object for the form passed in.
	Use the eval() function on this string to get the form object. */
function getForm(formName) {
	return formSwitch + openBracketSwitch + formName + closeFormBracketSwitch;
}

/* This function returns a string representing the object for a form(formName) nested in a layer(layerName).
	Use the eval() function on this string to get the form object. */
function getNestedForm(layerName, formName) {
	if (!flgNestedForm) {
		return getForm(formName);
	} else {
		return getLayer(layerName) + '.' + getForm(formName);
	}
}

/* begin functions for rollovers */
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) { //v3.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); 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 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;
}
/* end functions for rollovers */

/* begin global functions */

/* Opens a new browser window
		page: the URL of the page to load in the new window
		windowName: a name given to the window
		winWidth, winHeight: the width and height of the new window
*/
function openWindow(page, windowName, winWidth, winHeight, winSpec, flgReturnObj) {
    var sizeSpec;
	if (!winSpec) {
		sizeSpec='toolbar=0,location=0,directories=0,left=10,top=10,status=no,menubar=0,scrollbars=1,resizable=yes,width='+winWidth+',height='+winHeight;
	} else {
		sizeSpec=winSpec+',width='+winWidth+',height='+winHeight;
	}
    var windowObject;
	windowObject=window.open(page,windowName,sizeSpec);
	if (flgReturnObj) return windowObject;
}

/*  Changes the text in the status bar
		statusText: the text to display
*/
function winStat(statusText) {
	window.status=statusText;
	return true;
}

/* end global functions */

/* begin homepage functions */

/* Clears the text in a text input
		formName: the name of the form that contains the input
		inputName: the name of the input to clear
		defaultText: the text that should be cleared
*/
function clearField(formName, inputName, defaultText) {
	var field = eval(getForm(formName) + '.' + inputName);
	if (field.value == defaultText) {
		field.value = '';
	}
	return true;
}

/* Trim string */
function trimStr(str) {
	var strObj = new String(str);
	while(''+strObj.charAt(0)==' ') {
		strObj=strObj.substring(1,strObj.length);
	}
	while(''+strObj.charAt(strObj.length-1)==' ') {
		strObj=strObj.substring(0,strObj.length-1);
	}
	return strObj;
}

/* Checks if a string is a valid email address
				begins with letter or digit, contains letters, digits, or any ".-"
				followed by an "@" followed by letters, digits, or any ".-" followed by two or three letters
		email: the string to test
*/
function isEmail(email) {
        if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
           return true ;

        return false;
}

/*  Checks if a string is alphanumeric
				begins with letter or digit, contains letters, digits, or any ".-"
				followed by an "@" followed by letters, digits, or any ".-" followed by two or three letters
		email: the string to test
*/
// Test Letter
// listas de caracteres

function isLetter (c)
{
    return (((c >= "a") && (c <= "z"))||((c >= "A") && (c <= "Z")));
}

// Test Digit
function isDigit (c)
{   
 return ((c >= "0") && (c <= "9"))
}


function isUserName(s) 
{
    var i;
	var c;
	
    if (s.length==0) return false;

    c = s.charAt(0);
	
	if (! (isLetter(c) || isDigit(c))) return false;
	
    for (i = 0; i < s.length; i++)
    {   
        c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) || c=="@" || c=="." || c=="-" || c=="_") )
        return false;
    }

    return true;
}

function buyNow(iDVDID,vProductCode,bCheckout) 
{
	var buyNowForm = eval(getForm("buyNowForm"));
	if (buyNowForm==null) 
	{
	 alert("Error, buyNowForm null !");
	 return;
	}
	
	buyNowForm.bJavaScript.value=1;
	buyNowForm.iDVDID.value=iDVDID;
	buyNowForm.vProductCode.value=vProductCode;
	buyNowForm.bCheckout.value=bCheckout;
	buyNowForm.submit();
}

function validateForm(formname) 
{
	var theForm = eval(getForm(formname));
	if (theForm==null) 
	{
	 alert("Error, " + formname + " null !");
	 return false;
	}
	
	theForm.bJavaScript.value=1;
	
	if (theForm.vUser && !isUserName(theForm.vUser.value))
	{
	 alert("Please enter a valid user name.");
	 return false;
	}
	
	if (theForm.vEmail && !isEmail(theForm.vEmail.value))
	{
	 alert("Please enter a valid email address.");
	 return false;
	}
	if (theForm.vEmail && theForm.vRepeatEmail && theForm.vEmail.value!=theForm.vRepeatEmail.value)
	{
	 alert("Please enter the same repeat email address than email address.");
	 return false;
	}
	
	return true;
}

function submitForm(formname) 
{
	var theForm = eval(getForm(formname));
	if (theForm==null) 
	{
	 alert("Error, " + formname + " null !");
	 return;
	}
	
	if (validateForm(formname)) theForm.submit();
}

function submitAction(formname, action) 
{
	var theForm = eval(getForm(formname));
	if (theForm==null) 
	{
	 alert("Error, " + formname + " null !");
	 return;
	}
	
	theForm.action.value=action;
	
	if (validateForm(formname)) theForm.submit();
}


function submitBack(formname) 
{
	var theForm = eval(getForm(formname));
	if (theForm==null) 
	{
	 alert("Error, " + formname + " null !");
	 return;
	}
	
	theForm.bJavaScript.value=1;
	theForm.action.value=theForm.lastAction.value;
	theForm.submit();
}

function submitSearch(formname,defaultText,ret) 
{
 var searchForm = eval(getForm(formname));
 if ((trimStr(searchForm.vKeywords.value)=="") ||
     (trimStr(searchForm.vKeywords.value)==defaultText))
 {
  alert("Please enter a search keyword.");
  searchForm.vKeywords.focus();
  if (ret) return false;
  else return;
 } 
 
 if (!ret) searchForm.submit();
 
 if (ret) return true;
}


function submitCatalogSearch(ret) 
{
 var searchForm = eval(getForm('searchCatalogForm'));
 /*if (trimStr(searchForm.vKeywords.value)=="") 
 {
  alert("Please enter a search keyword.");
  searchForm.vKeywords.focus();
  if (ret) return false;
 } */
 if (!ret) searchForm.submit();
 if (ret) return true;
}

function AlertDelete(message)
{
 return confirm("Do you want to delete this " + message + " ?");
}

function AlertCreate(message)
{
 return confirm("Do you want to create a new  " + message + " record ?");
}

/* end homepage functions */
