var popup_displayed=0;
var mDivMOver=false;document.onclick=function(){if (popup_displayed==1) {popup_displayed=0;}else{if(document.getElementById("divpopup") != null){if (mDivMOver == false) {popup_close();}}}}

function producttypechange() {

  var pt=document.getElementById("ddlProductType").options[document.getElementById("ddlProductType").selectedIndex].value;	
  var h='';




  var sa=document.getElementById("styledata").value.split('||');
  var si=new Array();


  h='<select name="ddlStyle" id="ddlStyle" onchange="styletypechange();">';

  for ( i = 0; i < sa.length; i++ ) {

    si=sa[i].split('|');

    if (si[2]==pt) {

	h+='<option value="'+ si[0] + '"';
 	//if (selected == ia[1]) {h+=' selected';}
	h+='>'+ si[1] + '</option>';

    }

  }

 h+='</select>';

 document.getElementById("divProductStyle").innerHTML=h;



 styletypechange();	

}


function openBrWindow(theURL,winName,features) { 

	window.open(theURL,winName,features);
} 


function styletypechange() {


  var st=document.getElementById("ddlStyle").options[document.getElementById("ddlStyle").selectedIndex].value;	
  var h='';


  var ca=document.getElementById("colourdata").value.split('||');
  var ci=new Array();


  h='<select name="ddlColour" id="ddlColour">';

  for ( i = 0; i < ca.length; i++ ) {

    ci=ca[i].split('|');

    if (ci[2]==st) {

	h+='<option value="'+ ci[0] + '"';
 	//if (selected == ia[1]) {h+=' selected';}
	h+='>'+ ci[1] + '</option>';

    }

  }

 h+='</select>';


document.getElementById("divProductColour").innerHTML=h;
}


function confirmRemoveFI(intItemID, strItem){
    if (confirm("Do want to remove the item '" + strItem + "' from your favouristes list?\n\nClick 'OK' to remove or 'Cancel' to abort!")){
        document.Form1.delItemID.value = intItemID;
        document.Form1.submit();
    }
}


function updateQty(pid){
    document.Form1.updItemID.value = pid;
    document.Form1.submit();
}

function popUp(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
	var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
	var int_windowTop = (screen.height - a_int_windowHeight) / 2;
	var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable;
	var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
	if (parseInt(navigator.appVersion) >= 4) {
		obj_window.window.focus();
	}
}

function selectPostageZone(countryCode){
    var objForm = document.Form1;
    if (objForm){
        var objCountryCode = objForm.deliveryCountry;
        if (objCountryCode){
            objCountryCode.value = countryCode;
            objForm.submit();
        }
    }
}

var currentPostageZone = '';



//------------------------------------------------------------------------------------------
// Cal
//------------------------------------------------------------------------------------------


var yn = new Array(1930,1931,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030);
var na = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,'01','02','03','04','05','06','07','08','09');
var ml = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var sday;
var smonth;
var syear;
var sc;
var txtname;
var dn=0;

// Date Format:  1. dd/MM/yyyy  2. MM/dd/yyyy  3. yyyy-MM-dd
var dateformat=1;

//var mDivMOver=false;document.onclick=function() {if(document.getElementById("caldiv") != null){ if (mDivMOver == false) {dn++;if (dn > 1){document.getElementById("caldiv").style.visibility='hidden';document.getElementById('calshim').style.visibility='hidden';}}}}

function isdate(day, month, year)
{
var nastr=na.join(",")+',';
var ynstr=yn.join(",")+',';

if (nastr.indexOf(day + ',') == -1)
return false;

if (nastr.indexOf(month + ',') == -1)
return false;

if (ynstr.indexOf(year + ',') == -1)
return false;

if (month < 1 || month > 12)
return false;

if (year/4 == parseInt(year/4))
{
ml[1] = 29;
}
else
{
ml[1] = 28;
}

if (day < 1 || day > ml[month-1])
return false;

return true;
}


function calgo(name,thedate,format)
{
    txtname=name;

    if (format==1 || format==2 || format==3)
    {
        dateformat=format;
    }

    popup_position(txtname,164,184)

    var correctdate=false;

    sc='-';

    if (thedate.indexOf("/") != -1)
    {
        sc='/';
    }

    var checkdate=thedate.split(sc);

    if (checkdate.length == 3)
    {
        var cdday;
        var cdmonth;
        var cdyear;

        if (dateformat == 1)
        {
            cdday=checkdate[0];
            cdmonth=checkdate[1];
            cdyear=checkdate[2];
        }
        else if (dateformat == 2)
        {
            cdday=checkdate[1];
            cdmonth=checkdate[0];
            cdyear=checkdate[2];
        }
        else if (dateformat == 3)
        {
            cdday=checkdate[2];
            cdmonth=checkdate[1];
            cdyear=checkdate[0];
        }

        if (isdate(cdday,cdmonth,cdyear) == true)
        {
            correctdate=true;
        }
    }


    if (correctdate == true)
    {
        sday=cdday;
        smonth=cdmonth;
        syear=cdyear;
    
        calendar(sday,smonth,syear);
    }
    else
    {
        var d=new Date()
        sday=d.getDate();
        smonth=d.getMonth()+1;
        syear=d.getFullYear();
        calendar(sday,smonth,syear);
    }

    if (format==3)
    {
        sc='-'
    }
    else
    {
        sc='-'
    }
}

function caldown(day, month, year)
{
    month=month-1;

    if (month == 0)
    {
        month=12;
        year=year-1;
    }

    if (year < yn[0])
    {
        month=1;
        year=yn[0];
    }

    calendar(day, month, year);
}

function calup(day, month, year)
{
    month=month+1;

    if (month == 13)
    {
        month=1;
        year=year+1;
    }

    if (year > yn[yn.length-1])
    {
        month=12;
        year=yn[yn.length-1];
    }

    calendar(day, month, year);
}


function calmonth(day, month, year)
{
    calendar(day, month, year);
}

function calyear(day, month, year)
{
    calendar(day, month, year);
}

function calout(day, month, year)
{
    var thedate;

    if (day.toString().length==1)
    {
        day='0'+day;
    }

    if (month.toString().length==1)
    {
        month='0'+month;
    }

    if (dateformat == 1)
    {
        thedate=day + '/' + month + '/' + year;
    }
    else if (dateformat == 2)
    {
        thedate=month + '/' + day + '/' + year;
    }
    else if (dateformat == 3)
    {
        thedate=year + '-' + month + '-' + day;
    }

    document.getElementById(txtname).value=thedate;
    popup_close()
}

function calendar(day, month, year)
{
    dn=0;
    var monthnumber = new Array(1,2,3,4,5,6,7,8,9,10,11,12);
    var monthname = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
    var h;
    var DayLoop=0;
    var WeekLoop=0;
    var font='Arial';
    var pday='';
    var pmonth;
    var pyear;
    var ShadeColor='#edf5fe';
    var DayBackColor='#ffffff';
    var DayBorderColor='#eaeaea';
    var BorderColor='#294985';
    var DayHeadingBackColor='#294985';
    var DayBackColor='#ffffff';
    var SelectDayBackColor='#e1e1e1';
    var HoverDayBackColor='#9abce7';
    var DayStyle='style="font-family:' + font + ';font-size:8pt;font-weight:bold;color:#ffffff"';
    var LinkStyle='style="font-family:' + font + ';font-size:8pt;font-weight:normal;color:#294985"';
    var AlternateMonth='style="font-family:' + font + ';font-size:8pt;font-weight:normal;color:#666666"';
    var ArrowStyle='style="font-family:' + font + ';font-size:8pt;font-weight:bold;color:#294985"';
    var HeadingCellAttributes='width="14%" style="border-right-width:0px;border-left-width:0px;color:#ffffff;"'

    h='<table border=1 cellpadding=0 cellspacing=0 bordercolor=' + BorderColor +' style="border-collapse:collapse"><tr><td>'
    h+='<table border=1 width=180 cellspacing=0 bordercolor=' + DayBorderColor +' style="border-collapse:collapse">';
    h+='<tr bgcolor=' + ShadeColor + '><td colspan="7"><table border=0 cellpadding=1 cellspacing=1 width="100%"><tr>';
    h+='<td width="10%" onclick="caldown(1,' + month + ',' + year + ')" style="cursor:hand" ' + ArrowStyle + '>&lt;&lt;</a></td>';
    h+='<td align=center width="80%">';
    h+='<table border=0 cellpadding=0 cellspacing=0>';
    h+='<tr>';

    h+='<td><select name=ddlmonth style="font-size:8pt;" onchange="calmonth(' + day + ',this.options[this.selectedIndex].value, ' + year + ');">'

    for (var a = 0; a < monthnumber.length; a++)
    {
        h+='<option value=' + monthnumber[a]
        if (month == monthnumber[a])
        {
            h+=' selected=selected';
        }
        h+='>' + monthname[a] + '</option>';
    }

    h+='</select></td>'
    h+='<td>&nbsp;</td>';
    h+='<td><select name=ddlyear style="font-size:8pt;" onchange="calyear(' + day + ',' + month + ',this.options[this.selectedIndex].value);">'

    for (var a = 0; a < yn.length; a++)
    {
        h+='<option value=' + yn[a]
        if (year == yn[a])
        {
            h+=' selected=selected';
        }

        h+='>' + yn[a] + '</option>';
    }

    h+='</select></td>'
    h+='</tr>';
    h+='</table>';
    h+='</td>';
    h+='<td align=right width="10%" onclick="calup(1,' + month + ',' + year + ')" style="cursor:pointer" ' + ArrowStyle + '>&gt;&gt;</a></td>';
    h+='</tr></table></td></tr>'
    h+='<tr align=center bgcolor=' + DayHeadingBackColor + ' ' + DayStyle + '>';
    h+='<td ' + HeadingCellAttributes + '>Sun</td>';
    h+='<td ' + HeadingCellAttributes + '>Mon</td>';
    h+='<td ' + HeadingCellAttributes + '>Tue</td>';
    h+='<td ' + HeadingCellAttributes + '>Wed</td>';
    h+='<td ' + HeadingCellAttributes + '>Thu</td>';
    h+='<td ' + HeadingCellAttributes + '>Fri</td>';
    h+='<td ' + HeadingCellAttributes + '>Sat</td>';
    h+='</tr>';

    for(CellLoop=0; ;CellLoop++)
    {
        DayLoop++;
        WeekLoop++;

        if (isdate(DayLoop, month, year) == false)
        {
            break;
        }

        var TheDate=new Date(year, month-1, DayLoop);

        if (WeekLoop == 1)
        {
            h+='<tr>'
        }

        if (CellLoop < TheDate.getDay())
        {
            if (pday=='')
            {
                pmonth=month-1;
                pyear=year;

                if (pmonth == 0)
                {
                    pmonth=12;
                    pyear=year-1;
                }

                if (pyear/4 == parseInt(pyear/4))
                {
                    ml[1] = 29;
                }
                else
                {
                    ml[1] = 28;
                }

                pday=ml[pmonth-1]-TheDate.getDay()-CellLoop+1;
            }
            else
            {
                pday++;
            }

            h+='<td onclick="calout(' + pday + ',' + pmonth + ',' + pyear + ')" style="cursor:pointer" width="14%" bgcolor=' + ShadeColor + ' onmouseover="this.style.background=\'' + HoverDayBackColor + '\'" onmouseout="this.style.background=\'' + ShadeColor + '\'"><table border=0 cellpadding=1 cellspacing=0 width="100%"><tr><td align=right ' + AlternateMonth + '>' + pday + '</td></tr></table></td>';
            DayLoop=0;
        }
        else
        {
            h+='<td onclick="calout(' + DayLoop + ',' + month + ',' + year + ')" width="14%" style="cursor:hand" valign=top'

            if (sday==DayLoop && smonth==month && syear==year)
            {
                h+=' bgcolor="' + SelectDayBackColor + '" onmouseover="this.style.background=\'' + HoverDayBackColor + '\'" onmouseout="this.style.background=\'' + SelectDayBackColor + '\'">';
            }
            else
            {
                h+=' bgcolor="' + DayBackColor + '" onmouseover="this.style.background=\'' + HoverDayBackColor + '\'" onmouseout="this.style.background=\'' + DayBackColor + '\'">';
            }

            h+='<table border=0 cellpadding=1 cellspacing=0 width="100%"><tr><td align=right ' + LinkStyle + '>' + DayLoop + '</td></tr></table></td>';
        }

        if (WeekLoop == 7)
        {
            h+='</tr>';
            WeekLoop=0;
        }
    }

    var CellFill=TheDate.getDay()

    if (CellFill != 7)
    {
        var nmd=0;
        month++;
        if (month == 13)
        {
            month=1;
            year++;
        }

        for (i = CellFill+2; i <= 7; i++)
        {
            nmd++;
            h+='<td onclick="calout(' + nmd + ',' + month + ',' + year + ')" style="cursor:pointer" width="14%" bgcolor=' + ShadeColor + ' onmouseover="this.style.background=\'' + HoverDayBackColor + '\'" onmouseout="this.style.background=\'' + ShadeColor + '\'"><table border=0 cellpadding=1 cellspacing=0 width="100%"><tr><td align=right ' + AlternateMonth + '>' + nmd + '</td></tr></table></td>';
        }
        h+='</tr>';
    }

    h+='</table>';
    h+='</td></tr></table>';

    popup_show(h) 
}

function calmultiple(){	if (document.getElementById("datediv").style.visibility == 'visible')	{		document.getElementById("datediv").style.visibility = 'hidden';		document.getElementById("txtDate2").value = '';		document.getElementById("dateimage").src='images/datetype_multiple.gif';		document.getElementById("datediv").style.width='1px';	}	else	{		document.getElementById("datediv").style.visibility = 'visible';		document.getElementById("txtDate2").value = document.getElementById("dd").value;		document.getElementById("dateimage").src='images/datetype_single.gif';		document.getElementById("datediv").style.width=130;	}}
function popup_position(txtname, height, width) {

	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		document.getElementById("divpopup").setAttribute('onmouseover',function anonymous(){mDivMOver=true});
		document.getElementById("divpopup").setAttribute('onmouseout',function anonymous(){mDivMOver=false});
	}
		else
	{
		document.getElementById("divpopup").setAttribute('onMouseOver','mDivMOver=true');
		document.getElementById("divpopup").setAttribute('onMouseout','mDivMOver=false');
	}

	var popupleft=0;
	var popuptop=0;

 	objParent=document.getElementById(txtname).offsetParent;
         
    while(objParent && objParent.tagName.toUpperCase() != "BODY")
    {
        popupleft+=objParent.offsetLeft;
        popuptop+=objParent.offsetTop;
        objParent=objParent.offsetParent;
    }

	popupleft+=document.getElementById(txtname).offsetLeft
	popuptop+=document.getElementById(txtname).offsetTop + document.getElementById(txtname).offsetHeight + 2;


	if (popuptop+height > document.body.clientHeight)
	{
		popuptop=document.body.clientHeight-height;
	}

	if (popupleft+width > document.body.clientWidth)
	{
		popupleft=document.body.clientWidth-width;
	}

	document.getElementById("divpopup").style.left=popupleft+'px';
	document.getElementById("divpopup").style.top=popuptop+'px';

	popup_displayed=1;
}



function popup_show(html) {
	document.getElementById("divpopup").innerHTML=html;
	document.getElementById("divpopup").style.visibility='visible';	var IfrRef=document.getElementById('shimpopup');	IfrRef.style.width=document.getElementById("divpopup").offsetWidth;	IfrRef.style.height=document.getElementById("divpopup").offsetHeight;	IfrRef.style.top=document.getElementById("divpopup").style.top;	IfrRef.style.left=document.getElementById("divpopup").style.left;	IfrRef.style.zIndex=document.getElementById("divpopup").style.zIndex-1;	IfrRef.style.display="block";	IfrRef.style.visibility='visible';
}



function popup_close()
{
	document.getElementById("divpopup").style.visibility='hidden';
	document.getElementById('shimpopup').style.visibility='hidden';
}
