/* This function is used to open a pop-up window */
function openWindow(url, winTitle, winParams) {
    winName = window.open(url, winTitle, winParams);
    winName.focus();
}

function popUpWindow(winTitle, winParams, title, message) {
    if (winParams == '') winParams = 'scrollbars=1,width=600,height=400';
    var Popup = window.open('', winTitle, winParams);
    Popup.focus();
    Popup.document.write('<html><head><title>');
    Popup.document.write(title);
    Popup.document.write('</title><link rel="stylesheet" type="text/css" media="all" href="/style/default.css"/></head><body>');
    Popup.document.write(message);
    Popup.document.write('</body></html>');
}

// This function is for stripping leading and trailing spaces
function trim(str) {
    if (str != null) {
        var i;
        for (i = 0; i < str.length; i++) {
            if (str.charAt(i) != " ") {
                str = str.substring(i, str.length);
                break;
            }
        }

        for (i = str.length - 1; i >= 0; i--) {
            if (str.charAt(i) != " ") {
                str = str.substring(0, i + 1);
                break;
            }
        }

        if (str.charAt(0) == " ") {
            return "";
        } else {
            return str;
        }
    }
}

// This function is used by the login screen to validate user/pass
// are entered. 
function validateRequired(form) {
    var bValid = true;
    var focusField = null;
    var i = 0;
    var fields = new Array();
    oRequired = new required();

    for (x in oRequired) {
        if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && form[oRequired[x][0]].value == '') {
            if (i == 0)
                focusField = form[oRequired[x][0]];

            fields[i++] = oRequired[x][1];

            bValid = false;
        }
    }

    if (fields.length > 0) {
        focusField.focus();
        alert(fields.join('\n'));
    }

    return bValid;
}

function displayOnOff(o) {
    var obj = document.getElementById(o);
    if (obj.style.display == "") {
        obj.style.display = "none";
    } else {
        obj.style.display = "";
    }
}

function changeStyle(o,cla, k, s) {
    var obj = document.getElementById(o);
    obj.className = cla;
    var ko = document.getElementById(k);
    if(s == 'o') {
        ko.style.display = '';
    } else {
        ko.style.display = 'none';
    }
}

function changeStyle2(o,cla) {
    var obj = document.getElementById(o);
    obj.className = cla;
}

function confirmOff() {
    var msg = "Are you sure you want to deactivate this campaign?";
    ans = confirm(msg);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

function confirmLapse() {
    var msg = "Are you sure you want to lapse this campaign?";
    ans = confirm(msg);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

function confirmRevive(){
    var msg = "Are you sure you want to revive this campaign?";
    ans = confirm(msg);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

function confirmSignUp() {
    var msg = "Are you sure you want to signup this campaign?";
    ans = confirm(msg);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

function confirmSignUpT(desc) {
	var msg = "Are you sure you want to signup this campaign @ " + desc + "?";
	ans = confirm(msg);
	if(ans) {
		return true;
	} else {
		return false;
	}
}

function clearKeyword(obj) {
    if (obj.value == "Keyword") {
        obj.value = "";
    } else {
    }
}

function restoreKeyword(obj) {
    if (obj.value == "") {
        obj.value = "Keyword";
    } else {
    }
}

function checkKeyword(obj) {
    if (obj.value == "Keyword" || obj.value == " ") {
        alert("Please type a keyword to search.\n")
        return false;
    } else {
        return true;
    }
}

function checkLogin(obj) {
    var error = false;
    var msg = '';
    if (!checkPhone(obj) || (obj.password.value == '')) {
        if (!checkPhone(obj)) {
            msg = msg + "- Mobile Number.\n";
            error = true;
        }
/*        if (obj.password.value == '') {
            msg = msg + "- Password.\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;
    }
}

function checkRegister(obj) {
    var error = false;
    var msg = '';
    if ( ((obj.areacode !=undefined && obj.prefix !=undefined && obj.suffix !=undefined) && (!checkPhone(obj) || !checkPhone2(obj))) ||!obj.terms.checked) {
        if (obj.areacode !=undefined && obj.prefix !=undefined && obj.suffix !=undefined && !checkPhone(obj)) {
            msg = msg + "- Mobile Number.\n";
            error = true;
        }
        if(obj.areacode !=undefined && obj.prefix !=undefined && obj.suffix !=undefined && !checkPhone2(obj)) {
            msg = msg + "- Do not include 0 as the first digit of cell phone number.\n"
            error = true;
        }
        if (!obj.terms.checked) {
            msg = msg + "- Terms of Service Acceptance.\n"
            error = true;
        }
    }
    
    //temporary shown on UI for horoscope campaign
    if (document.getElementById("horo12") != null) {
        if (obj.horo12.value == -1) {
            msg = msg + "- " + "Horoscope" + "\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;
    	return true;
    }
}

function checkRegisterWithHandSet(obj) {
    var error = false;
    var msg = '';
    if (!checkPhone(obj) || !checkPhone2(obj) ||!obj.terms.checked || !(obj.useragentId.value > 0)) {
        if (!checkPhone(obj)) {
            msg = msg + "- Mobile Number.\n";
            error = true;
        }
        if(!checkPhone2(obj)) {
            msg = msg + "- Do not include 0 as the first digit of cell phone number.\n"
            error = true;
        }
        if (!obj.terms.checked) {
            msg = msg + "- Terms of Service Acceptance.\n"
            error = true;
        }
        if (!(obj.useragentId.value > 0)) {
        	msg = msg + "- HandSet.\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;
    	return true;    
    }
}

function checkRegisterWithNoTerms(obj) {	
    var error = false;
    var msg = '';
    if (!checkPhone(obj) || !checkPhone2(obj) ||(obj.operator!=undefined && obj.operator.value  < 0)) {
        if (!checkPhone(obj)) {
            msg = msg + "- Mobile Number.\n";
            error = true;
        }
        if(!checkPhone2(obj)) {
            msg = msg + "- Do not include 0 as the first digit of cell phone number.\n"
            error = true;
        }             
        if (obj.operator!=undefined && obj.operator.value == -1) {
	    msg = msg + "- Telecommunication Carrier.\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;
    }
    
    document.body.onunload = function em(){return true;}
    document.getElementById('submitButton').disabled=true;    
    return true;

}

function checkRegisterWithNoTerms_ES(obj) {	
    var error = false;
    var msg = '';
    if (!checkPhone(obj) || !checkPhone2(obj) ||(obj.operator!=undefined && obj.operator.value  < 0)) {
        if (!checkPhone(obj)) {
            msg = msg + "- Nmero de Celular\n";
            error = true;
        }
        if(!checkPhone2(obj)) {
            msg = msg + "- No incluir 0 como primer dgito del nmero celular\n"
            error = true;
        }             
        if (obj.operator!=undefined && obj.operator.value == -1) {
	    msg = msg + "- Compaa de Telecomunicaciones\n"
	    error = true;
		}       
    }
    if (error) {
        alert("La siguiente informacin esta incompleta o es incorrecta:\n\n" + msg + "\nPor favor asegrese de haber completado la informacin correctamente antes de enviarla.");
        return false;
    }
    
    document.body.onunload = function em(){return true;}
    document.getElementById('submitButton').disabled=true;    
    return true;
}

function checkRegisterT(obj) {
	document.body.onunload = function em(){return true;}
	
    var error = false;
    var msg = '';
    if (!checkPhone(obj) || !checkPhone2(obj) || !obj.operator.checked) {
        if (!checkPhone(obj)) {
            msg = msg + "- Mobile Number.\n";
            error = true;
        }
        if(!checkPhone2(obj)) {
            msg = msg + "- Do not include 0 as the first digit of cell phone number.\n"
            error = true;
        }
        if (!obj.terms.checked) {
            msg = msg + "- Terms of Service Acceptance.\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;
        return true;
    }
}

function checklength(nextfield,chars,currfield) {
  x= document.phone[currfield].value.length
  if (x == chars) {
    eval('document.phone.' + nextfield + '.focus();');
  }
}

function checklength2(nextfield,chars,currfield) {
  x= document.login[currfield].value.length
  if (x == chars) {
    eval('document.login.' + nextfield + '.focus();');
  }
}
function checklength2a(nextfield,chars,currfield) {
  x= document.login[currfield].value.length
  if (x == chars) {
    eval('document.loginA.' + nextfield + '.focus();');
  }
}
function checklength3(nextfield,chars,currfield) {
  x= document.register[currfield].value.length
  if (x == chars) {
    eval('document.register.' + nextfield + '.focus();');
  }
}

function checklength4(nextfield,chars,currfield) {
  x= document.resetpassword[currfield].value.length
  if (x == chars) {
    eval('document.resetpassword.' + nextfield + '.focus();');
  }
}

function checklength5(nextfield,chars,currfield) {
  x= (document.getElementsByName(currfield)[0]).value.length;
  if (x == chars) {
	 (document.getElementsByName(nextfield)[0]).focus();
  }
}

function checkPhone2(obj) {
    if(obj.areacode.value.charAt(0) != 0) {
        return true;
    }
    return false;
}

function checkPhone(obj) {
    var a = obj.areacode.value.length;
    var p = obj.prefix.value.length;
    var s = obj.suffix.value.length;
/*    if(obj.prefix.value.charAt(0) == 0) {
        return false;
    }*/
    if(a == 3 && p == 3 && (s == 4 || s== 5)){
        return true;
    }
    return false;
}

function unloadPopup(str) {
//    alert("popop");
    var Popup = window.open(str,'','height=600,width=800,status=0,toolbar=0,menubar=0,location=0,scrollbars=1');
    Popup.focus();
}

function unloadPopup1(str) {
//    alert("popop");
    var Popup = window.open(str,'','height=420,width=760,status=0,toolbar=0,menubar=0,location=0');
    Popup.focus();
}

function typeSubmit(obj) {
    document.body.onunload = function em(){return true;}
    return true;
}

function type2SubmitWithTerms(obj) {
    document.body.onunload = function em(){return true;}
    
    var error = false;
    var msg = '';

    if (!obj.terms.checked) {
        msg = msg + "- Terms of Service Acceptance.\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;
    }      
    document.getElementById('submitButton').disabled=true;          
    return true;
}

function type2SubmitWithTermsIV(obj) {
	document.body.onunload = function em(){return true;}
	var error = false;
	if(!obj.terms.checked) {
		error = true;
	}
	if(error) {
		document.getElementById('alert').style.display = '';
		return false;
	}
	document.getElementById('submitButton').disabled=true;
	return true;
}

var domTT_styleClass = 'domTTOverlib';
var domTT_maxWidth = false;
try
{
    var winCloseButton = document.createElement('img');
    winCloseButton.src = '/images/pu_closebutton.gif';
	winCloseButton.style.verticalAlign = 'bottom';
}
catch (e)
{
    var winCloseButton = 'X';
}

function logo_click(op, checklogoclick){
	if (checklogoclick) {
	    var obj = document.getElementsByName('operator')[0];
     	for (var n = 0; n < obj.options.length; n++) {
    		if(op == obj.options[n].value){
    			obj.options[n].selected = 'selected';
    		}    		
    	}
    }
}

function disPopup(){
	document.body.onunload = "";
	window.onunload= "";
}
// Show the document's title on the status bar
//window.defaultStatus = document.title;
//window.defaultStatus = window.self.name;

function changeBgTimeout(){}