function msg(n_msg,x){
var msg="The following fields were found to be blank or incorrect.\nKindly check and correct it before submiting the form \n"
msg=msg+"------------------------------------------------------------------\n\n"
msg=msg+n_msg+"\n\n"
if(x==1){alert(msg); return false;}
}

//for email addresses
var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

//illegal characters in fields
var illegalCharStr = '~!@#$%^*()<>{}[]=?/\\\":;';
 	
// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//check for illegal characters
function checkIlleg(va)
{
	var stripped = stripCharsInBag (va, illegalCharStr);
	if(va != '' && stripped.length < va.length)
	{
		return false;
	}
	return true;
}

//check for tel number
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

var whitespace = " \t\n\r";

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)
{   var i;
    // Is s empty?
    if (isEmpty(s)) return true;
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


//Verify TEXTAREA field - general
function VerifyMsg(f_ld,c_nt,cnt_fld) {

	var len = f_ld.value.length
	var cl

	if ((len == 1) && (f_ld.value.substring(0, 1) == " ")) {
		f_ld.value = ""
		len = 0
	}
	if (len > (c_nt-10)) {
		f_ld.value = f_ld.value.substring(0, c_nt)
		cl = 0
	}
	else {
		cl = c_nt - len
	}
	eval(cnt_fld).value = cl
}

//Editorial Form Validation
function edtValidate(){
	var x=0;
	var err_msg=""		
	if (!document.MECSCForm.title.value) {
		err_msg=err_msg+"Title\n"; x=1;
		}		
	if (!document.MECSCForm.descsm.value) {
		err_msg=err_msg+"Description (Newsletter)\n"; x=1;
		}	
	if (!document.MECSCForm.desc.value) {
		err_msg=err_msg+"Description (Complete)\n"; x=1;
		}	
	return msg(err_msg,x)
	}	

//Editor's Message Form Validation
function edtmsgValidate(){
	var x=0;
	var err_msg=""		
	if (!document.MECSCForm.edtmsg_title.value) {
		err_msg=err_msg+"Title\n"; x=1;
		}		
	if (!document.MECSCForm.edtmsg_desc_sm.value) {
		err_msg=err_msg+"Message (Newsletter)\n"; x=1;
		}	
	if (!document.MECSCForm.edtmsg_desc.value) {
		err_msg=err_msg+"Message (Complete)\n"; x=1;
		}	
	return msg(err_msg,x)
	}	

//Editor's Message Delete Record check
function edtDelCheck1() {
	var conf = confirm("The Editor's Message will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}
		
//Editorial Delete Record check
function edtDelCheck() {
	var conf = confirm("The Editorial will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}
	
//Upload Image form Validation
function imgValidate(){
	var x=0;
	var err_msg=""
	if(!document.MECSCForm.photo0.value){
		err_msg=err_msg+"Photo for Newsletter\n"; x=1;
		}
	return msg(err_msg,x);
	}

//News Bytes Form Validation
function newsValidate(){
	var x=0;
	var err_msg=""		
	if (!document.MECSCForm.title.value) {
		err_msg=err_msg+"Title\n"; x=1;
		}		
	return msg(err_msg,x)
	}	
	
//Editorial Delete Record check
function newsDelCheck() {
	var conf = confirm("The News Byte will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}
	
//Newsletter Launch check
function launchCheck() {
	var conf = confirm("This newsletter will be launched and made online.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}

//Send newsletter form Validation
function sndValidate(){
	var x=0;
	var err_msg=""
	if(!document.MECSCForm.subj.value){
		err_msg=err_msg+"Subject\n"; x=1;
		}
	if(!document.MECSCForm.sender.value){
		err_msg=err_msg+"Sender's Address\n"; x=1;
		}
	else if (!isEmail(document.MECSCForm.sender.value)) {
		err_msg=err_msg+"Sender's Address is not valid\n"; x=1;
		}
	if(!document.MECSCForm.emlmode[0].checked && !document.MECSCForm.emlmode[1].checked && !document.MECSCForm.emlmode[2].checked){
		err_msg=err_msg+"Select Subscriber List\n"; x=1;
		}	
	if(document.MECSCForm.emlmode[0].checked){
		if(!document.MECSCForm.txtfile.value){
			err_msg=err_msg+"Upload Text File\n"; x=1;
			}
		}	
	if(document.MECSCForm.emlmode[1].checked){
		if(!document.MECSCForm.addr.value){
			err_msg=err_msg+"Enter Email addresses\n"; x=1;
			}
		}	
	if(x==1){
		return msg(err_msg,x);
		}
	else {
		var conf = confirm("This will broadcast the current newsletter to all the subscribers selected.\nAre you sure?")
		if(!conf) 
			return false;
		else
			return true;
		}	
	}		
	

//Subscribe Form Validation
function subValidate(){
	var x=0;
	var err_msg=""
	if (!document.MECSCForm.name.value) {
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if (!document.MECSCForm.lname.value) {
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if (!document.MECSCForm.dsgntn.value) {
		err_msg=err_msg+"Designation\n"; x=1;
		}	
	if (!document.MECSCForm.cmpny.value) {
		err_msg=err_msg+"Company\n"; x=1;
		}
	if (!document.MECSCForm.tel.value) {
		err_msg=err_msg+"Tel. No.\n"; x=1;
		}
	if (!document.MECSCForm.email.value) {
		err_msg=err_msg+"Email\n"; x=1;
		}
	else if (!isEmail(document.MECSCForm.email.value)) {
		err_msg=err_msg+"Email Address is not valid\n"; x=1;
		}		
	if ((!document.MECSCForm.postaddr.value )&& (!document.MECSCForm.postalcode.value) ) {
		err_msg=err_msg+"Address - P.O Box OR Street Address \n"; x=1;
		}
	if (!document.MECSCForm.city.value) {
		err_msg=err_msg+"City\n"; x=1;
		}	
	if(!document.MECSCForm.cntry[document.MECSCForm.cntry.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}			
	if (!document.MECSCForm.cprofile.value) {
		err_msg=err_msg+"Company Profile \n"; x=1;
		}
	return msg(err_msg,x)
	}		

	
//Editorial Delete Record check
function vacDelCheck() {
	var conf = confirm("The vacancy information will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	

//Products - profile Form Validation
function prfValidate(){
	var x=0;
	var err_msg=""
	if (!document.MECSCForm.catid.value) {
		err_msg=err_msg+"Category\n"; x=1;
		}		
	if (!document.MECSCForm.cmpnyname.value) {
		err_msg=err_msg+"Name\n"; x=1;
		}		
	return msg(err_msg,x)
	}		
	
//Products - search Form Validation
function srchValidate(){
	var x=0;
	var err_msg=""
	if (!document.MECSCForm.keywrd.value || document.MECSCForm.keywrd.value=="Enter a word or phrase") {
		err_msg=err_msg+"Enter a word or phrase\n"; x=1;
		}
	else {
		if (!checkIlleg(document.MECSCForm.keywrd.value)){
			err_msg=err_msg+"Search - Invalid Characters\n"; x=1;
			}
		}
	return msg(err_msg,x)
	}	
		
//Newsletter change status check
function nlstatsCheck() {
	var conf = confirm("The status of the Newsletter will be modified.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}	
	

//Retail Market Update Request Form Validation
function rmurValidate(){
	var x=0;
	var err_msg=""
	if (!document.MECSCForm.mallname.value) {
		err_msg=err_msg+"Mall Name\n"; x=1;
		}
	if (!document.MECSCForm.city.value) {
		err_msg=err_msg+"City\n"; x=1;
		}
	if(!document.MECSCForm.cntry[document.MECSCForm.cntry.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}
	if (!document.MECSCForm.telcc.value || !document.MECSCForm.telac.value || !document.MECSCForm.telno.value) {
		err_msg=err_msg+"Contact Number\n"; x=1;
		}	
	if (!document.MECSCForm.fname.value) {
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if (!document.MECSCForm.lname.value) {
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if (!document.MECSCForm.dsgntn.value) {
		err_msg=err_msg+"Designation\n"; x=1;
		}	
	if (!document.MECSCForm.owner.value) {
		err_msg=err_msg+"Owner\n"; x=1;		
		}
	if (document.MECSCForm.email.value) {
		if (!isEmail(document.MECSCForm.email.value)) {
			err_msg=err_msg+"Email Address is not valid\n"; x=1;
			}
		}		
	if (!document.MECSCForm.malldate.value) {
		err_msg=err_msg+"Date of Opening\n"; x=1;
		}
	if (!document.MECSCForm.nounits.value) {
		err_msg=err_msg+"Number of Units\n"; x=1;
		}		
	if (!document.MECSCForm.parking.value) {
		err_msg=err_msg+"Parking Spaces\n"; x=1;
		}
	if (!document.MECSCForm.gbarea.value) {
		err_msg=err_msg+"Gross Built-up Area (sq.m.)\n"; x=1;
		}		
	if (!document.MECSCForm.glarea.value) {
		err_msg=err_msg+"Gross Leaseable Area (sq.m.)\n"; x=1;
		}		
	return msg(err_msg,x)
	}		


//Join MECSC Form Validation
function joinValidate(){
	var x=0;
	var err_msg=""
	if(!document.MECSCForm.sal[document.MECSCForm.sal.selectedIndex].value){
		err_msg=err_msg+"Salutation\n"; x=1;
		}
	if (!document.MECSCForm.fname.value) {
		err_msg=err_msg+"First Name\n"; x=1;
		}
	if (!document.MECSCForm.lname.value) {
		err_msg=err_msg+"Last Name\n"; x=1;
		}
	if (!document.MECSCForm.company.value) {
		err_msg=err_msg+"Company\n"; x=1;
		}
	if (!document.MECSCForm.dsgntn.value) {
		err_msg=err_msg+"Designation\n"; x=1;
		}			
	if (!document.MECSCForm.maddress.value) {
		err_msg=err_msg+"Mailing Address\n"; x=1;
		}		
	if (!document.MECSCForm.city.value) {
		err_msg=err_msg+"City\n"; x=1;
		}		
	if(!document.MECSCForm.cntry[document.MECSCForm.cntry.selectedIndex].value){
		err_msg=err_msg+"Country\n"; x=1;
		}
	if (!document.MECSCForm.btelcc.value || !document.MECSCForm.btelac.value || !document.MECSCForm.btelno.value) {
		err_msg=err_msg+"Business Phone\n"; x=1;
		}	
	if (!document.MECSCForm.email.value) {
		err_msg=err_msg+"Email\n"; x=1;
		}
		/*
	if (!document.MECSCForm.filename.value) {
		err_msg=err_msg+"Attach your photo\n"; x=1;
		}	*/
	else if (!isEmail(document.MECSCForm.email.value)) {
		err_msg=err_msg+"Email Address is not valid\n"; x=1;
		}
	if(document.MECSCForm.paytype[0].checked){
		if(document.MECSCForm.cardtype[document.MECSCForm.cardtype.selectedIndex].value=='0'){
			err_msg=err_msg+"Card Type\n"; x=1;
			}
		if(!document.MECSCForm.chname.value){
			err_msg=err_msg+"Card Holder's Name\n"; x=1;
			}
		if(!document.MECSCForm.cardno.value){
			err_msg=err_msg+"Card Number\n"; x=1;
			}
		if(isNaN(document.MECSCForm.cardno.value)){
			err_msg=err_msg+"Invalid Card Number\n"; x=1;
			}
		if(document.MECSCForm.cexpmon[document.MECSCForm.cexpmon.selectedIndex].value=='0'){
			err_msg=err_msg+"Card Expiry Month\n"; x=1;
			}
		if(document.MECSCForm.cexpyear[document.MECSCForm.cexpyear.selectedIndex].value=='0'){
			err_msg=err_msg+"Card Expiry Year\n"; x=1;
			}
		}
	if(!document.MECSCForm.agree[0].checked && !document.MECSCForm.agree[1].checked ){
		err_msg=err_msg+"Select Confidentiality Agreement\n"; x=1;
		}
	return msg(err_msg,x)
	}		
	
//Editorial Delete Record check
function DelCheck() {
	var conf = confirm("The record will be permanently deleted from the database.\nAre you sure?")
	if(!conf) 
		return false;
	else
		return true;
	}		