function stepKey(nextfield, chars, currfield){
	x = currfield.value.length;
	if (x == chars) {
		o = document.getElementById(nextfield); //changed, not get the webwork's form_id
		if ( o != null)	o.focus();
	}
}

function checkYellowCheckBox(obj) {
    var error = false;
    var msg = '';
	var checked = document.getElementById( obj.id + '_terms');
    if ( checked.checked==false) {
        error = true;
    }
    if (error) {
       document.getElementById('alert').style.display = '';
       return false;
    }
    disPopup();
    document.getElementById('submitButton').disabled=true;
}

function checkRegister(obj) {
    var error = false;
    var msg = '';

	if (checkPhone(obj) == false) {
	    msg = msg + "- Mobile Number.\n";
	    error = true;
	}
	if (!checkOperator(obj)) {
		msg = msg + "- Operator.\n";
		error = true;
	}
    if (error) {
        alert("The following information is missing or invalid:\n\n" + msg + "\nPlease make sure you have provided the above information correctly before submitting the data.");
        return false;
    } else{
    	document.getElementById('submitButton').disabled=true;    
	disPopup();
	return true;
    }
}

function checkPhone(obj) {
    var p = obj.elements['msisdn.phone'].value.length;
    var q = obj.elements['msisdn.phone'].value.charAt(0);
    phoneValue = obj.elements['msisdn.phone'].value;
    pattern = /^(8|9)[0-9]{7}/;

    if (!pattern.test(phoneValue)) { 
        return false;
    } else {
        return true;
    }
}

function checkOperator(obj) {
	var o = obj.elements['operatorId'].value;
	
	if(o>4) {
		return true;
	}
	return false;
}



var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 15
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function hidediv() {
	if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById('timermsg1').style.display = 'none';
			document.getElementById('timermsg2').style.display = '';
		}
		else {
		if (document.layers) { // Netscape 4
		document.timermsg1.display = 'none';
		document.timermsg2.display = '';
		}
		else { // IE 4
		document.all.timermsg1.style.display = 'none';
		document.all.timermsg2.style.display = '';
		}
	}
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
		hidediv();
        //alert("You have just wasted 10 seconds of your life.")
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function isSecondPage(){
	if(document.getElementById('timermsg1') != null){
		InitializeTimer();
	}
}

function unloadPopup() {
    var Popup = window.open('/popup/countdown.html','','height=420,width=760,status=0,toolbar=0,menubar=0,location=0,scrollbars=1');
    Popup.focus();
}

function disPopup(){
	document.body.onunload = "";
	window.onunload= "";
}

function changeBgTimeout(){
	var browserName=navigator.appName;
	if ( browserName == "Microsoft Internet Explorer")
		chgTransparent();
	else
		setTimeout('chgTransparent()', 2000);
}

function chgTransparent(){
	if (document.getElementById('inputzone'))
		document.getElementById('inputzone').style.backgroundColor='transparent';	
}

function filtterSetting( landingId ){
	if (document.getElementById('submitButton') && document.getElementById('submitButton').currentStyle){
		var img = document.getElementById('submitButton').currentStyle.filter;
		if (img != null && img != ''){
			img = img.substring(img.indexOf('\'')+1);
			img = img.substring(0,img.indexOf('\''));
			document.getElementById('submitButton').style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/tm"+landingId+"/"+img+"', sizingMethod='crop')";
		}
	}
}

function tncTopSetting(){
	if (document.getElementById('tnc').currentStyle){
		var top = Math.abs( document.getElementById('tnc').currentStyle.top.substring(0,3));
		top = top + 50;
		document.getElementById('tnc').style.top = top + 'px';	
	}
}