$j = jQuery.noConflict();
//var border = RUZEE.ShadedBorder.create({ corner:8, shadow:16,  border:2 });

//$j(window).load(function() {
//        $j('#my-border').liquidCanvas('[shadow{width:2; color:#f2f2f2; shift:2} border{color:#cccccc; width:1} fill{color:#ffffff}]  => roundedRect{radius:8}');
//        $j('#my-border2').liquidCanvas('[shadow{width:2; color:#f2f2f2; shift:2} border{color:#cccccc; width:1} image{url:"assets/images/product/mirage_liberty/row/banner.jpg"}] => roundedRect{radius:20}');
//});

Shadowbox.init({
	skipSetup:true,
	language:'en',
	players:['wmp','swf','img','flv','iframe','html'],
	useSizzle:false,
	adapter:'jquery'
});

$j(document).ready(function() {
    //akademie sub nav
    $j(".akademie .menuLevel2 li ul").css("display", "none");
    $j.each($j(".akademie .menuLevel2 li ul"),function() {
       if($j(".li_act", this).length) {
           $j(this).css("display","inline");
       } 
    });
    $j(".akademie .menuLevel2 li ul").prev().attr("href", "javascript:void(0)");
    $j(".akademie .menuLevel2 li a").click(function() {
       jQuery(this).next().toggle();
    });

    $j('#homepagenews .homepagenewsitem:last').addClass("last");
    var pathname = window.location.pathname;

    jQuery("#fontsize").attr("href", pathname + "#");

   // $j("ul.topmenu li a").attr("href", "/");
    $j("a").each(function() {
         if($j("img", this).length == 0)
        $j.fn.filesize($j(this), $j(this).attr("href"));
    });
    
 
});



jQuery.fn.filesize = function(item, path)  {
    var pattern = /\.pdf$/;
    if (pattern.test(path)) {
        jQuery.ajax({
            url: "index.php",
            type: "POST",
            async: true,
            data: {
                eID: "filesize_eID",
                path: path
            },
            //dataType: "html",
            success: function(response){
                if (response) {
                    item.append(" (" + response + ")");
                }
            },
            error: function(x, e){
                var err_text = "";
                if (x.status == 0) {
                    err_text = 'Server Connection Error.';
                }
                else
                if (x.status == 404) {
                    err_text = 'Requested URL not found.';
                }
                else
                if (x.status == 500) {
                    err_text = 'Internal Server Error.';
                }
                else
                if (e == 'parsererror') {
                    err_text = 'Error:\nParsing JSON Request failed.';
                }
                else
                if (e == 'timeout') {
                    err_text = 'Request Time out.';
                }
                else {
                    err_text = 'Unknow Error:\n' + x.responseText;
                }

            }
        });
    }
}

$j(function() {

    $j('ul.tabs').tabs("div.panes > div");

    //	$j("ul.tabs").tabs("div.panes > div");
    //	$j('#tabs').tabs();
    //       $j('#my-border').liquidCanvas('[shadow border gradient] => roundedRect{radius:4}');

    //var myBorder = RUZEE.ShadedBorder.create({ corner:4, shadow:9, border:1 });
    //    myBorder.render('my-border');

    //myBorder.render($j('#my-border'));

    	//$j.fn.media.defaults.flvPlayer = '/fileadmin/template/js/player.swf';

    	//$j.fn.media.defaults.flashvars = {streamer: 'rtmp://resmedfvs.cdnetworks.net/resmedfvs'};
    //	$j('.media').media();

    //	if (g_strLocaleCode=='us') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">sleep better ... for a better life</div>');
    //	} else if (g_strLocaleCode=='fr') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">mieux dormir ... pour mieux vivre</div><div class="homepagefeaturemessage" id="message2">Solutions ResMed en ventilation ... Améliorer la qualité des soins</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='se') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Sov bättre ... för ett bättre liv</div><div class="homepagefeaturemessage" id="message2">ResMed&acute;s ventilationslösningar ... Ger hög behandlingskvalitet</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='fi') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Nuku paremmin ... jotta voisit paremmin</div><div class="homepagefeaturemessage" id="message2">ResMed - ventilaatioratkaisut ... mahdollistavat laadukkaan hoidon</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='jp') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">sleep better ... for a better life</div><div class="homepagefeaturemessage" id="message2">ResMed Ventilation Solutions ... Making quality of care easy</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='ch') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Besserer Schlaf ... für ein besseres Leben</div><div class="homepagefeaturemessage" id="message2">ResMed Beatmungslösungen ... Qualitative Versorgung leicht gemacht</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='cn') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">sleep better ... for a better life</div><div class="homepagefeaturemessage" id="message2"></div>');
    //		rotateFeatureMessage();

    //$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Besserer Schlaf ... für ein besseres Leben</div><div class="homepagefeaturemessage" id="message2">ResMed Beatmungslösungen ... Qualitative Versorgung leicht gemacht</div>');
    rotateFeatureMessage();

    //else if (g_strLocaleCode=='la') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Ventilación ... para la calidad de vida</div><div class="homepagefeaturemessage" id="message2">ResMed Soluciones en Ventilación ... Haciendo fácil la calidad de la atención</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='br') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">durma melhor ... para uma vida melhor</div><div class="homepagefeaturemessage" id="message2">Soluções de Ventilação da ResMed ... Tornado a qualidade de cuidados fácil...</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='au') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">sleep better ... for a better life</div><div class="homepagefeaturemessage" id="message2">ResMed Ventilation Solutions ... Making quality of care easy</div>');
    //		rotateFeatureMessage();
    //	} else if (g_strLocaleCode=='no') {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">Sov bedre ... for et bedre liv</div><div class="homepagefeaturemessage" id="message2">ResMeds Ventilasjonsløsninger ... Enkel behandling med høy kvalitet</div>');
    //		rotateFeatureMessage();
    //	} else {
    //		$j('#homepagefeatureimage').append('<div id="homepagefeaturemessagestrip"></div><div class="homepagefeaturemessage" id="message1">sleep better ... for a better life</div><div class="homepagefeaturemessage" id="message2">ResMed Ventilation Solutions ... Making quality of care easy</div>');
    //		rotateFeatureMessage();
    //	}

    if(jQuery.browser.version=='6.0') {
        $j.ifixpng('/lib/images/pixel.gif');
        $j('img[src$=.png], .arrow-link2, div#searchpanelclose').ifixpng();
        $j('#leftnav a.toggle').filter(function(){
            return !$j(this).next().find('a').is('.loaf');
        }).next().hide();
    }
    $j('#leftnav a.toggle').filter(function(){
        return $j(this).next().find('a').is('.loaf');
    }).next().show();
    $j('div#leftnav a.toggle').click(function(){
        $j(this).next().slideToggle('fast');
        return false;
    });


    //	$j('.promobox').wrap('<div class="dialog"><div class="dialogcontent"></div></div>');
    //	$j('.dialogcontent').prepend('<div class="t"></div>');
    //	$j('.dialog').append('<div class="b"><div>');



    $j('.catalogitemthumb, .productsectionthumb, .gallerynavthumb, .serviceitemthumb, .contactsectionthumb, .videosectionthumb, .galleryimagelarge.active').wrap('<div class="dswrap0"><div class="dswrap1"><div class="dswrap2"><div class="dswrap3"></div></div></div></div>');
    $j('.gallerynavthumb img').wrap('<a href="javascript: void(0);"></a>');
    $j('div.gallerynavthumb').each(function() {
        if ($j(this).attr("id") == "0") {
            $j(this).children("a").addClass("activeSlide");
        }
    });
    //	$j('#balloonPopupContainer .balloonPopupPopup td').ifixpng();

    selectFontSize(false);
    //	Shadowbox.init({skipSetup:true});

    $j('div#search input#searchfield').focus(function(){
        $j(this).val('');
    });

    $j('div#search input#searchfield').blur(function(){
        if ($j(this).val()=='') {
    //$j(this).val(GUILanguageStrings.strings.ui['search_textbox']);
    }
    });

    $j('#content a.presentation').each(function(){
        var oLink = $j(this);
        Shadowbox.setup(oLink, {
            player:'iframe'
        });
    });

    $j('#content a[href$=.jpg]').each(function(){
     //   var oLink = $j(this);
     //   Shadowbox.setup(oLink, {
     //       player:'img'
    //    });
    });


    $j('#content a[href$=.flv]').each(function(){
        setMediaPlayerSetup($j(this), 'flv');
    }).filter(':not(:has(img))').addClass('streaming-flv');

    $j('#content a[href$=.mp4]').each(function(){
        setMediaPlayerSetup($j(this), 'mp4');
    });
	
/*    $j('#content a[href$=.mp4]').each(function(){
        setMediaPlayerSetup($j(this), 'mp4');
    }).filter(':not(:has(img))').addClass('streaming-mp4');	*/


    //	$j('#content a[href$=.flv]').addClass('streaming-flv').each(function(){
    //		setMediaPlayerSetup($j(this));
    //	});
    $j('#content a[href$=.wmv]').addClass('streaming-wmv').each(function(){
        setMediaPlayerSetup($j(this), 'wmv');
    });
    $j('#content a[href$=.swf]').each(function(){
        setMediaPlayerSetup($j(this), 'swf');
    }).filter(':not(:has(img))').addClass('doc-flash');

    $j('#content a[href$=.zip]').addClass('doc-zip');
    $j('#content a[href$=.exe]').addClass('doc-exe');
    $j('#content a[href$=.doc]').addClass('doc-doc');
    $j('#content a[href$=.xls]').addClass('doc-xls');
    $j('#content a[href$=.ppt]').addClass('doc-ppt');
    $j('#content a[href$=.pdf]').filter(function () {
        return !($j(this).parent('li').hasClass('doc-pdf') || $j(this).children('img').length || $j(this).hasClass('noicon'));
    //		return !$j(this).parent('li').hasClass('doc-pdf');
    }).addClass('doc-pdf');

    if ($j('#contentcolumns a[href$=.pdf]').length) {
        $j('#contentcolumns').append('<div class="acrobat-notice""><a href="http://www.adobe.com/products/acrobat/readstep2.html" title="Get Acrobat Reader" target="_blank"><img src="fileadmin/template/images/get_adobe_reader.gif" width="112" height="33" alt="Get Acrobat Reader" /></a></div>');
    }

    $j('#searchpanelclose').click(function(){
        //$j(document).unbind('keydown', 'esc');
        $j('#searchpanelcontainer').hide('slide', {
            direction: 'up'
        }, 'slow');
    });

    $j('a').click(function(){
        $j(this).blur();
    });
    $j('a').focus(function(){
        $j(this).blur();
        return false;
    });


    $j('div#rightcolumn div.productdocslist a.toggle').click(function(){
        var $jthis = $j(this);
        $jthis.next().slideToggle('fast', function(){
            $j($jthis).toggleClass('a-mi-minus').toggleClass('a-mi-plus');
        });
        return false;
    });
    $j('div#content ul.productdocscategory strong.toggle').click(function(){
        var $jthis = $j(this);
        $jthis.next().slideToggle('fast', function(){
            $j($jthis).toggleClass('a-mi-minus').toggleClass('a-mi-plus');
        });
        return false;
    });
    //	$j('div#content ul.productdocscategory li.prodname a.toggle').click(function(){
    $j('div#content li.prodname a.toggle').click(function(){
        var $jthis = $j(this);
        $jthis.next().slideToggle('fast', function(){
            $j($jthis).toggleClass('a-mi-minus').toggleClass('a-mi-plus');
        });
        return false;
    });
    $j('div#content li.prodname_nested a.toggle').click(function(){
        var $jthis = $j(this);
        $jthis.next().slideToggle('fast', function(){
            $j($jthis).toggleClass('a-mi-minus').toggleClass('a-mi-plus');
        });
        return false;
    });
    $j('div.faq-q a').click(function(e){
        e.preventDefault();
        var $jthis = $j(this).parent();

        if($j($jthis).siblings('div.faq-a').is(":hidden"))
        {
            //wenn Click eine Box �ffnen soll, alle vorher offenen Boxen schlie�en lassen
            $j('div.faq-q a').parent(".mi-minus").toggleClass('mi-minus').toggleClass('mi-plus').siblings('div.faq-a:visible').slideToggle('fast');
        }
        $jthis.siblings('div.faq-a').slideToggle('fast', function(){
            $j($jthis).toggleClass('mi-minus').toggleClass('mi-plus');
        });
    });

    $j('a.expandable-handle').click(function(e){
        e.preventDefault();
        var $jthis = $j(this);

        if($j($jthis).closest('p').nextAll('div.expandable-section:first').is(":hidden"))
        {
            //wenn Click eine Box �ffnen soll, alle vorher offenen Boxen schlie�en lassen
            $j('a.expandable-handle.a-mi-minus').toggleClass('a-mi-minus').toggleClass('a-mi-plus').closest('p').nextAll('div.expandable-section:first').slideToggle('fast');
        }
        $j($jthis).closest('p').nextAll('div.expandable-section:first').slideToggle('fast', function(){
            $j($jthis).toggleClass('a-mi-minus').toggleClass('a-mi-plus');
        });
    });

    $j('#registrationform :input:first').focus();
    $j('#softwareregistrationform :input:first').focus();
    $j('#passwordresetform input:first').focus();

    $j('#registrationform #servicecheckbox_dealers').click(function(){
        var $jthis = $j(this);
        if ($j('#registrationform #servicecheckbox_dealers').is(':checked')) {
            $j('#registrationform #existing_customer_div').show();
        } else {
            $j('#registrationform #customer_number').rules('remove', 'required');
            $j('#registrationform #customer_number').attr('value', '');
            //			$j('#registrationform #customer_number').val('');
            $j('#registrationform #existing_customer').attr('checked', false);
            $j('#registrationform #customer_number_div').hide();
            $j('#registrationform #existing_customer_div').hide();
        }
    });

    $j('#registrationform #existing_customer').click(function(){
        var $jthis = $j(this);
        if ($j('#registrationform #existing_customer').is(':checked')) {
            $j('#registrationform #customer_number').rules('add', {
                required: true
            });
            $j('#registrationform #customer_number_div').show();
        } else {
            $j('#registrationform #customer_number').rules('remove', 'required');
            $j('#registrationform #customer_number').attr('value', '');
            //			$j('#registrationform #customer_number').val('');
            $j('#registrationform #customer_number_div').hide();
        }
    });

    /*
$j('#registrationform #servicecheckbox_clinicians_extend_easycare-std').click(function(){
		var $jthis = $j(this);
		if ($j('#registrationform #servicecheckbox_clinicians_extend_easycare-std:checked').length) {
			$j('#registrationform #easycare-std_service_div').show();
		} else {
			$j('#registrationform #servicecheckbox_easycarestd').attr('checked', false);
			$j('#registrationform #easycare-std_service_div').hide();
		}
	});
*/


    // START - Handle display and value of state select field based on country select field
    $j('form#registrationform select#country, form#accountdetailsform select#country').selectChain({
        target: '#state',
        url: '/lib/jsp/request/getstatesbycountrykey.jsp',
        key:'code',
        value:'name',
        data:'countryKey',
        selectedfrom:'#selectedstate',
        blankkey:'NA',
        blankvalue:'Not Applicable',
        firstkey:'',
        firstvalue:'Select'
    });


    $j('select#region').change(function(){
        $j.getJSON('/lib/jsp/request/get_products_groups.jsp',{
            region: $j(this).val()
        }, function(j){
            var options = '<option value="">Select Product Category</>';
            for (var i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].value + '">' + j[i].label + '</option>';
            }
            $j('#productgroup').html(options);
            $j('#productgroup option:first').attr('selected', 'selected');
            $j('#productgroup').trigger('change');
        })
        $j.getJSON('/lib/jsp/request/get_locale_languages.jsp',{
            region: $j(this).val()
        }, function(j){
            var options = '';
            if (j.length>1) {
                options += '<option value="">All Applicable</>';
            }
            for (var i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].value + '">' + j[i].label + '</option>';
            }
            $j('#language').html(options);
            $j('#language option:first').attr('selected', 'selected');
            $j('#language').trigger('change');
        })
        $j('#doctype option').attr('selected', '');
        $j('#doctype option:first').attr('selected', 'selected');


    });
    $j('select#productgroup').change(function(){
        $j.getJSON('/lib/jsp/request/get_products_list.jsp',{
            productgroup: $j(this).val(),
            region: $j('#region').val()
        }, function(j){
            var options = '<option value="">All</>';
            for (var i = 0; i < j.length; i++) {
                options += '<option value="' + j[i].value + '">' + j[i].label + '</option>';
            }
            $j('#product').html(options);
            $j('#product option:first').attr('selected', 'selected');
            $j('#product').trigger('change');
        })
    });



    $j('form#locate_distributor_me_af select#country').change(function(){
        var $jthis = $j(this);
        if ($jthis.val()=='other') {
            $j('form#locate_distributor_me_af input#user_country').rules('add', {
                required: true
            });
            $j('form#locate_distributor_me_af div#user_specified_country').show();
        } else {
            $j('form#locate_distributor_me_af input#user_country').rules('remove', 'required');
            $j('form#locate_distributor_me_af div#user_specified_country').hide();
        }
    });
    $j('form#customer_enquiry select#country').change(function(){
        var $jthis = $j(this);
        if ($jthis.val()=='other') {
            $j('form#customer_enquiry input#user_country').rules('add', {
                required: true
            });
            $j('form#customer_enquiry div#user_specified_country').show();
        } else {
            $j('form#customer_enquiry input#user_country').rules('remove', 'required');
            $j('form#customer_enquiry div#user_specified_country').hide();
        }
    });

    /*
$j('select#product, select#productgroup').change(function(){
	var options = '<option value="">Select</>';
	if (($j('#product').val()!='')||($j('#productgroup').val()!='')) {

		options += '<option value="fact_sheet">Fact Sheets</option>';
		options += '<option value="user_guide">User Guides</option>';
		options += '<option value="components_card">Components Cards</option>';
		options += '<option value="fitting_guide">Fitting Guides</option>';
		options += '<option value="patient_brochure">Patient Brochures</option>';
		options += '<option value="product_brochure">Product Brochures</option>';
		options += '<option value="quick_setup_guide">Quick Setup Guides</option>';
		options += '<option value="clinical_manual">Clinical Manuals</option>';
		options += '<option value="data_management_guide">Data Management Guide</option>';
	}
	$j('#doctype').html(options);
	$j('#doctype option:first').attr('selected', 'selected');
});
*/



    /*
	$j('#region').selectChain({
		target: '#productgroup',
		url: '/lib/jsp/request/get_products_groups.jsp',
		key:'value',
		value:'label',
		data:'regionKey',
		selectedfrom:'#region',
		blankkey:'NA',
		blankvalue:'None Found',
		firstkey:'',
		firstvalue:'Select'
	}).trigger('change');
	$j('#productgroup').selectChain({
		target: '#product',
		url: '/lib/jsp/request/get_products_list.jsp',
		key:'value',
		value:'label',
		data:'region:'+$j('#region').val(),
		selectedfrom:'#productgroup',
		blankkey:'NA',
		blankvalue:'None Found',
		firstkey:'',
		firstvalue:'Select'
	});
*/
    /*
	$j('#region').selectChain({
		target: '#products',
		url: '/lib/jsp/request/get_products_list.jsp',
		key:'value',
		value:'label',
		data:'regionKey',
		selectedfrom:'#region',
		blankkey:'NA',
		blankvalue:'None Found',
		firstkey:'',
		firstvalue:'Select'
	});
*/

    $j('#registrationform #state').change(function(){ // remmember the value of the selected state in a hidden field
        //	   alert($j('#registrationform #state').val());
        $j('#registrationform #selectedstate').val($j('#registrationform #state').val());
    });
    $j('#accountdetailsform #resetform').click(function(){
        window.open(g_strCurrentURL, '_self');
    }); // clear values on form reset
    // END - Handle display and value of state select field based on country select field

    if ($j('#serverMessage').length){
        $j('#serverMessage').modal({
            onOpen: ajaxFormModalOpen,
            onClose: closeModal
        });
    }

    $j('.modallink').click(function(e){
        e.preventDefault();
        getFormModal($j(this).attr('href'));
    });

    $j('#simplemodal-container #cancelform').live('click', function(){
        closeModal();
    });
    $j('#simplemodal-container #redirecttologin').live('click', function(){
        redirectToLogin();
    });
    $j('#simplemodal-container #redirecttohome').live('click', function(){
        redirectToHome();
    });
    $j('#simplemodal-container #reloadpage').live('click', function(){
        reloadPage();
    });
    $j('#simplemodal-container #submitform').live('click', function(){
        submitForm();
    });

    //	$j.validator.setDefaults({
    //		errorPlacement: function(error, element){
    //			error.insertBefore(element);
    //		},
    //		messages: {
    //			email: {
    //				email: GUILanguageStrings.strings.validator['email_message']
    //			},
    //			confirm_email: {
    //				email: GUILanguageStrings.strings.validator['email_message']
    //			},
    //			new_email: {
    //				email: GUILanguageStrings.strings.validator['email_message']
    //			},
    //			confirm_new_email: {
    //				email: GUILanguageStrings.strings.validator['email_message']
    //			},
    //			j_username: {
    //				email: GUILanguageStrings.strings.validator['email_username_message']
    //			}
    //		}
    //	});

    $j.extend($j.validator.messages, {
        //		Default Messages Strings in jquery.validate - This script is limited to these strings
        //		required: 'This field is required',
        //		remote: "Please fix this field.",
        //		email: "Please enter a valid email address.",
        //		url: "Please enter a valid URL.",
        //		date: "Please enter a valid date.",
        //		dateISO: "Please enter a valid date (ISO).",
        //		dateDE: "Bitte geben Sie ein gültiges Datum ein.",
        //		number: "Please enter a valid number.",
        //		numberDE: "Bitte geben Sie eine Nummer ein.",
        //		digits: "Please enter only digits",
        //		creditcard: "Please enter a valid credit card number.",
        //		equalTo: "Please enter the same value again.",
        //		accept: "Please enter a value with a valid extension.",
        //		maxlength: $.validator.format("Please enter no more than {0} characters."),
        //		minlength: $.validator.format("Please enter at least {0} characters."),
        //		rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
        //		range: $.validator.format("Please enter a value between {0} and {1}."),
        //		max: $.validator.format("Please enter a value less than or equal to {0}."),
        //		min: $.validator.format("Please enter a value greater than or equal to {0}.")
        //	required: GUILanguageStrings.strings.validator['required'],
        //	minlength: $j.validator.format(GUILanguageStrings.strings.validator['minlength'])
        });

    $j.validator.addMethod('rmdpassword', function(value, element){
        return this.optional(element) || /^\w*(?=\w{8,})(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/.test(value);
    }, "A password must be at least 8 characters long and have at least one uppercase, one lowercase and one numeric character");

    $j.validator.addMethod('us_phone', function(value, element){
        return this.optional(element) || /(^[1-9]?\([1-9]\d{2}\)[\s|\-]?\d{3}[\s|\-]?\d{4}$)|(^[1-9]?[\s|\-]?[1-9]\d{2}[\s|\-]?\d{3}[\s|\-]?\d{4}$)/.test(value);
    }, "Please enter a phone number in the format 1-000-000-0000 or 1(000)000-0000.");
    $j.validator.addMethod('us_fax', function(value, element){
        return this.optional(element) || /(^[1-9]?\([1-9]\d{2}\)[\s|\-]?\d{3}[\s|\-]?\d{4}$)|(^[1-9]?[\s|\-]?[1-9]\d{2}[\s|\-]?\d{3}[\s|\-]?\d{4}$)/.test(value);
    }, "Please enter a fax number in the format 000-000-0000 or (000)000-0000 or (000) 000 0000.");
    $j.validator.addMethod('us_pcode', function(value, element){
        return this.optional(element) || /(^\d{5}$)|(^\d{5}[\s|\-]?\d{4}$)|(^\w\d\w[\s|\-]?\d\w\d$)/.test(value);
    }, "Please enter a zip/post code in US format e.g. 00000 or 00000 0000 or in Canadian format e.g. A0A 0A0.");

    $j.validator.addMethod('au_phone', function(value, element){
        return this.optional(element) || /(^[1-9]\d{3}[\s|\-]?\d{4}$)|(^\(?[0][1-9]\)?[\s\-]?[1-9]\d{3}[\s|\-]?\d{4}$)/.test(value);
    }, "Please enter a phone number in the format 0000 0000 or 00 0000 0000.");
    $j.validator.addMethod('au_fax', function(value, element){
        return this.optional(element) || /(^[1-9]\d{3}[\s|\-]?\d{4}$)|(^\(?[0][1-9]\)?[\s\-]?[1-9]\d{3}[\s|\-]?\d{4}$)/.test(value);
    }, "Please enter a fax number in the format 0000 0000 or 00 0000 0000.");
    $j.validator.addMethod('au_pcode', function(value, element){
        return this.optional(element) || /^\d{4}$/.test(value);
    }, "Please enter a post code in the format 0000.");

    $j.validator.addMethod('uk_phone', function(value, element){
        return this.optional(element) || /^[0-9 ]+$/.test(value);
    }, "Please enter a valid phone number using only numbers and spaces");
    $j.validator.addMethod('uk_fax', function(value, element){
        return this.optional(element) || /^[0-9 ]+$/.test(value);
    }, "Please enter a valid fax number using only numbers and spaces");
    $j.validator.addMethod('uk_pcode', function(value, element){
        return this.optional(element) || /^([A-Za-z]{1,2})([0-9]{1,2})([A-Za-z]{0,1})([ ]{0,1})([0-9]{1})([A-Za-z]{2})$/.test(value);
    }, "Please enter a post code in the correct format.");

    //	$j("#registrationform").validate({
    //		rules: {
    //			reenterpassword:{equalTo:'#password'},
    //			serviceName: {
    //				required: true
    //			}
    //		},
    //		messages: {
    //			serviceName: GUILanguageStrings.strings.validator['requiredcheckedmin']
    //		},
    //		submitHandler: handlePageFormSubmit
    //	});
    $j("#changepasswordform").validate({
        rules: {
            confirm_new_password:{
                equalTo:'#new_password'
            }
        },
        submitHandler: handlePageFormSubmit
    });

    $j("#accountdetailsform").validate({
        submitHandler: handlePageFormSubmit
    });

    $j("#productdocuments").validate({
        submitHandler: handlePageFormSubmit
    });

    $j('a.noclick').click(function(e){
        e.preventDefault();
        return false;
    });



    $j("#passwordresetform").validate({
        rules: {
            email: 'required email',
            verification_code: 'required'
        },
        submitHandler: handlePageFormSubmit
    });
    $j("#loginform").validate({
        rules: {
            j_username: 'required email',
            j_password: 'required rmdpassword'
        },
        submitHandler: handlePageFormSubmit
    });
    $j("#softwareregistrationform").validate({
        submitHandler: handlePageFormSubmit
    });
    $j("#locate_distributor_me_af").validate({
        submitHandler: handleEmailFormSubmit
    });
    $j("#distributor_application_me_af").validate({
        submitHandler: handleEmailFormSubmit
    });
    $j("#rga").validate({
        submitHandler: handleEmailFormSubmit
    });
    $j("#customer_enquiry").validate({
        submitHandler: handleEmailFormSubmit
    });

    $j('#captchaimage').click(function(e){
        e.preventDefault();
        $j.post('/lib/jsp/request/captcha.jsp', function(data){
            $j('#captchaimage').attr('src', data);
        });
    });

    $j("#loginlink").click(function(e){
        e.preventDefault();
        showLogin();
    });

    $j("a.loginlink").click(function(e){
        e.preventDefault();
        showLogin();
    });

    var fm = $j('#searchform').bind('submit',function(e){
        //		var fld = [];
        //		$j('input',fm).not('[type=submit]').each(function(){
        ////			fld.push(this.name+'='+encodeURIComponent($j(this).val().replace(/^#/,'')));
        //			fld.push(this.name+'='+this.value);
        //		});
        //		var url = fm.attr('action')+'?'+fld.join('&');
        //		doSearch(url);
        //		fm[0].reset();
        loadSearchView(jQuery("#searchfield").val());
        return false;
    });

    function loadSearchView(input){
        jQuery.ajax({
            url: "index.php",
            type: "POST",
            async: true,
            data: {
                eID: "searchView_eID",
                input: input,
                filtercall: "false"
            },
            dataType: "html",
            success: function(response){

                jQuery("#searchpanelresults").html(response);
                jQuery("#searchpanelcontainer").fadeIn("slow");
            },
            error: function(x, e){
                var err_text = "";
                if (x.status == 0) {
                    err_text = 'Server Connection Error.';
                }
                else
                if (x.status == 404) {
                    err_text = 'Requested URL not found.';
                }
                else
                if (x.status == 500) {
                    err_text = 'Internal Server Error.';
                }
                else
                if (e == 'parsererror') {
                    err_text = 'Error:\nParsing JSON Request failed.';
                }
                else
                if (e == 'timeout') {
                    err_text = 'Request Time out.';
                }
                else {
                    err_text = 'Unknow Error:\n' + x.responseText;
                }

            }
        });
    }

    $j('div#searchsubmit').click(function(e){
        $j('#searchform').submit();
    });

    $j('#savedsearch').click(function(e){
        if ($j('#searchpanelcontainer').css('display')=='none'){
            $j('#searchform').submit();
        }
    });

    if ($j('#galleryimagelarge').length) {
        $j('#galleryimagelarge').cycle({
            fx:    'fade',
            speedIn:  250,
            speedOut: 100,
            timeout: 0,
            pager:  '#gallerynav' ,
            pagerAnchorBuilder: function(idx, slide) {
                return '#gallerynav li:eq(' + idx + ') a';
            }
        });
    }
    if ($j('#featureproductrotationimage').length) {
        $j('#featureproductrotationimage').cycle({
            fx:    'fade',
            timeout: 5000,
            pager:  '#featureproductrotationnav' ,
            pagerAnchorBuilder: function(idx, slide) {
                return '#featureproductrotationnav li:eq(' + idx + ') a';
            }
        });
    }

    $j('a#ventilation-accessories-selectallproducts').click(function(){
        $j('input:checkbox[name=productcode]').attr('checked', true);
    });
    $j('a#ventilation-accessories-selectallcategories').click(function(){
        $j('input:checkbox[name=accessorycategorycode]').attr('checked', true);
    });



    //	$j('.tooltips').each(function(){
    //		var jthis = $j(this);
    //		jthis.qtip({
    //			content: jthis.html(),
    //			position: {
    //				target: 'mouse',
    //           	corner: {
    //					tooltip: 'bottomLeft',
    //					target: 'topRight'
    //				},
    //				adjust: {
    //					mouse: false,
    //					x: 15,
    //					y: 15
    //				}
    //			},
    //			show: {
    //				delay: 0
    //			}
    //		});
    //	});



    //	$j('.homepagechannellink').qtip({content: '<img src="'+$j(this).find('img').attr('src')+'" />'});


    //	var toolTip = $j('<div id="tooltipContent">'
    //	  + '<p>This is a tooltip</p>'
    //	  + '</div>');

    //	$j('body').append(toolTip);




    //	$j('.tooltip').ezpz_tooltip({contentId:'tooltipContent'});



    //	$j('body').append('<div id="tooltipContent"></div>');
    //	$j('.accessoriesthumbnailtooltip').each(function(){
    //		var jthis = $j(this);
    //		jthis.ezpz_tooltip({
    //			contentId:'tooltipContent',
    //			beforeShow: function(content){
    //					content.html(jthis.html());
    //			}
    //		});
    //	});


    $j('.getfiledownload').click(function(e){
        e.preventDefault();
        $j.blockUI();
        $j.get('/'+g_strLocaleCode+'/lib/jsp/request/get_file_download.jsp', {
            url: $j(this).attr('href')
        }, function(data) {
            if (data!='') {
                window.location = data;
            //		} else {
            //			window.open(g_strCurrentURL, '_self');
            }
            $j.unblockUI();
        });
    });


    $j('.geteasycareactivation').click(function(e){
        e.preventDefault();
        $j.blockUI();
        $j.get('/lib/jsp/request/get_easycare_activationkey.jsp', {
            params: $j(this).attr('href'),
            target: $j(this).attr('rel')
        }, function(data) {
            $j.unblockUI();
        });
    });


    $j('.geteasycaressokey').click(function(e){
        e.preventDefault();
        $j.blockUI();
        $j.get('/lib/jsp/request/get_easycare_ssokey.jsp', {
            params: $j(this).attr('href'),
            target: $j(this).attr('rel')
        }, function(data) {
            $j.unblockUI();
        });
    });

	$j('#vpaplineupproducts a').hover(
	  function () {
                $j("#vpaplineup > div.vpaplineupproductdescription").hide();
		$j(this).addClass("current");
		$j("#vpaplineup > div.vpaplineupproductdescription").eq($j(this).parent().index()).show();
	  },
	  function () {
		$j(this).removeClass("current");
		//$j("#vpaplineup > div.vpaplineupproductdescription").eq($j(this).parent().index()).hide();
	  }
	);

});




function setMediaPlayerSetup(oLink, strMediaType) {
    //	var strMediaFileName = parseUri(oLink.attr('href')).fileName;
    var strMediaFileName = oLink.attr('href');
    //	var strMediaFileDimensions = strMediaFileName.match(/\d\d\d/g);

    //			alert(strMediaFileName.match(/\d{2,3}[x]\d{2,3}/));

    var strMediaFileDimensions = strMediaFileName.match(/\d{2,3}[x]\d{2,3}/);
    if (strMediaFileDimensions != null) {
        var nMediaFileDimensionWidth = 320;
        var nMediaFileDimensionHeight = 180;
        var nExtraHeight = 0;
        if (strMediaType == 'wmv' && !isIE()) {
            nExtraHeight = 20;
        } else if (strMediaType == 'flv') {
            nExtraHeight = 0;
        } else if (strMediaType == 'mp4') {
            nExtraHeight = 0;
        }

        if (strMediaFileDimensions.length > 0) {
            strMediaFileDimensions = strMediaFileDimensions[0].match(/\d{2,3}/g);
            nMediaFileDimensionWidth = parseInt(strMediaFileDimensions[0]);
            nMediaFileDimensionHeight = parseInt(strMediaFileDimensions[1]);
        }
        nMediaFileDimensionHeight += nExtraHeight;
        //		alert(nMediaFileDimensionWidth+'|'+nMediaFileDimensionHeight);
        //		if (strMediaFileDimensions.length==2) {
        //			if (oLink.hasClass('streaming-wmv') && !isIE()) {
        //				nExtraHeight = 20;
        //			}
        //			var nMediaFileDimensionWidth = parseInt(strMediaFileDimensions[0]);
        //			var nMediaFileDimensionHeight = parseInt(strMediaFileDimensions[1])+nExtraHeight;
        Shadowbox.setup(oLink, {
            autoplayMovies: true,
            height: nMediaFileDimensionHeight,
            width: nMediaFileDimensionWidth
        });
    //		}
    }
}






























