﻿var theForm;
var tabTimeOutID = null;
var queryString  = new PageQuery(window.location.search); 
var prodcat = unescape(queryString.getValue('c'));
var prod = unescape(queryString.getValue('p'));
var brand = unescape(queryString.getValue('b'));
var range = unescape(queryString.getValue('r'));
var pageName = window.location.pathname;
pageName = '/'+ pageName.substring(pageName.indexOf('/') + 1);

function goURL(pg){
    var qs='';
    if(prodcat!='false') qs += 'c=' + prodcat + '&'
    if(prod!='false') qs += 'p=' + prod + '&'
    if(brand!='false') qs += 'b=' + brand + '&'
    if(range!='false') qs += 'r=' + range + '&'

    if (qs.length>0)
        if (typeof(pg)!='undefined')
            window.location = pg + '?' + qs.substring(0,qs.length-1);
        else
            window.location = pageName + '?' + qs.substring(0,qs.length-1);
    else
        if (typeof(pg)!='undefined')
            window.location = pg;
        else
            window.location = pageName;

}


function ShowPopupImage(myimage) {
	html = "<html><head><title>Allans Music</title></head><body style='margin:20px' onBlur='self.focus()'><img src='" + myimage + "' style='border:0px;' name='image' onload='window.resizeTo(document.image.width+50,document.image.height+95)'></body></html>";
	popup=window.open ('','image','width=10,height=10,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
	popup.document.open();
	popup.document.write(html);
	popup.document.focus();
	popup.document.close()
}
function isValidCC(oSrc, args) {
    var nCheck = 0;
    var nDigit = 0;
    var bEven  = false;

    if(args.Value.length<15){args.IsValid = false;return;}

    for (n = args.Value.length - 1; n >= 0; n--) {
        var cDigit = args.Value.charAt (n);
        if (isDigit (cDigit)) {
            var nDigit = parseInt(cDigit, 10);
            if (bEven) {
                if ((nDigit *= 2) > 9) nDigit -= 9;
            }
            nCheck += nDigit;
            bEven = ! bEven;
        }
        else if (cDigit != ' ' && cDigit != '.' && cDigit != '-'){
            args.IsValid = false;
            return;
        }
    }
    args.IsValid = (nCheck % 10) == 0;
}
function isDigit(src){return (src>='0') && (src<='9')}

function isAllDigits(oSrc, args) {
   for (n = args.Value.length - 1; n >= 0; n--) {
        var cDigit = args.Value.charAt (n);
        if (! isDigit (cDigit)) {

            args.IsValid = false;
            return;
        }
    }
    args.IsValid = true;
}

//function TopTabOnMouseOver(sender, args){

//    //If the user moves out of the tab (unselect timer is started) and comes back in before 
//    //the timer expires, we need to clear the timer to stop the unselect() call
//    if(tabTimeOutID!=null){
//        clearTimeout(tabTimeOutID);
//        tabTimeOutID=null;
//     }
//    args.Tab.Select();
//}

function TopTabOnMouseOut(e){   
    
    //Find the element which the mouse is over   
    var destElement = e.relatedTarget || e.toElement;   
    
    //SL 21/08/2007
    if(tabTimeOutID!=null){
        clearTimeout(tabTimeOutID);
        tabTimeOutID=null;
     }
       
    //If that element is part of the tabstrip then exit (i.e. don't start the timer to unselect the tabstrip)
    while (destElement){   
        if (destElement.parentNode == ctl00_TabStripTopNav.DomElement){
            return;
        }
        destElement = destElement.parentNode;   
    }
   if(typeof(pageDefaultTab)!='undefined' && pageDefaultTab!='' && ctl00_TabStripTopNav.FindTabByText(pageDefaultTab)){
        tabTimeOutID = setTimeout("ctl00_TabStripTopNav.FindTabByText(pageDefaultTab).SelectParents();", 3000);

   }else if(typeof(ctl00_TopTabStrip)!='undefined' && ctl00_TopTabStrip.SelectedTab){
       tabTimeOutID = setTimeout("if(ctl00_TabStripTopNav.SelectedTab) ctl00_TabStripTopNav.SelectedTab.UnSelect();", 3000);  
       //tabTimeOutID = setTimeout("ctl00_TabStripTopNav.Tabs[0].Select();", 1000);
   }
   
} 

function TabStripBrowseTypeOnTabSelected(sender,eventArgs){
    createCookie('TabStripBrowseTypeIndex',eventArgs.Tab.Text,365)
}

// radWindow //
function PlayMedia(id,w,h){
   var oWnd =  window.radopen('/cms/PlayMedia.aspx?id='+id, 'media'+id);
   oWnd.SetWidth(w+50);
   oWnd.SetHeight(h+150);
   oWnd.Center();
   return false;
}

function PlayLPMedia(id, w, h) {
    var oWnd = window.radopen('/LandingPages/LPMediaPlayer.aspx?mid=' + id, 'media' + id);
    oWnd.SetWidth(w);
    oWnd.SetHeight(h);
    oWnd.Center();
    return false;
}  

function OnClientClose(radWindow){

    //var mPlayer = radWindow.Iframe.contentWindow.document.getElementsByTagName("OBJECT")[0]
      var mPlayer = radWindow.Iframe.contentWindow.document.MediaPlayer
      if(navigator.appName == 'Microsoft Internet Explorer' && mPlayer && mPlayer.id=="MediaPlayer")
          mPlayer.Stop();         // Windows media player needs to be stopped on IE otherwise IE crashes from a memory leak

    radWindow.Iframe.src=''; //clear any flash player inside popup window to stop it playing

}  
        
// COOKIES //
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


//QUERYSTRINGS
function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
        for(var i=0; i < this.q.split("&").length; i++) {
        this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; } 
}

//COOLSTUFF JUMP MENU
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function go(frameName,url) {
    parent.frameName.location.href = url;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// EDUCATION IMAGE ROLLOVERS

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// PRElOAD IMAGES
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// SL 15/10/2008 - clear search text
function clearDefault(el) {
    if (el.defaultValue==el.value) el.value = "";
}


//SL 7/12/2009 - Close browser Window 
function closeWindow() {
    //uncomment to open a new window and close this parent window without warning 
    //var newwin=window.open("popUp.htm",'popup',''); 
    if (navigator.appName == "Microsoft Internet Explorer") {
        this.focus(); self.opener = this; self.close();
    }
    else { window.open('', '_parent', ''); window.close(); }
} 
