﻿var currentclass; 
/*** COMMON FUNCTIONS ***/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function toggleeffect(elem, effect, dur){
    /*Effect.toggle(element, ['appear' | 'slide' | 'blind'], [options] );*/
    var length = (dur/10);
    Effect.toggle(MM_findObj(elem), effect, {duration: length });
}

function TogglePanel(triggerid, itemid, effect, speed, openedtext, closedtext){
    var length = (speed/10);
    var trigger = document.getElementById(triggerid);
    var item = document.getElementById(itemid);   
    if (trigger) {        
        currentclass = trigger.className;        
    }else{
        currentclass='';
    }
    
    /*** Start Effect ***/  
    Effect.toggle(item, effect, {duration:length, beforeStart:function() {
    /*** Change class and text of trigger ***/
    if (currentclass.indexOf('opened') > -1)
        {
            trigger.className = trigger.className.replace('opened','closed');
            //alert('closing');
            if(openedtext.length > 1){
                trigger.innerHTML = openedtext; 
                trigger.title = openedtext;
            }
        }
        else
        {
            trigger.className = trigger.className.replace('closed','opened');
            //alert('opening');
            if(closedtext.length > 1){
                trigger.innerHTML = closedtext; 
                trigger.title = closedtext;
            }                        
        }
    }});
}
/* Modals */
function showModal(modalcid){
    Effect.Appear(MM_findObj(modalcid),{duration: 0.3});
}
function closeModal(modalcid){
    toggleeffect(modalcid, 'appear',3);
}
function PositionModal(modalid, modalcont, height)
{
    var windowheight = MM_findObj(modalcont).offsetHeight;
    //var modalheight = MM_findObj(modalid).offsetHeight;
    var remainder = windowheight - height;
    remainder = remainder/2 - (height/2);
    //new Effect.Morph(MM_findObj(modalid), {style: 'margin-top:'+remainder+"px",duration: 0.3});
    MM_findObj(modalid).style.marginTop = remainder+"px";
}
/*** END ***/

/*** MA ***/
/* Password Strength */
/* onkeyup checks the string to pass regular expressions to check for combinations of letters, numbers and special characters */
function passwordStrength(txtpassword,imgpstrength) {
	var strength;
	/**amend to pass in the pstrength id as generated by asp.net **/
	if(imgpstrength) {
	    strength = MM_findObj(imgpstrength);
	}else{
	    strength = MM_findObj('pstrength');
	}	
	var strongRegex = new RegExp("^(?=.{7,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
	var medstrongRegex = new RegExp("^(?=.{6,})(((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[a-z])(?=.*\\W))|((?=.*[0-9])(?=.*[a-z])(?=.*\\W))|((?=.*[0-9])(?=.*[A-Z])(?=.*\\W))).*$", "g");
	var mediumRegex = new RegExp("^(?=.{5,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*\\W))|((?=.*[a-z])(?=.*\\W))).*$", "g");
	var lowmedRegex = new RegExp("(?=.{5,}).*", "g");
	var lowRegex = new RegExp("(?=.{4,}).*", "g");
	var pwd = MM_findObj(txtpassword);
	if (pwd.value.length==0){
		MM_findObj('pscont').style.display = "none";
	} else if (false == lowRegex.test(pwd.value)) {
	    MM_findObj('pscont').style.display = "";
		strength.src = '../images/MA/pw_weak.gif';
		strength.alt = 'weak';
	} else if (strongRegex.test(pwd.value)) {
	    MM_findObj('pscont').style.display = "";
		strength.src = '../images/MA/pw_high.gif';
		strength.alt = 'high';
	} else if (mediumRegex.test(pwd.value)) {
	    MM_findObj('pscont').style.display = "";
		strength.src = '../images/MA/pw_medium.gif';
		strength.alt = 'medium';		
		if (medstrongRegex.test(pwd.value)){
		    strength.src = '../images/MA/pw_medhigh.gif';
		    strength.alt = 'medium strong';}
    } else if (lowmedRegex.test(pwd.value)) {
	    MM_findObj('pscont').style.display = "";
		strength.src = '../images/MA/pw_lowmed.gif';
		strength.alt = 'low med';
	} else { 
	    MM_findObj('pscont').style.display = "";
		strength.src = '../images/MA/pw_low.gif';
		strength.alt = 'low';
	}
}
/*** END ***/

/*** SB ***/
function showBasket() {
    TogglePanel('MCOpenClose','MCStretch','slide',8,'<span>Open</span>','<span>Close</span>');
    var isOpened = document.getElementById('MCOpenClose').className.indexOf('opened');
    /*if (isOpened > -1) {
      s.events='scView';void(s.t());
    }*/
}
/* Carousel for minicart */
function fadeoutin(action, setid, setcount, buttonid, hidden, altbuttonid){
        if (MM_findObj(buttonid).getAttribute('disabled') != 'disabled')
        {            
            var currentset = parseInt((MM_findObj(hidden).value)); 
            var settofade = setid+"_"+currentset;
            var nextsettofade = setid+"_"+(currentset+1);
            var previoussettofade = setid+"_"+(currentset-1);
            MM_findObj(altbuttonid).setAttribute('disabled','disabled')
            MM_findObj(buttonid).setAttribute('disabled','disabled')
            if (action == 'next'){ 
                if (currentset < setcount){       
                    Effect.Fade((MM_findObj(settofade)),{duration: 0.5, afterFinish: function(){
                        currentset++;
                        if (currentset < setcount){
                            MM_findObj(buttonid).removeAttribute('disabled')                            
                        }
                        (MM_findObj(hidden)).value = currentset;
                        Effect.Appear((MM_findObj(nextsettofade)),{duration: 0.5});                                      
                    }});
                }
                if (currentset >= 1){
                    MM_findObj(altbuttonid).removeAttribute('disabled')
                }
            }
            if (action == 'previous'){ 
                if (currentset > 1){       
                    Effect.Fade((MM_findObj(settofade)),{duration: 0.5, afterFinish: function(){
                        currentset--;
                        if (currentset > 1){
                           MM_findObj(buttonid).removeAttribute('disabled')
                        }
                        MM_findObj(hidden).value = currentset;
                        Effect.Appear((MM_findObj(previoussettofade)),{duration: 0.5});                    
                    }});
                }
                if (currentset <= setcount){
                    MM_findObj(altbuttonid).removeAttribute('disabled')
                }
            }
        }
    }

function fadeinout(action, setid, setcount, buttonid, hidden, altbuttonid) {
    if (MM_findObj(buttonid).className != 'disabled') {
            var currentset = parseInt((MM_findObj(hidden).value));
            var settofade = setid + "_" + currentset;
            var nextsettofade = setid + "_" + (currentset + 1);
            var previoussettofade = setid + "_" + (currentset - 1);
            MM_findObj(altbuttonid).className = 'disabled'
            MM_findObj(buttonid).className = 'disabled'
            if (action == 'next') {
                if (currentset < setcount) {
                    Effect.Fade((MM_findObj(settofade)), { duration: 0.5, afterFinish: function() {
                        currentset++;
                        if (currentset < setcount) {
                            MM_findObj(buttonid).className = ''
                        }
                        (MM_findObj(hidden)).value = currentset;
                        Effect.Appear((MM_findObj(nextsettofade)), { duration: 0.5 });
                    } 
                    });
                }
                if (currentset >= 1) {
                    MM_findObj(altbuttonid).className = ''
                }
            }
            if (action == 'previous') {
                if (currentset > 1) {
                    Effect.Fade((MM_findObj(settofade)), { duration: 0.5, afterFinish: function() {
                        currentset--;
                        if (currentset > 1) {
                            MM_findObj(buttonid).className = ''
                        }
                        MM_findObj(hidden).value = currentset;
                        Effect.Appear((MM_findObj(previoussettofade)), { duration: 0.5 });
                    } 
                    });
                }
                if (currentset <= setcount) {
                    MM_findObj(altbuttonid).className = ''
                }
            }
        }
    }
function ResetCarousel(hidden) {
    MM_findObj(hidden).value = 1;
}
function ResetCarosel(hidden){
    ResetCarousel(hidden);
}
/*** End ***/

