window.onMouseMove = mouser;
window.onLoad = PreloadIMG;
function PreloadIMG(){MM_preloadImages("images/but_home2.png","images/but_quicklinks2.png","images/but_shopping2.png","images/but_giftreg2.png","images/but_mail2.png","images/but_vouchers2.png","images/but_contact2.png","images/howtopurchase2.png","images/loading_small.gif","images/loading.gif","images/popdivsframe/bottom.png","images/popdivsframe/bottomleft.png","images/popdivsframe/bottomright.png","images/popdivsframe/left.png","images/popdivsframe/right.png","images/popdivsframe/top.png","images/popdivsframe/topleft.png","images/popdivsframe/topright.png");}
function MM_swapImgRestore() {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() {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) {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); return x;}
function MM_swapImage() {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];}}

function GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}

var xmlhttp_ChkTru;
function ChkTru(str,strid){if (str.length == 0){document.getElementById("txtChkTru").value = "";return;}xmlhttp_ChkTru = GetXmlHttpObject();if (xmlhttp_ChkTru == null){alert ("Your browser does not support XMLHTTP!");return;}var url = "LITVI_chktru.asp";url = url + "?ref=" + str;url = url + "&id="+strid;xmlhttp_ChkTru.onreadystatechange = stateChanged_chktru;xmlhttp_ChkTru.open("GET",url,true);xmlhttp_ChkTru.send(null);}
function stateChanged_chktru(){if (xmlhttp_ChkTru.readyState == 4){document.getElementById("txtChkTru").value = xmlhttp_ChkTru.responseText;}}

var xmlhttp_GetCities;
function GetCities(prov){if (prov.length == 0){document.getElementById("RegionDD").innerHTML = "<select name='city'><option value=''>*Please Select</option></select>";return;}xmlhttp_GetCities = GetXmlHttpObject();if (xmlhttp_GetCities == null){alert ("Your browser does not support XMLHTTP!");return;}var url = "GetCities.asp";url = url + "?prov="+prov;xmlhttp_GetCities.onreadystatechange = stateChanged_getcities;xmlhttp_GetCities.open("GET",url,true);xmlhttp_GetCities.send(null);}
function stateChanged_getcities(){if (xmlhttp_GetCities.readyState == 1){document.getElementById("RegionDD").innerHTML = "<select name=\"city\"><option value=\"\">Loading...</option></select>";}if (xmlhttp_GetCities.readyState == 4){document.getElementById("RegionDD").innerHTML = xmlhttp_GetCities.responseText;}}

var xmlhttp_divpopup;
function divpopup(themethod,theurl,atclicksend){if(atclicksend){MoveDivToClick("PopDiv");}if (themethod.length == 0 || theurl.length == 0){document.getElementById("PopDiv").innerHTML = "";document.getElementById("PopDiv").style.display = "none";return;}xmlhttp_divpopup = GetXmlHttpObject();if (xmlhttp_divpopup == null){alert ("Your browser does not support XMLHTTP!");return;}xmlhttp_divpopup.onreadystatechange = stateChanged_divpopup;xmlhttp_divpopup.open(themethod,theurl,true);xmlhttp_divpopup.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xmlhttp_divpopup.send(theurl);}
function stateChanged_divpopup(){if (xmlhttp_divpopup.readyState == 1){dispload("PopDiv");}if (xmlhttp_divpopup.readyState == 4){document.getElementById("PopDiv").style.display = "block";document.getElementById("PopDiv").innerHTML = xmlhttp_divpopup.responseText;}}

function myUnpack(id){var prodid = id;PopWindow("unpack.asp?id=" + prodid,"UNPACK","500px","600px","0px","0px");}
function mymailUnpack(id){var prodid = id;PopWindow("mailunpack.asp?id=" + prodid,"UNPACK","500px","600px","0px","0px");}
function PopWindow(url,name,h,w,left,top) {var optiontxt;optiontxt = "height=" + h + ",width=" + w + ",left=" + left + ",top=" + top + ",status=0,location=0,scrollbars=1,toolbar=0,resizable=1";window.open(url,name,optiontxt);}

var loadingpic = "";
loadingpic += "<table style=\"background-color: #f3f3f3; border: solid 1px #cccccc; width: 150px; height: 100px;\" ";
loadingpic += "cellpadding=\"5\" cellspacing=\"0\" border=\"0\">";
loadingpic += "<tr><td style=\"text-align: center; vertical-align: middle;\">";
loadingpic += "<center><img src=\"images/loading.gif\" alt=\"Loading...\" title=\"Loading...\" /><br/><b>LOADING...</b></center>";
loadingpic += "</td></tr>";
loadingpic += "</table>";
var posx;var posy;var DivX = 100;var DivY = 100;var xmlhttp;var DivClkLft;var DivClkRgt;var moveX;var moveY;
function mouser(event){posx = event.clientX;posy = event.clientY;}
function dispload(divID){document.getElementById(divID).style.display = "block";document.getElementById(divID).innerHTML = loadingpic;}
function GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}
function MoveDivToClick(divID){if (!posx){posx = 100;}if (!posy){posy = 100;}moveX = posx;moveY = posy;DivX = posx;DivY = posy;document.getElementById(divID).style.left = DivX + "px";document.getElementById(divID).style.top = DivY + "px";}
function MoveDiv(divID){dsblSlct(document.body);DivClkLft = posx - DivX;DivClkRgt = posy - DivY;document.onmousemove = MovemyDiv;function MovemyDiv(){moveX = posx - DivClkLft;moveY = posy - DivClkRgt;DivX = moveX;DivY = moveY;document.getElementById(divID).style.left = moveX + "px";document.getElementById(divID).style.top = moveY + "px";}}
function StopDiv(divID){enblSlct(document.body);document.onmousemove = StopmyDiv;function StopmyDiv(){if (moveX != null && moveY != null){if (document.getElementById(divID).style.visibility != 'hidden'){DivX = moveX;DivY = moveY;} else {DivX = DivX;DivY = DivY;}document.getElementById(divID).style.left = moveX + "px";document.getElementById(divID).style.top = moveY + "px";}}}
function ClosePopDiv(){document.getElementById("PopDiv").innerHTML = "";document.getElementById("PopDiv").style.display = "none";}
function dsblSlct(trgt){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return false};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moznone");document.getElementById("PopDiv").setAttribute("class","PopDivNotSelect");}else{trgt.onmousedown=function(){return false};trgt.style.cursor = "default";}}
function enblSlct(trgt){if (typeof trgt.onselectstart!="undefined"){trgt.onselectstart=function(){return true};}else if (typeof trgt.style.MozUserSelect!="undefined"){trgt.setAttribute("class","moztext");document.getElementById("PopDiv").setAttribute("class","PopDiv");}else{trgt.onmousedown=function(){return true};trgt.style.cursor = "select";}}

function myresize(img,mywidth,myheight){document.getElementById(img).style.width = mywidth+"px";document.getElementById(img).style.height = myheight+"px";}

function slideSwitch(slideshow) {var $active = $(slideshow + ' DIV.active');if ( $active.length == 0 ) $active = $(slideshow + ' DIV:last');
/* to pull the divs in the order they appear in the markup > */
var $next =  $active.next().length ? $active.next() : $(slideshow + ' DIV:first');
/* to pull the divs randomly > */
//var $sibs  = $active.siblings();var rndNum = Math.floor(Math.random() * $sibs.length );var $next  = $( $sibs[ rndNum ] );
$active.addClass('last-active');$next.css({opacity: 0.0}) .addClass('active') .animate({opacity: 1.0}, 1000, function() {$active.removeClass('active last-active');});}

function checkContact(form)
{
    var name = form.name;
    var tel = form.tel;
    var email = form.email;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    
	if (name.value == "")
    {
        alert('Please enter your name in the space provided.');
        name.focus();
        return false;
    }
    if (tel.value == "")
    {
        alert('Please enter your contact tel number in the space provided.');
        tel.focus();
        return false;
    }
    if (email.value == "")
    {
        alert('Please enter your email address in the space provided.');
        email.focus();
        return false;
    }
    if(!email.value.match(emailRegex)) {
        alert('The email address entered was not valid. Please re-enter your email address.');
        email.focus();
        return false;
    }
	
	return true;
}

function CkeckKeyword(form)
{
    var keyword = form.keyword;
    
    if (keyword.value == "")
    {
        keyword.focus();
        return false;
    }
    if (keyword.value.length < 3)
    {
        alert('Keyword must be atleast 3 characters');
        keyword.focus();
        return false;
    }
    
    return true;
}

function CheckReg(form)
{
    var myname = form.myname;
    var mysname = form.mysname;
    var cell = form.cell;
    var email = form.email;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    var province = form.province;
    var city = form.city;
    var add = form.add;
    var giftmes = form.giftmes;
    
    if (myname.value == "")
    {
        alert('Please enter your name.');
        myname.focus();
        return false;
    }
    if (mysname.value == "")
    {
        alert('Please enter your surname.');
        mysname.focus();
        return false;
    }
    if (cell.value == "")
    {
        alert('Please enter your cell number.');
        cell.focus();
        return false;
    }
    if (email.value == "")
    {
        alert('Please enter your email address.');
        email.focus();
        return false;
    }
    if(!email.value.match(emailRegex)) {
        alert('You have entered an invalid email address.');
        email.focus();
        return false;
    }
    if (province.value == "")
    {
        alert('Please select a province.');
        province.focus();
        return false;
    }
    if (city.value == "")
    {
        alert('Please select a city.');
        city.focus();
        return false;
    }
    if (add.value == "")
    {
        alert('Please enter the delivery address.');
        add.focus();
        return false;
    }
    if (giftmes.value == "")
    {
        alert('Please specify which message needs to accompany which product.');
        giftmes.focus();
        return false;
    }
    
    if (document.getElementById('cd').value.length == 0)
    {
        document.getElementById('place').style.display = 'none';
        document.getElementById('empty').style.display = 'block';
        document.getElementById('incorrect').style.display = 'none';
        return false;
    }else{
        document.getElementById('place').style.display = 'block';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'none';
    }
    
    if (document.getElementById('cd').value != document.getElementById('txtChkTru').value)
    {
        document.getElementById('place').style.display = 'none';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'block';
        return false;
    }else{
        document.getElementById('place').style.display = 'block';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'none';
    }
    
    return true;
}

function CheckVoucher(form)
{
    var fromname = form.fromname;
    var frommail = form.frommail;
    var toname = form.toname;
    var tomail = form.tomail;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    
    if (fromname.value == "")
    {
        fromname.focus();
        return false;
    }
    if (frommail.value == "")
    {
        frommail.focus();
        return false;
    }
    if(!frommail.value.match(emailRegex)) {
        alert('Invalid Email Address.');
        frommail.focus();
        return false;
    }
    
    if (toname.value == "")
    {
        toname.focus();
        return false;
    }
    if (tomail.value == "")
    {
        tomail.focus();
        return false;
    }
    if(!tomail.value.match(emailRegex)) {
        alert('Invalid Email Address.');
        tomail.focus();
        return false;
    }
    
    if (document.getElementById('cd').value.length == 0)
    {
        document.getElementById('place').style.display = 'none';
        document.getElementById('empty').style.display = 'block';
        document.getElementById('incorrect').style.display = 'none';
        return false;
    }else{
        document.getElementById('place').style.display = 'block';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'none';
    }
    
    if (document.getElementById('cd').value != document.getElementById('txtChkTru').value)
    {
        document.getElementById('place').style.display = 'none';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'block';
        return false;
    }else{
        document.getElementById('place').style.display = 'block';
        document.getElementById('empty').style.display = 'none';
        document.getElementById('incorrect').style.display = 'none';
    }
    
    return true;
}

function traceChecked(chk,id,qty,price)
{
    var qtybox = document.getElementById("qtybox" + id);
    if (document.getElementById(chk).checked == true){
    var mydd = "";
    mydd += "<select name=\"qty" + id + "\" id=\"qty" + id + "\">";
    for (i=1;i<=qty;i++)
    {
        if (i == qty){
        mydd += "<option value=\"" + i + "\" selected=\"selected\">" + i + "</option>";
        } else {
        mydd += "<option value=\"" + i + "\">" + i + "</option>";
        }
    }
    mydd += "</select>";
    qtybox.innerHTML = mydd;
    }
    if (document.getElementById(chk).checked == false){qtybox.innerHTML = qty;}
}

function mtraceChecked(chk,id,qty,price)
{
    var mqtybox = document.getElementById("mqtybox" + id);
    if (document.getElementById(chk).checked == true){
    var mydd = "";
    mydd += "<select name=\"mqty" + id + "\" id=\"mqty" + id + "\">";
    for (i=1;i<=qty;i++)
    {
        if (i == qty){
        mydd += "<option value=\"" + i + "\" selected=\"selected\">" + i + "</option>";
        } else {
        mydd += "<option value=\"" + i + "\">" + i + "</option>";
        }
    }
    mydd += "</select>";
    mqtybox.innerHTML = mydd;
    }
    if (document.getElementById(chk).checked == false){mqtybox.innerHTML = qty;}
}