new function(p) { var r = p.separator || '&'; var s = p.spaces === false ? false : true; var u = p.suffix === false ? '' : '[]'; var v = p.prefix === false ? false : true; var w = v ? p.hash === true ? "#" : "?" : ""; var x = p.numbers === false ? false : true; jQuery.query = new function() { var j = function(o, t) { return o != undefined && o !== null && (!!t ? o.constructor == t : true) }; var k = function(a) { var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(a), base = match[1], tokens = []; while (m = rx.exec(match[2])) tokens.push(m[1]); return [base, tokens] }; var l = function(a, b, c) { var o, token = b.shift(); if (typeof a != 'object') a = null; if (token === "") { if (!a) a = []; if (j(a, Array)) { a.push(b.length == 0 ? c : l(null, b.slice(0), c)) } else if (j(a, Object)) { var i = 0; while (a[i++] != null); a[--i] = b.length == 0 ? c : l(a[i], b.slice(0), c) } else { a = []; a.push(b.length == 0 ? c : l(null, b.slice(0), c)) } } else if (token && token.match(/^\s*[0-9]+\s*$/)) { var d = parseInt(token, 10); if (!a) a = []; a[d] = b.length == 0 ? c : l(a[d], b.slice(0), c) } else if (token) { var d = token.replace(/^\s*|\s*$/g, ""); if (!a) a = {}; if (j(a, Array)) { var e = {}; for (var i = 0; i < a.length; ++i) { e[i] = a[i] } a = e } a[d] = b.length == 0 ? c : l(a[d], b.slice(0), c) } else { return c } return a }; var n = function(a) { var c = this; c.keys = {}; if (a.queryObject) { jQuery.each(a.get(), function(a, b) { c.SET(a, b) }) } else { jQuery.each(arguments, function() { var q = "" + this; q = q.replace(/^[?#]/, ''); q = q.replace(/[;&]$/, ''); if (s) q = q.replace(/[+]/g, ' '); jQuery.each(q.split(/[&;]/), function() { var a = decodeURIComponent(this.split('=')[0] || ""); var b = decodeURIComponent(this.split('=')[1] || ""); if (!a) return; if (x) { if (/^[+-]?[0-9]+\.[0-9]*$/.test(b)) b = parseFloat(b); else if (/^[+-]?[0-9]+$/.test(b)) b = parseInt(b, 10) } b = (!b && b !== 0) ? true : b; if (b !== false && b !== true && typeof b != 'number') b = b; c.SET(a, b) }) }) } return c }; n.prototype = { queryObject: true, has: function(a, b) { var c = this.get(a); return j(c, b) }, GET: function(a) { if (!j(a)) return this.keys; var b = k(a), base = b[0], tokens = b[1]; var c = this.keys[base]; while (c != null && tokens.length != 0) { c = c[tokens.shift()] } return typeof c == 'number' ? c : c || "" }, get: function(a) { var b = this.GET(a); if (j(b, Object)) return jQuery.extend(true, {}, b); else if (j(b, Array)) return b.slice(0); return b }, SET: function(a, b) { var c = !j(b) ? null : b; var d = k(a), base = d[0], tokens = d[1]; var e = this.keys[base]; this.keys[base] = l(e, tokens.slice(0), c); return this }, set: function(a, b) { return this.copy().SET(a, b) }, REMOVE: function(a) { return this.SET(a, null).COMPACT() }, remove: function(a) { return this.copy().REMOVE(a) }, EMPTY: function() { var c = this; jQuery.each(c.keys, function(a, b) { delete c.keys[a] }); return c }, load: function(a) { var b = a.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1"); var c = a.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1"); return new n(a.length == c.length ? '' : c, a.length == b.length ? '' : b) }, empty: function() { return this.copy().EMPTY() }, copy: function() { return new n(this) }, COMPACT: function() { function build(c) { var d = typeof c == "object" ? j(c, Array) ? [] : {} : c; if (typeof c == 'object') { function add(o, a, b) { if (j(o, Array)) o.push(b); else o[a] = b } jQuery.each(c, function(a, b) { if (!j(b)) return true; add(d, a, build(b)) }) } return d } this.keys = build(this.keys); return this }, compact: function() { return this.copy().COMPACT() }, toString: function() { var i = 0, queryString = [], chunks = [], self = this; var f = function(a) { a = a + ""; if (s) a = a.replace(/ /g, "+"); return encodeURIComponent(a) }; var g = function(a, b, c) { if (!j(c) || c === false) return; var o = [f(b)]; if (c !== true) { o.push("="); o.push(f(c)) } a.push(o.join("")) }; var h = function(c, d) { var e = function(a) { return !d || d == "" ? [a].join("") : [d, "[", a, "]"].join("") }; jQuery.each(c, function(a, b) { if (typeof b == 'object') h(b, e(a)); else g(chunks, e(a), b) }) }; h(this.keys); if (chunks.length > 0) queryString.push(w); queryString.push(chunks.join(r)); return queryString.join("") } }; return new n(location.search, location.hash) } } (jQuery.query || {});
$(document).ready(function() {
    SetAccordion();
    OpenPartnerLogin();
   
});

function SetAccordion() {

    var accordionBox = $(".accordionBox");
    if ($(accordionBox).length < 1) return;
    
    
            $(accordionBox).find("h4").wrap("<a class='ah4' href='#' />");

            var imgArrow = "<img class='imgArrow' style='padding:0 5px;' id='imgArrow' src='../Content/images/common/arrowblue.png'/>";
            var imgArrowbluedown = "<img class='imgArrow' id='imgArrow' style='padding:0 5px;' src='../Content/images/common/arrowbluedown.png'/>";
    
            $(".ah4").click(function() {

                    var parent = $(this).parents(".accordionItem:eq(0)");
                    var img = $(this).find(".imgArrow");
                    var parag = $(parent).find("div:first");
                    var h4 = $(this).find("h4:first");
                    
                    $(img).remove();

                    if ($(parent).is(".selected")) {
                        $(parag).hide("300");
                        $(parent).removeClass("selected");
                        $(h4).prepend(imgArrow);
                    } else {
                        $(parag).show("200");
                        $(parent).addClass("selected");
                        $(h4).prepend(imgArrowbluedown);
                    }
             
                    return false;
                });

                var accordionIndex = $.query.get('accid');
                $(accordionBox).find(".accordionItem.selected").removeClass("selected");
                if (accordionIndex) {
                    $(accordionBox).find("." + accordionIndex).addClass("selected");
                } else if (accordionIndex == 'KO') {
                ;//do nothing
                }
                else {
                    $(accordionBox).find(".accordionItem:eq(0)").addClass("selected");
                }

    var divNotSelect = $(accordionBox).find(".accordionItem:not(.selected)");
      divNotSelect.find("h4").prepend(imgArrow);
      divNotSelect.find("div:first").hide();

    var divSelect = $(accordionBox).find(".accordionItem.selected");
      divSelect.find("h4").prepend(imgArrowbluedown);
      divSelect.find("div:first").show();
  }


  function processSlideshow(elem, imageList, imageDuration, fadeSpeed, current) {
          var listSize = imageList.length;
          if (!current || current >= listSize) current = 0;
          if (!imageDuration) imageDuration = 2000;
          if (!fadeSpeed) fadeSpeed = 1000;
          $(elem + " img").attr("src", imageList[current]);
          if (current == (listSize - 1)) {
              $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
          } else {
              $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
          }
          $(elem + " img").animate({ opacity: "1" }, imageDuration).
     animate({ opacity: "0.01" }, fadeSpeed, function() {
         $(this).css("opacity", "1"); processSlideshow(elem, imageList, imageDuration, fadeSpeed, current + 1)
     });
  }
  
  
  function OpenPartnerLogin()
  {
     
  // $("#PartnerResourcesLogin").click(function(){});
  
   if($('[id$=lblLoginError].show').length > 0){
  // alert('test');
        showPopup("#LoginDialog");
        $('[id$=lblLoginError]').removeClass("show");
    return;
   }
  
   $('a[name=modal]').click(function(e) {
    
    if($('input[id$=IsPR_Login]').val() == 'True')
      {
           document.location="PartnerResources.aspx";
        return;
      }  
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	showPopup(id);
		
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
  }
  
  
  function showPopup(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("slow",0.7);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
//		alert($("#ctl00_PartnerLoginBox1_txtPassword").length);
		$("#ctl00_PartnerLoginBox1_txtPassword").focus().change(function(){
		    if (window.event.keyCode == 13) // Enter pressed?
            { 
	             $("#ctl00_PartnerLoginBox1_btnLogin").submit(); 
//	             alert($("#ctl00_PartnerLoginBox1_btnLogin").length);
            }
		});
		
		
		$('a[name=modal]').click(function(e) {
    
    if($('input[id$=IsPR_Login]').val() == 'True')
      {
           document.location= "PartnerResources.aspx";
        return;
      }  
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	showPopup(id);
		
	
	});
	
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
  }
