/* global variables */
var _CountryName = "''";
var _CityName = "";
var _Validator = null;
var _ThankYouPage = "thank-you.aspx";
var _ActionPage = "";
var _FormName = "";
var _RedirectPage = "";
var _RegEx_Email = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/;
var g_noclick = function() { return false; };

/* standard functions starts here */

function getQueryParam(p) {
    hu = window.location.search.substring(1);
    gy = hu.split('&amp;');
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split('=');
        if (ft[0] == p) {
            return ft[1];
        }
    }
}
function scriptEmailClear(e) {
    var myTextField = e.value;
    if (myTextField == "Enter Official ID") {
        e.value = "";
    }
}
function scriptEmailBlur(e) {
    var myTextField = e.value;
    if (myTextField == "") {
        e.value = "Enter Official ID";
    }
}

function openWindow(anchor, options) {
    var args = '';
    if (options == null) {
        var win = window.open(anchor);
        return false;
    }

    if (typeof (options) == 'undefined') { var options = new Object(); }
    if (typeof (options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random() * 100000); }

    if (typeof (options.height) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
        args += "height=" + options.height + ",";
    }

    if (typeof (options.width) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
        args += "width=" + options.width + ",";
    }

    if (typeof (options.fullscreen) != 'undefined') {
        args += "width=" + (screen.availWidth - 20) + ",";
        args += "height=" + (screen.availHeight - 40) + ",";
    }

    if (typeof (options.center) == 'undefined') {
        options.x = 0;
        options.y = 0;
        args += "screenx=" + options.x + ",";
        args += "screeny=" + options.y + ",";
        args += "left=" + options.x + ",";
        args += "top=" + options.y + ",";
    }

    if (typeof (options.center) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
        options.y = Math.floor((screen.availHeight - (options.height || screen.height)) / 2) - (screen.height - screen.availHeight);
        options.x = Math.floor((screen.availWidth - (options.width || screen.width)) / 2) - (screen.width - screen.availWidth);
        args += "screenx=" + options.x + ",";
        args += "screeny=" + options.y + ",";
        args += "left=" + options.x + ",";
        args += "top=" + options.y + ",";
    }

    if (typeof (options.scrollbars) != 'undefined') { args += "scrollbars=1,"; }
    if (typeof (options.menubar) != 'undefined') { args += "menubar=1,"; }
    if (typeof (options.locationbar) != 'undefined') { args += "location=1,"; }
    if (typeof (options.resizable) != 'undefined') { args += "resizable=1,"; }

    var win = window.open(anchor, options.name, args);
    return false;

}

function showAtBottomRight(windowId, afterSeconds) {
    setTimeout(function() {
        document.getElementById(windowId).style.display = 'block';
        var winH = $(window).height();
        var winW = $(window).width();
        var winT = winH - document.getElementById(windowId).offsetHeight;
        var winL = winW - document.getElementById(windowId).offsetWidth;
        document.getElementById(windowId).style.top = winT + 'px';
        document.getElementById(windowId).style.left = winL + 'px';
        //$(windowId).css({ 'top': winT + 'px', 'left': winL + 'px' });
    }, 1000 * afterSeconds);
}

/* standard functions end here */


/* forms v1 starts here */

function assignCountryCode() {
    var cmb = document.getElementById('ccountry');
    var valu = cmb[cmb.selectedIndex].value;
    var cityRow = document.getElementById("cityRow");
    if (valu.indexOf("#") != -1) {
        var icode = valu.split("#")
        var ctelephonecode = document.getElementById('ctelephonecode');
        ctelephonecode.value = icode[1];
    }
    cityRow.style.display = 'none';
    if (ctelephonecode.value == '+91') cityRow.style.display = '';
}

function assignCountryCode(cmb, cityRowName, telephoneCodeLblName) {
    var valu = cmb[cmb.selectedIndex].value;
    var cityRow = document.getElementById(cityRowName);
    var ctelephonecode = document.getElementById(telephoneCodeLblName);
    if (valu.indexOf("#") != -1) {
        var icode = valu.split("#")
        ctelephonecode.value = icode[1];
    } else {
        ctelephonecode.value = '';
    }
    cityRow.style.display = 'none';
    if (document.getElementById(cityRowName + '2') != null) document.getElementById(cityRowName + '2').style.display = 'none';
    if (ctelephonecode.value == '+91') {
        cityRow.style.display = '';
        if (document.getElementById(cityRowName + '2') != null) document.getElementById(cityRowName + '2').style.display = '';
    }
}

function saveEmail() {
    if ($("#entryForm").validate().element("#cemail")) {
        var email = 'val=' + Math.random() + '&email=' + document.getElementById('cemail').value;
        if (jQuery.trim(email).length > 0) {
            email = encodeURI(email);
            var xml_http;
            if (window.XMLHttpRequest) { /* code for IE7+, Firefox, Chrome, Opera, Safari */xml_http = new XMLHttpRequest(); } else { /* code for IE6, IE5 */xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
            xml_http.onreadystatechange = function () {
                if (xml_http.readyState == 4 && xml_http.status == 200) {
                }
            }
            xml_http.open("POST", "/common/saveemail.aspx?", true);
            xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xml_http.send(email);
        }
    }
}
function saveFormData() {
    var valid = _Validator.valid();
    _Validator.showErrors();
    if (!valid) {
        alert('Please correct/fill the fields.');
        return;
    }
    var formData = '';
    var ccountry = document.getElementById('ccountry');
    var wtodlbpm = (document.getElementById('cwtodlbpmChk') == null || document.getElementById('cwtodlbpmChk') == 'undefined') ? 0 : (document.getElementById('cwtodlbpmChk').checked ? 1 : 0);
    var city = (document.getElementById('ccountry').value == 'India' ? document.getElementById('ccity').value : '');
    formData += 'val=' + Math.random() + '&save=1&form=' + _FormName
                    + '&name=' + document.getElementById('cname').value
                    + '&email=' + document.getElementById('cemail').value
                    + '&country=' + ccountry[ccountry.selectedIndex].text
                    + '&countryval=' + ccountry[ccountry.selectedIndex].value
                    + '&city=' + city
                    + '&tpcode=' + document.getElementById('ctelephonecode').value
                    + '&pn=' + document.getElementById('ctelephone').value
                    + '&requirement=' + document.getElementById('crequirement').value
                    + '&wtodlbpm=' + wtodlbpm
                    + '&sku=0' //+ (document.getElementById('cupdateChk').checked ? 1 : 0)
                    + '&sknl=0' //+ (document.getElementById('cnewsLetterChk').checked ? 1 : 0);
    formData = encodeURI(formData);
    var xmlhttp;
    if (window.XMLHttpRequest) { /* code for IE7+, Firefox, Chrome, Opera, Safari */xmlhttp = new XMLHttpRequest(); } else { /* code for IE6, IE5 */xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("formDataRoot").style.display = 'none';
            document.getElementById("formDataThankYourMsg").style.display = 'block';
            document.getElementById("thankyouFormFrame").src = _ThankYouPage + "?" + formData;
            if (_RedirectPage.length > 0) setTimeout(function () { window.location = _RedirectPage; }, 2000);
        }
    }
    xmlhttp.open("POST", "saveform.aspx?", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(formData);
    if (_ActionPage != "") document.getElementById("actionFormFrame").src = _ActionPage + "?" + formData;
    
}
function initForm() {
    _Validator = $("#entryForm").validate({
        submitHandler: function () {
            saveFormData();
        },
        messages: {
            required: 'Please fill the field',
            email: 'Invalid email address.'
        }
    });
    $('#entryForm').submit(function (event) {
        event.preventDefault(); // our env actually monkey patches preventDefault
        // impl your own prevent default here
        // basically the idea is to bind a prevent default
        // stopper on the form's submit event
    });
    $("#formSubmitBtn").click(function (evt) {
        // Validate the form and retain the result.
        var isValid = $("#entryForm").valid();

        // If the form didn't validate, prevent the
        //  form submission.
        if (!isValid)
            evt.preventDefault();
    })
    if (_CountryName != "''") {
        $("#ccountry").find(":contains(" + _CountryName + ")").attr("selected", "selected");
        assignCountryCode();
    }
    document.getElementById('ccity').value = _CityName;
}

/* forms v1 ends here */

/* validator code starts here */

function clone(intance) {
    if (typeof (intance) != 'object' || intance == null) return intance;
    var obj = intance.constructor();
    for (p in intance) {
        obj[p] = clone(intance[p]);
    }
    return obj;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
};
Validator.prototype.items;
Validator.prototype.stack;
Validator.prototype.groupName = '';
Validator.prototype.classNames = {
    inputDefault: 'inputDefault',
    inputOnFocus: 'inputOnFocus',
    inputOnError: 'inputOnError'
};
Validator.prototype.add = function(itemObject) {
    itemObject.id = this.groupName + itemObject.id;
    itemObject.parent = this;
    var elemt = document.getElementById(itemObject.id);
    this.items[itemObject.id] = itemObject;
    var vgroup = itemObject.parent;
    var saveemailfld = 0;
    var e = elemt.tagName == 'SELECT' ? elemt.parentNode : elemt;
    e.className = vgroup.classNames.inputDefault;

    if (itemObject.requiredif_2 != null) itemObject.requiredif_2 = this.groupName + itemObject.requiredif_2;
    if (itemObject.eitherone_2 != null) itemObject.eitherone_2 = this.groupName + itemObject.eitherone_2;

    var checks = itemObject.checks.split(',');
    for (i = 0; i < checks.length; i++) {
        var check = checks[i].toLowerCase().trim();
        if (check == 'requiredif') {
            if (itemObject.requiredif_2 != null) {
                var second = itemObject.parent.items[itemObject.requiredif_2];
                second.requiredif_by = itemObject.id;
            }
        } else if (check == 'email') {
            saveemailfld = 1;
        }
    }

    var e_onfocus = function(e) {
        //vgroup.validateItem(itemObject);
        var e = elemt.tagName == 'SELECT' ? elemt.parentNode : elemt;
        e.className = vgroup.classNames.inputOnFocus;
        vgroup.showWaterMark(itemObject, true);
    };
    var e_onblur = function(e) {
        var e = elemt.tagName == 'SELECT' ? elemt.parentNode : elemt;
        //e.className = vgroup.validateItem(itemObject) ? vgroup.classNames.inputDefault : vgroup.classNames.inputOnError;
        e.className = vgroup.classNames.inputDefault;
        vgroup.showWaterMark(itemObject, false);
    };
    var e_onkeyup = function(e) {
        // var e = elemt.tagName == 'SELECT' ? elemt.parentNode : elemt;
        // e.className = vgroup.validateItem(itemObject) ? vgroup.classNames.inputOnFocus : vgroup.classNames.inputOnError;
    };
    var e_onchange = function(e) { // to save email
        var e = elemt.tagName == 'SELECT' ? elemt.parentNode : elemt;
        if (vgroup.validateItem(itemObject, 1)) {
            var email = 'val=' + Math.random() + '&email=' + elemt.value;
            if (email.trim().length > 0) {
                email = encodeURI(email);
                var xml_http;
                if (window.XMLHttpRequest) { /* code for IE7+, Firefox, Chrome, Opera, Safari */xml_http = new XMLHttpRequest(); } else { /* code for IE6, IE5 */xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
                xml_http.onreadystatechange = function() {
                    if (xml_http.readyState == 4 && xml_http.status == 200) {
                    }
                }
                xml_http.open("POST", "/common/saveemail.aspx?", true);
                xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xml_http.send(email);
            }
        }
    }

    if (elemt.attachEvent != null) {
        elemt.attachEvent('onfocus', e_onfocus);
        elemt.attachEvent('onblur', e_onblur);
        elemt.attachEvent('onkeyup', e_onkeyup);
        if (saveemailfld) elemt.attachEvent('onchange', e_onchange);
    } else {
        elemt.addEventListener('focus', e_onfocus, false);
        elemt.addEventListener('blur', e_onblur, false);
        elemt.addEventListener('keyup', e_onkeyup, false);
        if (saveemailfld) elemt.addEventListener('change', e_onchange, false);
    }
    this.showWaterMark(itemObject, false);
};
Validator.prototype.showWaterMark = function(itemObject, isOnFocus) {
    if (itemObject.watermark != null) {
        var elemt = document.getElementById(itemObject.id);
        var val = itemObject.parent.getValue(itemObject);
        if (val.length <= 0) elemt.value = itemObject.watermark;
        if (isOnFocus) {
            elemt.style.color = '';
            if (val.length <= 0) elemt.value = '';
        } else {
            if (val == '') {
                elemt.value = itemObject.watermark;
                elemt.style.color = 'gray';
            } else {
                elemt.style.color = '';
            }
        }
    }
}
Validator.prototype.getValue = function(itemObject) {
    var elemt = document.getElementById(itemObject.id);
    var value = elemt.value;
    if (itemObject.watermark != null) {
        if (value.trim().toLowerCase() == itemObject.watermark.toLowerCase()) return '';
    }
    return value;
}
Validator.prototype.messages = {
    required: 'Please specify {0}.',
    email: 'Please enter valid {0}.',
    minimumlength: 'Please fill {0}, at least {1} character(s) expected.',
    minimum: 'Please enter a value not less than {1}.',
    maximum: 'Please enter a value not greater than {1}.',
    number: 'Please enter valid numeric value.',
    digits: 'Please enter only digits.',
    eitherone: 'Please specify either {0} or {1}.',
    requiredif: 'Please specify {0}.',
    telephone: 'Please specify valid {0}.',
    telephonecode: 'Please specify valid {0}.'
};
Validator.prototype.validators = {
    required: function(item, value) {
        return (value + '').trim().length >= 1 ? true : false;
    },
    email: function(item, value) {
        var regEx = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/;
        return regEx.test(value);
    },
    minimumlength: function(item, value) {
        return (value + '').length >= item.minimumlength ? true : false;
    },
    minimum: function(item, value) {
        return value >= item.minimum ? true : false;
    },
    maximum: function(item, value) {
        return value <= item.maximum ? true : false;
    },
    number: function(item, value) {
        var regEx = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/;
        return regEx.test(value);
    },
    digits: function(item, value) {
        var regEx = /^\d+$/;
        return regEx.test(value);
    },
    eitherone: function(item, value) {
        if (item.eitherone_2 != null) {
            var second = item.parent.items[item.eitherone_2];
            var val2 = item.parent.getValue(second);
            if ((value + '').trim().length >= 1) {
                document.getElementById(second.errorTarget != null ? second.errorTarget : second.id + '_Err').innerHTML = '';
                return true;
            } else if ((val2 + '').trim().length >= 1) {
                item.parent.validateItem(second);
                return true;
            }
        }
        if ((value + '').trim().length >= 1) return true;
        return false;
    },
    requiredif: function(item, value) {
        if (item.requiredif_2 != null) {
            var second = item.parent.items[item.requiredif_2];
            var val2 = item.parent.getValue(second);
            if ((val2 + '').trim().length >= 1) return (value + '').trim().length >= 1 ? true : false;
        } else if (item.requiredif_method != null) {
            if (item.requiredif_method(item, value)) return (value + '').trim().length >= 1 ? true : false;
        }
        return true;
    },
    telephone: function(item, value) {
        var regEx = /^[0-9]([0-9]\-?){4,10}[0-9]$/;
        return regEx.test(value);
    },
    telephonecode: function(item, value) {
        var regEx = /^\+?[0-9]{1,4}$/;
        return regEx.test(value);
    }
};
Validator.prototype.messageFormatters = {
    minimumlength: function(item, value, msg) {
        return msg.replace(/\{1\}/, item.minimumlength);
    },
    eitherone: function(item, value, msg) {
        return msg = msg.replace(/\{1\}/, item.parent.items[item.eitherone_2].title);
    }
};
Validator.prototype.validateItem = function(itm, ignoreMsg) {
    if (this.stack[itm.id] != null) return null;
    this.stack[itm.id] = true;
    var ok = true;
    var elment = document.getElementById(itm.id);
    var checks = itm.checks.split(',');
    var msg = '';
    var val = itm.parent.getValue(itm);
    for (i = 0; i < checks.length; i++) {
        var check = checks[i].toLowerCase().trim();
        if (check.length > 0) {
            if (!this.validators[check](itm, val)) {
                ok = false;
                if (msg.length > 0) msg += '<br/>';
                var m = this.messages[check];
                if (itm.messages != null && itm.messages[check] != null) m = itm.messages[check];
                if (this.messageFormatters[check]) m = this.messageFormatters[check](itm, val, m);
                if (m != null) msg += m;
                if (itm.onlysingle == null || itm.onlysingle) break;
            }
            if (check == 'requiredif' && (val + '').trim().length == 0) break; // required if? no need to check other validations if empty.. stop here
        }
    }
    msg = msg.replace(/\{0\}/, (itm.title != null ? itm.title : ''));
    if (ignoreMsg == null || ignoreMsg == 0) document.getElementById(itm.errorTarget != null ? itm.errorTarget : elment.id + '_Err').innerHTML = msg;

    if ((val + '').trim().length <= 0) {
        if (itm.requiredif_by != null) {
            var first = itm.parent.items[itm.requiredif_by];
            //document.getElementById(first.errorTarget != null ? itm.errorTarget : first.id + '_Err').innerHTML = '';
            itm.parent.validateItem(first, ignoreMsg);
        }
    }
    if (!ok) elment.className = itm.parent.classNames.inputOnError; else elment.className = itm.parent.classNames.inputDefault;
    this.stack[itm.id] = null;
    return ok;
}
Validator.prototype.validate = function(itms) {
    var ok = true;
    if (itms == null) itms = this.items;
    for (itm in itms) {
        ok = this.validateItem(this.items[itm]) && ok;
    }
    return ok;
}
function Validator(name) {
    name = name != null ? name : '';
    this.groupName = name;
    this.items = new Object;
    this.stack = new Object;
    this.classNames = clone(this.classNames);
    for (e in this.classNames) this.classNames[e] = name + this.classNames[e];
}

/* validator code ends here */

/* modal window code starts here */

$(document).ready(function() {

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();


        //Get the A tag
        var id = $(this).attr('href');

        $('#mask')[0].childWindowId = id;

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        //Set the popup window to center
        //$('#boxesContainer').css({ 'width': maskWidth, 'height': maskHeight, 'display': 'block' });
        $(id).css({ 'display': 'block', 'z-index': 99999 });
        //alert(winH / 2 - $(id)[0].offsetHeight / 2);

        $(id).css({ 'top': Math.floor((winH - $(id)[0].offsetHeight) / 2) + 'px', 'left': winW / 2 - $(id)[0].offsetWidth / 2 });
        //$(id).click(g_noclick);
        //transition effect
        $(id).fadeIn(500);

        if ($(id).attr('modalInit') != null && $(id).attr('modalInit') != 'undefined') window[$(id).attr('modalInit')]();

    });

    //if close button is clicked
    $('.window .close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $($('#mask')[0].childWindowId).hide();
        //$('#boxesContainer').hide();
        //$('#boxesContainer').children().css({ 'display': 'none' });
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function() {
        $('#mask').hide();
        $($('#mask')[0].childWindowId).hide();
        //$('#boxesContainer').hide();
        //$('#boxesContainer').children().css({ 'display': 'none' });
        $('.window').hide();
    });

    //if container is clicked
    $('#boxesContainer').click(function() {
        $('#mask').hide();
        $($('#mask')[0].childWindowId).hide();
        //$('#boxesContainer').hide();
        //$('#boxesContainer').children().css({ 'display': 'none' });
        $('.window').hide();
    });

    $('.CloseWindow').click(function() {
        $('#mask').hide();
        $($('#mask')[0].childWindowId).hide();
        //$('#boxesContainer').hide();
        //$('#boxesContainer').children().css({ 'display': 'none' });
        $('.window').hide();
    });

});


function showModalwindow(linkobj) {
    
        //Get the A tag
        var id = $(linkobj).attr('href');

        $('#mask')[0].childWindowId = id;

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        $('#mask').fadeIn(500);
        $('#mask').fadeTo("fast", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        //Set the popup window to center
        //$('#boxesContainer').css({ 'width': maskWidth, 'height': maskHeight, 'display': 'block' });
        $(id).css({ 'display': 'block', 'z-index': 99999 });
        //alert(winH / 2 - $(id)[0].offsetHeight / 2);

        $(id).css({ 'top': Math.floor((winH - $(id)[0].offsetHeight) / 2) + 'px', 'left': winW / 2 - $(id)[0].offsetWidth / 2 });
        //$(id).click(g_noclick);
        //transition effect
        $(id).fadeIn(500);

        if ($(id).attr('modalInit') != null && $(id).attr('modalInit') != 'undefined') window[$(id).attr('modalInit')]();
}

/* model window code ends here */
