//validation for manditory

//var errorColor="orange";

var errorColor = "#FFFFCC";

var bgColor = "white";

//history.forward(1);

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;
        }
    }
}


function hasValue(obj, obj_type, helperMsg, spanid) {



    //alert("hasValue");

    //alert("  # obj============>"+obj+"\nobj_type============>"+obj_type+"\n"+"helperMsg==========>"+helperMsg);

    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE") {

        if (obj.value.length == 0) {

            obj.style.backgroundColor = errorColor;


            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else if (document.all && document.all["_" + obj.name + "_editor"] && (obj.value == '<P>&nbsp;</P>')) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "SELECT") {


        if (obj.value == -1) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {



        //if (obj.length) {



        //	for (i=0; i < obj.length; i++) {


        if (obj.checked) {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;


        } else {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        }


    }

    return false;

}


/////
function hasValue5(obj, obj_type,
                   helperMsg, spanid) {
    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE") {
        var ovalue = obj.value;
        //alert("ovalue.charAt(0)========="+ovalue.charAt(0));
        if (ovalue.charAt(0) == 0 && obj.value.length != 0) {
            obj.style.backgroundColor = errorColor;
            document.getElementById(spanid).innerHTML = txt;
            //obj.focus();
            return false;
        }
        else {
            document.getElementById(spanid).innerHTML = "";
            obj.style.backgroundColor = bgColor;
            return true;
        }
    }
}
//////


function hasValue6(obj, obj_type,
                   helperMsg, spanid) {
    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE") {
        var ovalue = obj.value;
        //alert("ovalue.charAt(0)========="+ovalue.charAt(0));
        if (obj.value.length != 0) {
            if (ovalue.charAt(0) == 0) {
                obj.style.backgroundColor = errorColor;
                document.getElementById(spanid).innerHTML = txt;
                return false;
            }
            if (obj.value.length > 10 || obj.value.length < 10) {
                obj.style.backgroundColor = errorColor;
                document.getElementById(spanid).innerHTML = txt;
                return false;
            }
            if (obj.value.length = 10) {
                document.getElementById(spanid).innerHTML = "";
                obj.style.backgroundColor = bgColor;
                return true;
            }
        } else {

            document.getElementById(spanid).innerHTML = "";
            obj.style.backgroundColor = bgColor;
            return true;

        }
    }
}
//////


function lengthCriteria(elem1,minlength,maxlength,length,helperMsg,spanid)

{

    var txt = "<span class='error_txt'>" + helperMsg + "<br/></span>";

    if (minlength < length ||maxlength > length ) {

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

        return false;

    }


    return true;

}



function lengthGreater(elem1, length,
                     helperMsg,
                     spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + "<br/></span>";

    var len = elem1.value;


    if (len.length > length) {

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

        return false;

    }


    return true;

}




















function hasValue4(obj, obj_type, helperMsg, spanid) {

    //alert("obj============>"+obj+"\nobj_type============>"+obj_type+"\n"+"helperMsg==========>"+helperMsg);
	
    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE") {


        if (obj.value.length == 0) {

            obj.style.backgroundColor = errorColor;


            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else if (document.all && document.all["_" + obj.name + "_editor"] && (obj.value == '<P>&nbsp;</P>')) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "SELECT") {

        if (obj.value == 1) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "SELECT") {

        if (obj.value == 1) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "RADIO") {

        var status = false;

        for (i = 0; i < obj.length; i++) {

            if (obj[i].checked) {
                document.getElementById(spanid).innerHTML = "";

                //obj.style.backgroundColor = bgColor;

                status = true;


            }


        }
        if (!status) {
            //obj.style.backgroundColor = errorColor;
            document.getElementById(spanid).innerHTML = txt;


        }


        return status;

    } else if (obj_type == "CHECKBOX") {

        if (obj.checked) {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;


        } else {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        }

    }

    return false;

}
//////////////

function hasValue4l(obj, obj_type,
                    helperMsg, spanid,
                    spanid1) {

    //alert("obj============>"+obj+"\nobj_type============>"+obj_type+"\n"+"helperMsg==========>"+helperMsg);

    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    if (obj_type == "TEXT" || obj_type == "PASSWORD" || obj_type == "TEXTAREA" || obj_type == "FILE") {


        if (obj.value.length == 0) {

            obj.style.backgroundColor = errorColor;


            document.getElementById(spanid).innerHTML = txt;
            document.getElementById(spanid1).style.display = "";


            //obj.focus();

            return false;

        } else if (document.all && document.all["_" + obj.name + "_editor"] && (obj.value == '<P>&nbsp;</P>')) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;
            document.getElementById(spanid1).style.display = "";


            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";
            document.getElementById(spanid1).style.display = "none";


            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "SELECT") {

        if (obj.value == 1) {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        } else {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;

        }

    } else if (obj_type == "RADIO" || obj_type == "CHECKBOX") {





        //if (obj.length) {



        //	for (i=0; i < obj.length; i++) {


        if (obj.checked) {

            document.getElementById(spanid).innerHTML = "";

            obj.style.backgroundColor = bgColor;

            return true;


        } else {

            obj.style.backgroundColor = errorColor;

            document.getElementById(spanid).innerHTML = txt;

            //obj.focus();

            return false;

        }


    }

    return false;

}


////////////

function hasValue8(obj, obj_type,
                   helperMsg, spanid) {

    //alert("obj============>"+obj.value+"\nobj_type============>"+obj_type+"\n"+"helperMsg==========>"+helperMsg);

    obj.value = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    if (obj.value == -1) {
        obj.style.backgroundColor = errorColor;
        document.getElementById(spanid).innerHTML = txt;
        return false;
    } else {
        document.getElementById(spanid).innerHTML = "";
        obj.style.backgroundColor = bgColor;
        return true;
    }

}


//validation for numeric 2 argument

function isNumeric(elem, helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var numericExpression = /^[0-9]+$/;

    if (elem.value.match(numericExpression)) {

        elem.style.backgroundColor = bgColor;

        document.getElementById("errorContent").innerHTML = "";

        return true;

    } else {

        elem.style.backgroundColor = errorColor;

        document.getElementById("errorContent").innerHTML = txt;

        elem.focus();

        return false;

    }

}

//validation for numeric 3 argument

function isNumeric3(elem, helperMsg,
                    spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var numericExpression = /^[0-9]+$/;

    if (elem.value.match(numericExpression)) {

        elem.style.backgroundColor = bgColor;

        document.getElementById(spanid).innerHTML = "";

        return true;

    } else {

        elem.style.backgroundColor = errorColor;

        document.getElementById(spanid).innerHTML = txt;

        elem.focus();

        return false;

    }

}


//Validation for email 2 argument

function emailValidator(elem,
                        helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    //var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.(aero$|asia$|biz$|cat$|com$|coop$|edu$|gov$|info$|jobs$|mil$|mobi$|museum$|in$|name$|net$|org$|travel$|int$|co.in$)/;


    if (elem.value.match(emailExp)) {

        elem.style.backgroundColor = bgColor;

        document.getElementById("errorContent").innerHTML = "";

        return true;

    } else {

        elem.style.backgroundColor = errorColor;

        document.getElementById("errorContent").innerHTML = txt;

        elem.focus();

        return false;

    }

}


//Validation for email 2 argument , (obj, obj_type, helperMsg,spanid) {

function emailValidator3(elem,
                         helperMsg,
                         spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    //var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.(aero$|asia$|biz$|cat$|com$|coop$|edu$|gov$|info$|jobs$|mil$|mobi$|museum$|in$|name$|net$|org$|travel$|int$|co.in$)/;
    if (elem.value.match(emailExp)) {

        elem.style.backgroundColor = bgColor;

        document.getElementById(spanid).innerHTML = "";

        return true;

    } else {

        elem.style.backgroundColor = errorColor;

        document.getElementById(spanid).innerHTML = txt;

        elem.focus();

        return false;

    }

}

function emailMatch(email, aemail, helperMsg, spanid) {


    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    if (email.value != aemail.value) {

        aemail.style.backgroundColor = bgColor;

        document.getElementById(spanid).innerHTML = "";

        return true;

    } else {

        aemail.style.backgroundColor = errorColor;

        document.getElementById(spanid).innerHTML = txt;

        aemail.focus();

        return false;

    }

}


function emailValidator4(elem,
                         helperMsg,
                         spanid,
                         spanid1) {

    var txt = "<span class='error_txt'>" + helperMsg + "</span>";

    //var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.(aero$|asia$|biz$|cat$|com$|coop$|edu$|gov$|info$|jobs$|mil$|mobi$|museum$|in$|name$|net$|org$|travel$|int$|co.in$)/;


    if (elem.value.match(emailExp)) {

        elem.style.backgroundColor = bgColor;

        document.getElementById(spanid).innerHTML = "";
        document.getElementById(spanid1).style.display = "none";


        return true;

    } else {

        elem.style.backgroundColor = errorColor;
        document.getElementById(spanid1).style.display = "";
        document.getElementById(spanid).innerHTML = txt;


        elem.focus();

        return false;

    }

}


//validation for number range

function numberrange(elem, min_value,
                     max_value,
                     helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    if (min_value != null) {

        if (elem.value < min_value)

            elem.style.backgroundColor = errorColor;

        document.getElementById("errorContent").innerHTML = txt;

        elem.focus();

        return false;

    }


    if (max_value != null) {

        if (elem.value > max_value)

            elem.style.backgroundColor = errorColor;

        document.getElementById("errorContent").innerHTML = txt;

        elem.focus();

        return false;

    }

    elem.style.backgroundColor = bgColor;

    document.getElementById("errorContent").innerHTML = "";

    elem.focus();

    return true;

}

//Number Validation

function checknumber(object_value) {

    if (object_value.length == 0)

        return true;


    var start_format = " .+-0123456789";

    var number_format = " .0123456789";

    var check_char;

    var decimal = false;

    var trailing_blank = false;

    var digits = false;


    check_char = start_format.indexOf(object_value.charAt(0));

    if (check_char == 1)

        decimal = true;

    else if (check_char < 1)

        return false;


    for (var i = 1; i < object_value.length;
         i++) {

        check_char = number_format.indexOf(object_value.charAt(i))

        if (check_char < 0) {

            return false;

        } else if (check_char == 1) {

            if (decimal)

                return false;

            else

                decimal = true;

        } else if (check_char == 0) {

            if (decimal || digits)

                trailing_blank = true;

        } else if (trailing_blank) {

            return false;

        } else {

            digits = true;

        }

    }


    return true;

}

//Check Integer

function checkinteger(object_value) {

    if (object_value.length == 0)

        return true;


    var decimal_format = ".";

    var check_char;


    check_char = object_value.indexOf(decimal_format);

    if (check_char < 1)

        return checknumber(object_value);

    else

        return false;

}

function isCharacter(elem, helperMsg,
                     spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    var Char;
    var isNumber = true;
    var sText = elem.value;

    for (i = 0; i < sText.length && isNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

            return false;

        }

    }

    return true;

}
function isValidatePassword(elem,
                            helperMsg,
                            spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


    var Char;
    var sText = elem.value;

    Char = sText.charAt(0);
    if (ValidChars.indexOf(Char) == -1)

    {

        document.getElementById(spanid).innerHTML = txt;

        elem.style.backgroundColor = errorColor;

        elem.focus();

        return false;

    }

    return true;
}

function isStartValue(elem, helperMsg,
                      spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    var sText = elem.value;
    //alert(sText);
    if (sText.charAt(0) == 0) {
        document.getElementById(spanid).innerHTML = txt;

        elem.style.backgroundColor = errorColor;

        elem.focus();

        return false;

    }

    return true;
}


function isNumber(elem, helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "0123456789";

    var IsNumber = true;

    var Char;

    var sText = elem.value;


    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            IsNumber = false;

            document.getElementById("errorContent").innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else if (sText.length != 10) {

            IsNumber = false;

            document.getElementById("errorContent").innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else {

            document.getElementById("errorContent").innerHTML = "";

            elem.style.backgroundColor = bgColor;

        }

    }

    return IsNumber;

}

//isNumber with 3 arguments


function isNumber3(elem, helperMsg,
                   spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "0123456789";

    var IsNumber = true;

    var Char;

    var sText = elem.value;


    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else if (sText.length != 10) {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else {

            document.getElementById(spanid).innerHTML = "";

            elem.style.backgroundColor = bgColor;

        }

    }

    return IsNumber;

}

function checkMobileNoByCountryId(elem, elem1, helperMsg,
                                  spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "0123456789";

    var IsNumber = true;

    var Char;

    var sText = elem.value;
    var countryId = elem1;

    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else if (sText.length == 10 && countryId == 2) {

            var IsNumber = true;

        } else if (sText.length == 10 && countryId != 2) {

            var IsNumber = true;

        } else {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        }

    }

    return IsNumber;

}


function isMobileNumber(elem,
                        helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "0123456789";

    var IsNumber = true;

    var Char;

    var sText = elem.value;


    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            IsNumber = false;

            document.getElementById("errorContent").innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else if (sText.length != 10) {

            IsNumber = false;

            document.getElementById("errorContent").innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else {

            document.getElementById("errorContent").innerHTML = "";

            elem.style.backgroundColor = bgColor;

        }

    }

    return IsNumber;

}


function matcher(elem1, elem2,
                 helperMsg) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var IsNumber = true;

    var Char;

    var sText1 = elem1.value;

    var sText2 = elem2.value;

    //	alert(sText1);

    //alert(sText2);


    if (sText1 != sText2)

    {

        IsNumber = false;

        document.getElementById("errorContent").innerHTML = txt;

        elem2.style.backgroundColor = errorColor;

        elem2.focus();

    }


    return IsNumber;

}

//

function matcher4(elem1, elem2,
                  helperMsg, spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var IsNumber = true;

    var Char;

    var sText1 = elem1.value;

    var sText2 = elem2.value;

    //	alert(sText1);

    //alert(sText2);


    if (sText1 != sText2)

    {

        IsNumber = false;

        document.getElementById(spanid).innerHTML = txt;

        elem2.style.backgroundColor = errorColor;

        elem2.focus();

    }


    return IsNumber;

}

function matcher5(elem1, elem2,
                  helperMsg, spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var IsNumber = true;

    var Char;

    var sText1 = elem1.value;

    var sText2 = elem2.value;

    //	alert(sText1);

    //alert(sText2);


    if (sText1 == sText2)

    {

        IsNumber = false;

        document.getElementById(spanid).innerHTML = txt;

        elem2.style.backgroundColor = errorColor;

        elem2.focus();

    }


    return IsNumber;

}


function matchsmspin(elem1, value,
                     helperMsg,
                     spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var IsNumber = true;

    var Char;

    var sText1 = elem1.value;

    var sText2 = trim(value.value);

    if (parseInt(sText1) != parseInt(sText2))

    {
        IsNumber = false;

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

    }

    return IsNumber;

}


function matcherwithval(elem1, value,
                        helperMsg,
                        spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var IsNumber = true;

    var Char;

    var sText1 = elem1.value;

    var sText2 = value;


    if (sText1 != sText2)

    {
        IsNumber = false;

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

    }


    return IsNumber;

}


//to check min lentgh ---

//function lengthCheck(elem1,length,helperMsg){

//	var txt ="<span class='error_txt'><B>"+helperMsg+"</b> <br/></span>";

//	var len=elem1.value;

//

//		  if (len.length < length) 			 {

//				document.getElementById("errorContent").innerHTML=txt;

//				elem1.style.backgroundColor=errorColor;

//				elem1.focus();

//				return false;

//			 }

//

//	   return true;

//}

//to check min lentgh ---

function lengthCheck(elem1, length,
                     helperMsg,
                     spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + "<br/></span>";

    var len = elem1.value;


    if (len.length < length) {

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

        return false;

    }


    return true;

}

function pinLengthCheck(elem1, length,
                        helperMsg,
                        spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + "<br/></span>";

    var len = elem1.value;


    if (len.length != length) {

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        elem1.focus();

        return false;

    }


    return true;

}


function convertToTitle(obj)

{

    var original = obj.value;
    var o_split = original.split(" ");
    //this probably isn't a complete list of words that shouldn't be capitalized
    var special_words = new Array('and', 'the', 'to', 'for', 'is', 'in', 'a', 'at', 'an', 'from', 'by', 'if', 'of');
    for (i = 0; i < o_split.length; i++) {
        if (i == 0) {
            //always capitalize the first word
            o_split[i] = (o_split[i].substring(0, 1)).toUpperCase() + o_split[i].substring(1);
        }
        else if (special_words.indexOf(o_split[i]) < 0) {
            o_split[i] = (o_split[i].substring(0, 1)).toUpperCase() + o_split[i].substring(1);
        }
    }
    retval = o_split.join(' ');
    return retval;
}


//date time function

//clock function define in top.jsp page
function clock_notuse() {
    //change in not(!) symbol (R.A.A)
    if (document.layers && document.all) return;

    var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");

    var ticktock = new Date();

    var month = ticktock.getMonth() + 1;

    var date = ticktock.getDate();

    var day = ticktock.getDay();

    var year = ticktock.getFullYear();

    var utime = ticktock.getTime();

    var hours = ticktock.getHours();

    var minutes = ticktock.getMinutes();

    var seconds = ticktock.getSeconds();


    var GMTmonth = ticktock.getUTCMonth() + 1;

    var GMTdate = ticktock.getUTCDate();

    var GMTday = ticktock.getUTCDay();

    var GMTyear = ticktock.getUTCFullYear();

    var GMThours = ticktock.getUTCHours();

    var GMTminutes = ticktock.getUTCMinutes();

    var GMTseconds = ticktock.getUTCSeconds();


    var milliseconds = (utime * 1000).toString().substring(10, 13);

    var apm = "AM";


    var Swatch = "@" + (((utime / 86400000) % 1) + (1 / 24)).toString().substring(2, 5);


    var decimaltime = ((hours / 24) + (minutes / 1440) + (seconds / 86400) + (milliseconds / 86400000));

    decimaltime = decimaltime.toString().substring(1, 7);

    var udect = ((utime / 86400000) % 1).toString().substring(1, 7);

    var totalseconds = (hours * 3600 + minutes * 60 + seconds + milliseconds / 1000);

    var gotime = utime / 864 + 50000;

    var umt1 = gotime.toString().substring(5, 7);

    var umt2 = gotime.toString().substring(7, 10);


    with (Math) {

        var hextime = floor(totalseconds / 1.318359375);

        var hex1 = floor(hextime / 4096);

        hextime -= 4096 * hex1;

        var hex2 = floor(hextime / 256);

        hextime -= 256 * hex2;

        var hex3 = floor(hextime / 16);

        hextime -= 16 * hex3;

        var hex4 = hextime;

    }


    var hexadecimalValue = hex[hex1] + "_" + hex[hex2] + hex[hex3] + "_" + hex[hex4];


    if (day == 0)

        day = "Sun";

    if (day == 1)

        day = "Mon";

    if (day == 2)

        day = "Tue";

    if (day == 3)

        day = "Wed";

    if (day == 4)

        day = "Thu";

    if (day == 5)

        day = "Fri";

    if (day == 6)

        day = "Sat";


    if (GMTday == 0)

        GMTday = "Sun";

    if (GMTday == 1)

        GMTday = "Mon";

    if (GMTday == 2)

        GMTday = "Tue";

    if (GMTday == 3)

        GMTday = "Wed";

    if (GMTday == 4)

        GMTday = "Thu";

    if (GMTday == 5)

        GMTday = "Fri";

    if (GMTday == 6)

        GMTday = "Sat";


    if (month <= 9) month = "0" + month;

    if (date <= 9) date = "0" + date;

    if (hours > 11) apm = "PM";

    if (hours > 12) hours = hours - 12;

    if (hours == 0) hours = 12;

    if (hours <= 9) hours = "0" + hours;

    if (minutes <= 9) minutes = "0" + minutes;

    if (seconds <= 9) seconds = "0" + seconds;


    if (GMTmonth <= 9) GMTmonth = "0" + GMTmonth;

    if (GMTdate <= 9) GMTdate = "0" + GMTdate;

    if (GMThours <= 9) GMThours = "0" + GMThours;

    if (GMTminutes <= 9) GMTminutes = "0" + GMTminutes;

    if (GMTseconds <= 9) GMTseconds = "0" + GMTseconds;


    var NETbase = utime / 86400000 * 360;

    var NETdegrees = Math.floor(NETbase % 360);

    var NETminutes = Math.floor((NETbase * 60) % 60);

    if (NETminutes <= 9) NETminutes = "0" + NETminutes;

    var NETstring = NETdegrees + "°" + NETminutes + "' NET";

    if (month == 1)

        month = "Jan";

    else if (month == 2)

        month = "Feb";

    else if (month == 3)

        month = "Mar";

    else if (month == 4)

        month = "Apr";

    else if (month == 5)

        month = "May";

    else if (month == 6)

        month = "Jun";

    else if (month == 7)

        month = "Jul";

    else if (month == 8)

        month = "Aug";

    else if (month == 9)

        month = "Sep";

    else if (month == 10)

        month = "Oct";

    else if (month == 11)

        month = "Nov";

    else if (month == 12)

        month = "Dec";

    var localValue = " " + month + " " + date + "," + year + " " + day + " " + hours + ":" + minutes + " " + apm;

    var GMTValue = "GMT/UTC Date/Time: " + GMTyear + "." + GMTmonth + "." + GMTdate + " " + GMTday + " " + GMThours + ":" + GMTminutes + ":" + GMTseconds + "." + milliseconds;

    var dtimeValue = "Local Decimal Time: " + decimaltime;

    var udtimeValue = "Decimal Time GMT: " + udect;
    // decimaltime.hynes.net

    var umtValue = "Universal Metric Time: " + umt1 + "." + umt2;
    // More at Zapatopi.net

    var hexValue = "Hexadecimal Time: " + hexadecimalValue;
    // More at intuitor.com/hex

    var unixValue = "Milliseconds since 1/1/1970 00:00 GMT: " + utime;

    var SwatchValue = "Swatch Internet Time: " + Swatch + " .beats";
    // More at Swatch.com

    var NETValue = "New Earth Time: " + NETstring;
    // More at Newearthtime.net



    //document.getElementByID("localface").innerHTML = localValue;

    document.getElementById('dateTime').innerHTML = localValue;

    /*document.clock.GMTface.value = GMTValue;

  document.clock.dtimeface.value = dtimeValue;

  document.clock.udtimeface.value = udtimeValue;

  document.clock.umtface.value = umtValue;

  document.clock.hexface.value = hexValue;

  document.clock.unixface.value = unixValue;

  document.clock.Swatchface.value = SwatchValue;

  document.clock.NETface.value = NETValue;*/



    //Countdown

    var cyear = 2008;
    //  enter 4-digit year

    var cmonth = 0;
    //  0 for January, 1 for February ... 11 for December

    var cdate = 1;
    //  day of the month

    var chours = 0;
    //  24-hour only

    var cminutes = 0;

    var cseconds = 0;

    var cms = 0;
    //  milliseconds


    var description = "New Year's 2008";

    var future = new Date(cyear, cmonth, cdate, chours, cminutes, cseconds, cms);

    var future2 = future.getTime();

    countdown = future - utime;

    countsec = Math.floor(countdown / 1000);

    countdays = Math.floor(countdown / 86400000 * 1000) / 1000;

    var csValue = "Seconds until " + description + ": " + countsec;
    var cdValue = "Days until " + description + ": " + countdays;

    //document.clock.csface.value = csValue

    // document.clock.cdface.value = cdValue


    setTimeout("clock()", 1);

}


//trim spaces before and after a word

function trimAll(sString)

{

    while (sString.substring(0, 1) == ' ')

    {

        sString = sString.substring(1, sString.length);

    }

    while (sString.substring(sString.length - 1, sString.length) == ' ')

    {

        sString = sString.substring(0, sString.length - 1);

    }

    return sString;

}


function test(val) {



    //alert(val);

    //alert("========================"+val);

    document.getElementById("errorContent").innerHTML = val;

}


//check mobile no not start with 0


function checkMobileStart(elem1,
                          helperMsg,
                          spanid) {


    var i = 0;

    var mobNo = elem1.value;

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    document.getElementById(spanid).innerHTML = "";


    if (mobNo != "") {


        var value = mobNo;

        regExp1 = /^[0-9]+$/;


        if (regExp1.test(value) && value.charAt(0) == '0') {


            document.getElementById(spanid).innerHTML = txt;

            elem1.focus();

            return false;

        }

    }


    return true;

}

function checkInitialValueFWLL(elem1,
                           helperMsg,
                           spanid,CheckValue) {
    var debug = false;
    if (debug) {
        alert("Start checkInitialValue ! " + elem1.value);
    }
    var result = false;
    var i = 0;
    var mobNo = elem1.value;
    var initialMobNo = mobNo.substring(0, 1);
    var ismatch = false;

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    document.getElementById(spanid).innerHTML = "";
    elem1.style.backgroundColor = bgColor;

    var special_words = new Array(CheckValue);


    for (i = 0; i < special_words.length;
         i++) {
        if (initialMobNo == special_words[i]) {
            ismatch = true;
        }

    }
    if (debug) {
        alert("isMatch ! " + ismatch);
    }

 if (ismatch) {
        document.getElementById(spanid).innerHTML = "";
        result = true;
    } else {
document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        result = false;
    }

    if (debug) {
        alert("result ! " + result);
    }

    return result;
}


function checkInitialValue(elem1,
                           helperMsg,
                           spanid) {
    var debug = false;
    if (debug) {
        alert("Start checkInitialValue ! " + elem1.value);
    }
    var result = false;
    var i = 0;
    var mobNo = elem1.value;
    var initialMobNo = mobNo.substring(0, 2);
    var ismatch = false;

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    document.getElementById(spanid).innerHTML = "";
    elem1.style.backgroundColor = bgColor;

    var special_words = new Array('70','71','72','73','74','75','76','77','78','79','80','81','82','83','84','85','86','87','88','89','90', '91', '92', '93', '94','95', '96', '97', '98', '99');
    for (i = 0; i < special_words.length;
         i++) {
        if (initialMobNo == special_words[i]) {
            ismatch = true;
        }


    }
    if (debug) {
        alert("isMatch ! " + ismatch);
    }

    if (ismatch) {
        //eleml.style.backgroundColor=bgColor;
        document.getElementById(spanid).innerHTML = "";
        result = true;
    } else {
        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;

        result = false;
    }

    if (debug) {
        alert("result ! " + result);
    }

    return result;
}

function checkFun()
{
	alert('hello');
}
function checkInitialValueDTH(operator,elem1,
                           helperMsg,
                           spanid) {
    var debug = false;
    
    if (debug) {
        alert("Start checkInitialValue ! " + elem1.value);
    }
    var result = false;
    var i = 0;
    var mobNo = elem1.value;
    var initialMobNo = ""
    var special_words = ""

	if(operator == "dish")
	{
		initialMobNo=mobNo.substring(0, 4);
		special_words=new Array('0139','0150','0151');

    	}
	else if(operator == "tatasky")
	{
		initialMobNo=mobNo.substring(0,2);
		special_words=new Array('10');
		

	}
	var ismatch = false;

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    document.getElementById(spanid).innerHTML = "";
    elem1.style.backgroundColor = bgColor;

    for (i = 0; i < special_words.length;
         i++) {
        if (initialMobNo == special_words[i]) {
            ismatch = true;
        }


    }
    if (debug) {
        alert("isMatch ! " + ismatch);
    }

    if (ismatch) {
        //eleml.style.backgroundColor=bgColor;
        document.getElementById(spanid).innerHTML = "";
        result = true;
    } else {
        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;
    result = false;
    }

    if (debug) {
        alert("result ! " + result);
    }

    return result;
}



function isValidDate(elem1, elem2,
                     elem3, helperMsg,
                     helperMsg1, spanid)
{

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    var txt1 = "<span class='error_txt'>" + helperMsg1 + " <br/></span>";
    day = parseInt(elem1.value);
    month = parseInt(elem2.value);
    year = parseInt(elem3.value);

    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {

        document.getElementById(spanid).innerHTML = txt;

        elem1.style.backgroundColor = errorColor;
        elem2.style.backgroundColor = errorColor;
        elem3.style.backgroundColor = errorColor;

        elem1.focus();
        elem2.focus();
        elem2.focus();
        document.getElementById(spanid).innerHTML = txt;
        return false;

    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) {

            document.getElementById(spanid).innerHTML = txt1;

            elem1.style.backgroundColor = errorColor;
            elem2.style.backgroundColor = errorColor;
            elem3.style.backgroundColor = errorColor;

            elem1.focus();
            elem2.focus();
            elem2.focus();
            return false;

        }
    }

    return true;
}


///////////////// onlyNumbers ////

function onlyNumbers(evt) {
    var e = evt;

    //for trans-browser compatibility
    var charCode = e.which || e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    {
        //alert("Put only numeric values");
        return false;
    }
    return true;
}
//////////////////


/*Code for write excel file*/


function CreateExcelSheet()
{

    // the DOM enables the table parameters to be used from the id
    var x = myRecords.rows

    var xls = new ActiveXObject("Excel.Application")
    //  To make it display in its own window
    xls.visible = true

    xls.Workbooks.Add

    for (i = 0; i < x.length; i++)
    {
        var y = x[i].cells

        for (j = 0; j < y.length; j++)
        {
            xls.Cells(i + 1, j + 1).Value = y[j].innerText
        }
    }

    //   xls.ActiveWorkbook.Save        ()
    //   xls.ActiveWorkbook.Close       ()

}


//to check difference between date --18

function diffrenceDate(elem1, elem2,
                       elem3, helperMsg,
                       spanid) {

    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";
    var date = new Date();

    var dd = "",mm = "",yy = "";

    dd = date.getDate();
    mm = date.getMonth() + 1;
    yy = date.getFullYear();

    ddd = elem1.value;
    dmm = elem2.value;
    dyy = elem3.value;

    if (dd >= ddd) {
        dd = dd - ddd;
    } else {
        dd = ((dd + 30) - ddd);
        mm = mm - 1;

    }

    if (mm >= dmm) {
        mm = mm - dmm;
    } else {
        mm = ((mm + 12) - dmm);
        yy = yy - 1;
    }

    if (yy >= dyy) {
        yy = yy - dyy;
    } else {
        yy = yy - dyy;
    }
    // alert("dd= "+dd);
    // alert("mm= "+mm);
    // alert("yy= "+yy);

    if (yy < 18) {
        document.getElementById(spanid).innerHTML = txt;
        elem1.style.backgroundColor = errorColor;
        elem2.style.backgroundColor = errorColor;
        elem3.style.backgroundColor = errorColor;
        elem1.focus();
        elem2.focus();
        elem2.focus();
        return false;
    }
    else {
        return true;
    }


}


function addressValidate(obj, helperMsg, spanid) {
    obj.value = trim(obj.value);
    sText = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var ValidChars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-@/. ";

    var IsNumber = true;

    var Char;

    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Chars = sText.charAt(i);

        if (ValidChars.indexOf(Chars) == -1)

        {


            IsNumber = false;

        }

    }

    if (!IsNumber) {

        obj.style.backgroundColor = errorColor;
        document.getElementById(spanid).innerHTML = txt;

    }

    else {
        obj.style.backgroundColor = bgColor;
        document.getElementById(spanid).innerHTML = "";
    }
    return IsNumber;

}

function checkNoL(elem, helperMsg, spanid, noLength) {
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";

    var ValidChars = "0123456789";

    var IsNumber = true;

    var Char;

    var sText = elem.value;


    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Char = sText.charAt(i);

        if (ValidChars.indexOf(Char) == -1)

        {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else if (sText.length != noLength) {

            IsNumber = false;

            document.getElementById(spanid).innerHTML = txt;

            elem.style.backgroundColor = errorColor;

            elem.focus();

        } else {

            document.getElementById(spanid).innerHTML = "";

            elem.style.backgroundColor = bgColor;

        }

    }

    return IsNumber;

}

function checkCumulative(amt,amtlimit,
                   helperMsg, spanid) {
    var txt = "<span class='error_txt1' ><b>" + helperMsg + "</b> <br/></span>";
    if (parseInt(amt) > parseInt(amtlimit) ) {    
        document.getElementById(spanid).innerHTML = txt;
	window.scroll(0,600);
        return false;
    } else {
         document.getElementById(spanid).innerHTML = "";
        return true;
    }
}

function checkCumulativeRechargeSuccess(successRechcount,limit,
                   helperMsg, spanid) {
    var txt = "<span class='error_txt1' ><b>" + helperMsg + "</b> <br/></span>";
    //alert(successRechcount+"|"+limit);
    if (parseInt(successRechcount) > parseInt(limit)) {
        document.getElementById(spanid).innerHTML = txt;
        window.scroll(0,600);
	return false;
	
    } else {
         document.getElementById(spanid).innerHTML = "";
        return true;
    }
}
//Added on Mar 3rd 2009

function specialCharCheck(obj, obj_type, helperMsg, spanid) {

    //alert("obj============>"+obj+"\nobj_type============>"+obj_type+"\n"+"helperMsg==========>"+helperMsg);

    obj.value = trim(obj.value);

        var specialChar='<>(){}[]?&*~`!$%^=+|:\'"\;';
        //var repChar=',#\\';
        var txt = "<span class='error_txt'>" + helperMsg +' '+specialChar+ " <br/></span>";
        var status=true;

        for(i=0;i<obj.value.length;i++){
                if(specialChar.indexOf(obj.value.charAt(i))>=0){
                        status=false;
                        break;
                }
                if(obj.value.charAt(i)==','){
                        obj.value=obj.value.replace(',','.');
                }else if(obj.value.charAt(i)=='#') {
                        obj.value=obj.value.replace('#',' ');
                }else if(obj.value.charAt(i)=='\\'){
                        obj.value=obj.value.replace('\\',' ');
                }
        }

    if (!status) {
                obj.style.backgroundColor = errorColor;
        document.getElementById(spanid).innerHTML = txt;
    }

    return(status);

}
// Added on Mar 5th 2009
function addressValidate3(obj, helperMsg, spanid) {
    obj.value = trim(obj.value);
    sText = trim(obj.value);
    var txt = "<span class='error_txt'>" + helperMsg + " <br/></span>";


    var ValidChars = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-@/. ,#\\";

    var IsNumber = true;

    var Char;

    for (i = 0; i < sText.length && IsNumber;
         i++)

    {

        Chars = sText.charAt(i);

        if (ValidChars.indexOf(Chars) == -1)

        {


            IsNumber = false;

        }

    }

    if (!IsNumber) {

        obj.style.backgroundColor = errorColor;
        document.getElementById(spanid).innerHTML = txt;

    }

    else {
        obj.style.backgroundColor = bgColor;
        document.getElementById(spanid).innerHTML = "";
    }
    return IsNumber;

}
