function popUp(name,URL,width,height) {
	eval(name + " = window.open('" + URL + "', '" + name + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

//Shows a div with display block
function showBlockDiv(id) {
  //assumes that prototype has been loaded.
  Element.setStyle($(id),{'display':'block'})
}

//Hides a div with display block
function hideBlockDiv(id) {
  //assumes that prototype has been loaded.
  Element.setStyle($(id),{'display':'none'})
}

//Hides or shows a DIV that's supposed to have block display
function toggleBlockDiv(id) {
    if (Element.getStyle(id,'display')=='block') {
      hideBlockDiv(id)
    } else {
      showBlockDiv(id)
    }
}

/** Toggle the Please Wait div, or a similar one.
    Pass null, if you want to use the default please wait div.
    Otherwise pass the ID you want to show during your wait period.
    The div will be centered */
function togglePleaseWait(please_wait_div_id) {
    if (please_wait_div_id == null) {
      please_wait_div_id = 'please_wait'
    }

    toggleBlockDiv(please_wait_div_id)

    if (Element.getStyle(please_wait_div_id,'display')=='block') {
      Effect.Center(please_wait_div_id)
      Element.setStyle($(please_wait_div_id),{'z-index':'1000'})
    }
}

function validateLoggedInTextAlertForm() {

	if (!document.forms.pinForm.termsAccept2.checked) {
		showBlockDiv('error_accept_terms')
		//Effect.Pulsate('error_accept_terms',{duration:2, from:0.3})
		return false
	} 
	hideBlockDiv('error_accept_terms')
	return true
}

function validateNotLoggedInTextAlertForm() {

	var valid_operator = true
	if (document.forms.signup.operatorId.value == "") { 
		showBlockDiv('error_invalid_operator')
		//Effect.Pulsate('error_invalid_operator',{duration:2, from:0.3})
		$('operatorIdSelect').focus()
		valid_operator = false
	}

	if (valid_operator) {
	  hideBlockDiv('error_invalid_operator')
    }

	
	var p1 = $('phoneNew1').value
	var p2 = $('phoneNew2').value
	var p3 = $('phoneNew3').value


	var valid_number = true
	if (isNaN(p1) || 
		isNaN(p2) || 
		isNaN(p3) ||
		p1=='' || 
		p2=='' || 
		p3=='' || 
		p1.length < 3 || 
		p2.length < 3 ||
		p3.length < 4) {

		valid_number = false

		showBlockDiv('error_invalid_number')

		//Effect.Pulsate('error_invalid_number',{duration:2, from:0.3})

		$('phoneNew1').focus()

	}

    if (valid_number) {
      hideBlockDiv('error_invalid_number')
    }
	return valid_operator && valid_number;
}

var IE4 = (document.all);
var NS4 = (document.layers);
var lastKeyPressed;
document.onkeypress = setLastKeyPressed;

function setLastKeyPressed(e)
{
	if (e != null)
		lastKeyPressed = e.which;
	else
		lastKeyPressed = false;
}

function nextfield(fldobj,elmid,frmname,maxchar,minchar,pelmid)
{
	if ((fldobj.value.length > minchar) && (fldobj.value.length < maxchar)) {
		fldobj.focus();
	}
	else if(fldobj.value.length == maxchar)
	{
		document.getElementById(elmid).focus()
	}
	else if ((fldobj.value.length == minchar) && ((lastKeyPressed == 8) || (!lastKeyPressed))) {
			document.getElementById(pelmid).focus();
			$(pelmid).select();
	}
}

//returns true if the fgiven email is a valid address, false otherwise.
function isEmailValid(email) {
  var emailRegexp=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
  return emailRegexp.test(email)
}
