﻿// OPEN VIDEO
function openvideowin(code, rootURL) {
    var Wname = "popped";
    var exec = 'window.open("';
    var URL   = rootURL+"Video.aspx?code="+code;
    exec+= URL;      exec+= '", "';
    exec+= Wname;    exec+= '", "';
    exec+='width=400,height=400';
    exec+=',top=0,left=0,screenX=0,screenY=0,toolbar=0,location=0';
    exec+=',directories=0,resizable=0,status=0,menubar=0,scrollbars=0")';
    eval (exec);
}

//FIX FOR BUG IN SOME IE
function cancelEvent()
{
// ie only hack
if (window.event) window.event.cancelBubble = true;
// everyone else
return false;
}

// HELP 
function displayHelp(rootURL) {
	window.open(rootURL+"help.htm", "HELP", "height=600,width=900,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

// PRINT ORDER
function printOrder() {
	window.open("order-print.htm", "PRINTORDER", "height=500,width=600,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");	
}

// PRINT MAP
function printMap() {
	window.open("http://maps.google.com.au/maps?f=q&hl=en&geocode=&q=4+distribution+ave+ashmore&sll=-27.976628,153.362296&sspn=0.004501,0.009989&ie=UTF8&ll=-27.97695,153.359249&spn=0.009001,0.019977&z=16&iwloc=addr&pw=2", "PRINTMAP", "height=600,width=800,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");	
}

// CLEAR & FOCUS
function clearAndFocusIfNotSet(itemId, compValue) {
    if (document.getElementById(itemId).value == compValue) {
        document.getElementById(itemId).value = ''; 
        document.getElementById(itemId).focus();
    }
}

/* SET VALUE */
function setFieldValueIfBlank(itemId, newValue) {
    if (document.getElementById(itemId).value == '') {
        document.getElementById(itemId).value = newValue;
    }
}

//CLICKS THE ADD BUTTON AND REDIRECTS
function UpdateCartGoTo(redirectURL) {
    redirect = document.getElementById('ctl00_cphContent_hdnRedirectURL');
	if (!redirect) {
	    window.location = redirectURL;	    
	} else {
	    redirect.value = redirectURL;
	    document.getElementById('ctl00_cphContent_hdnAddButton').click();
	}	
}

//CLICKS THE ADD BUTTON
function UpdateCart() {
    redirectBtn = document.getElementById('ctl00_cphContent_hdnAddButton');
	if (redirectBtn) {
	    document.getElementById('ctl00_cphContent_hdnAddButton').click();
	}
}

//OPEN URLS IN NEW WINDOW
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
     anchor.target = "_blank";
   }
   if (anchor.getAttribute("rel") == "emaillink") {
        realAddress = anchor.innerHTML.replace("[at]", "@"); 
        anchor.innerHTML = realAddress;  
        anchor.setAttribute("href", "mailto:" + realAddress);  
   }
 }
}
window.onload = externalLinks;