// JScript File
function cmtrim(str) {
	return str.replace(/^ */,"").replace(/ *$/,"");
}
function isDigit(str) {
    var reDigit = /^\d/
    return reDigit.test(str)
}
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
   if (strEmail.search(validRegExp) == -1)
		return false;
    else return true;
}
function ValidateEmail(oEmail) {
   	if (cmtrim(oEmail.value) == "") { alert('Please enter Email Address.'); oEmail.focus(); return false; }
	if (!isValidEmail(oEmail.value)) { alert('Please enter a valid email address.'); oEmail.focus(); return false; }
	return true;
}
var bStop;
function ValidateUserFields(Frm) {

 
  //var Frm = document.frmRegister;
  if (cmtrim(Frm.txt_FirstName.value) == "") { alert('Please enter your first name.'); Frm.txt_FirstName.focus(); return false; }
  if (cmtrim(Frm.txt_MobileNumber.value) == "") { alert('Please enter Mobile Number.'); Frm.txt_MobileNumber.focus(); return false; }
  
  if (!Frm.chk_ReadCond.checked)
  {
	alert("Please indicate that you agree to be bound by the Terms & Conditions and warrant that you have read and understood our Privacy Policy.");
  	return false;
  }
  
  if (! isDigit(cmtrim(Frm.txt_MobileNumber.value))) { alert('Please enter valid mobile number.'); Frm.txt_MobileNumber.focus(); return false;}
  if (cmtrim(Frm.txt_Email.value) != "" && !ValidateEmail(Frm.txt_Email)) return false ; 
  Frm.hdnOper.value = "register";
  bStop  = "y";
  
  Frm.submit();
  return true;
}
function ValidateMobileNumber(Frm) {

 if (bStop == "y") return true;
 if (cmtrim(Frm.txt_Unsubscribe_Mobile.value) == "") { alert('Please enter Mobile Number.'); Frm.txt_Unsubscribe_Mobile.focus(); return false; }
 if (! isDigit(cmtrim(Frm.txt_Unsubscribe_Mobile.value))) { alert('Please enter valid mobile number.'); Frm.txt_Unsubscribe_Mobile.focus(); return false;}
 Frm.hdnOper.value = "unsubscribe";
 return true;    
}
function DefaultToSubmitButton(Frm, oEvent, page) {
     var characterCode ;
  if(oEvent && oEvent.which) 
        characterCode = oEvent.which;
   else
        characterCode = oEvent.keyCode;
    if(characterCode == 13) {
        if (page == "register")
            return ValidateUserFields(Frm);
         if (page == "unsubscribe")
            return ValidateMobileNumber(Frm);
    }
    else 
        return true ; 
}
function validateAdminlogin() {
    if (cmtrim(document.frmAdminLogin.UserID.value) == "")
	{
	   	alert("Please enter user name.");
	   	document.frmAdminLogin.UserID.focus();
		return(false);
	}
	if (document.frmAdminLogin.Password.value == "")
	{
	   	alert("Please enter password.");
	   	document.frmAdminLogin.Password.focus();
		return(false);
	}
	else
	{
	    document.frmAdminLogin.hdn_submit.value = "Y";
		return(true); 
	}
}
function DisplayError(ErrorMsg) {
    if (ErrorMsg != "")
        alert(ErrorMsg);
}
function SubmitSMSTestingPage(Oper) {
    if (Oper == 'start') {
    	if (document.fromSMSTesting.CurrentDate.value == "") { alert("Please enter current date."); document.fromSMSTesting.CurrentDate.focus(); return(false); }
    	if (document.fromSMSTesting.time.value == "") { alert("Please enter time."); document.fromSMSTesting.time.focus(); return(false); }
    	if (document.fromSMSTesting.txtSchedulerTime.value == "") { alert("Please enter scheduler time."); document.fromSMSTesting.txtSchedulerTime.focus(); return(false); }
    }
    document.fromSMSTesting.Oper.value = Oper;
    document.fromSMSTesting.submit();
    return true;
}

function isEmailAddr (emailStr) {
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
   if (emailStr.search(validRegExp) == -1)
		return false;
    else return true;
}


function validate_enteryourjingle() {
	var errormsg ='';
	var errcount = 0;
    var frm = document.frmEntryYourJingle;

	if (cmtrim(frm.txtTagName.value) == "") { errormsg = errormsg + 'Tag name\n'; errcount = errcount + 1;
		 if (errcount==1){frm.txtTagName.focus();}
	}

	if (cmtrim(frm.txtEmailAddress.value) == "") { errormsg = errormsg + 'Email address\n'; errcount = errcount + 1;
		 if (errcount==1){frm.txtEmailAddress.focus();}
	}
	else {
		if (!isEmailAddr(cmtrim(frm.txtEmailAddress.value))) { errormsg = errormsg + 'Please enter a valid email address!\n'; errcount = errcount + 1;
			if (errcount==1){frm.txtEmailAddress.focus();}
		}
	
	}
	
	if (cmtrim(frm.inputFile.value) == "") { errormsg = errormsg + 'Look in video file\n'; errcount = errcount + 1;
		 if (errcount==1){frm.inputFile.focus();}
	}
		
	if (frm.chkTermCondition.checked == false) { errormsg = errormsg + 'I have read and understand the terms & conditions      \n'; errcount = errcount + 1;
		 if (errcount==1){frm.chkTermCondition.focus();}
	}

	if ( errormsg != "" ) {
	    alert('Please enter the following information:     \n'+ errormsg);
		return false;
	}
	else {
	    return true;
	    
        var answer = confirm ('CONFIRMATION OF TERMS OF ENTRY\n\n By uploading or recording my jingle to the Macleans website, I confirm that:\n\n-I am over the age of 18 and consent to GSK communicating my jingle entry, voice, image and likeness on the Macleans website; and \n  any other medium, including but not limited to television and radio;\n\n-I\'m under 18 and I have obtained my parent guardian\'s consent to enter this competition and for GSK to communicate my jingle entry, voice, \n  image and likeness on the Macleans website. ');
    	if (answer){
    		document.getElementById("inlineProgressBarDiv").style.visibility = "visible";
    		frm.hdnSubmitPage.value = "Y";
    		frm.submit();
	    	return true;
	    //	frm.submit();
    	}
    	else {
    	    return false;
	    }
    }
}
function validate_enteryourjingle1() {
	var errormsg ='';
	var errcount = 0;
    var frm = document.frmEntryYourJingle;

	if (cmtrim(frm.txtTagName.value) == "") { errormsg = errormsg + 'Tag name\n'; errcount = errcount + 1;
		 if (errcount==1){frm.txtTagName.focus();}
	}

	if (cmtrim(frm.txtEmailAddress.value) == "") { errormsg = errormsg + 'Email address\n'; errcount = errcount + 1;
		 if (errcount==1){frm.txtEmailAddress.focus();}
	}
	else {
		if (!isEmailAddr(cmtrim(frm.txtEmailAddress.value))) { errormsg = errormsg + 'Please enter a valid email address!\n'; errcount = errcount + 1;
			if (errcount==1){frm.txtEmailAddress.focus();}
		}
	
	}
	
	if (cmtrim(frm.inputFile.value) == "") { errormsg = errormsg + 'Look in video file\n'; errcount = errcount + 1;
		 if (errcount==1){frm.inputFile.focus();}
	}
		
	if (frm.chkTermCondition.checked == false) { errormsg = errormsg + 'I have read and understand the terms & conditions      \n'; errcount = errcount + 1;
		 if (errcount==1){frm.chkTermCondition.focus();}
	}

	if ( errormsg != "" ) {
	    alert('Please enter the following information:     \n'+ errormsg);
		return false;
	}
	else {
	    var answer = confirm ('CONFIRMATION OF TERMS OF ENTRY\n\n By uploading or recording my jingle to the Macleans website, I confirm that:\n\n-I am over the age of 18 and consent to GSK communicating my jingle entry, voice, image and likeness on the Macleans website; and \n  any other medium, including but not limited to television and radio;\n\n-I\'m under 18 and I have obtained my parent guardian\'s consent to enter this competition and for GSK to communicate my jingle entry, voice, \n  image and likeness on the Macleans website. ');
    	if (answer){
    		document.getElementById("inlineProgressBarDiv").style.visibility = "visible";
    		frm.hdnSubmitPage.value = "Y";
    		frm.submit();
	    	return true;
	    //	frm.submit();
    	}
    	else {
    	    return false;
	    }
    }
}
function showhide(DivName, bShow) {
  if (bShow)
    document.getElementById(DivName).className = "divShow";
  else
    document.getElementById(DivName).className = "divHide";
}
