// master.js

function openRemote(url,width,height,remote) 
{
	var properties = "scrollbars=no,resizable=no,top=0,left=0, innerWidth="+width+",innerHeight="+height+",width="+width+",height="+height;
	var remote = open(url, remote, properties);
	remote.opener.name = "myWindow";
}

function updateState(countryIdx, stateDd, stateDiv)
{
	var element = document.getElementById(stateDiv);
	cleanDropDown(stateDd);

	if (arCountries[countryIdx][2] < 0) {
		element.style.display = 'none';
	} else {
		element.style.display = '';
		popDropDown(stateDd,arStates[arCountries[countryIdx][2]]);
	}
	
		
}

function setDropDownDisplay(dd,id){
	var element = document.getElementById(id);
	if(dd.options.length==1){
		element.style.display = 'none';
	}else{
		element.style.display = '';
	}
}
// Form Functions
function popDropDown(dd,arList){
	cleanDropDown(dd);
	for( var i=0;i<arList.length;i++ ){
		dd.options[i] = new Option(arList[i][1], arList[i][0]);
	}
}

function setDropDown(dd,selValue){
	for(var i=0;i<dd.length;i++ ){
		if(selValue == dd.options[i].value) dd.options[i].selected=true;
	}
}

function cleanDropDown(dd){
	dd.selectedIndex = null;
	while( dd.length > 0 ){
		dd.options[0] = null;
	}
}

function hideElement(id)
{
	var element = document.getElementById("state");
	element.style.display = "none";
}
function showElement(id)
{
	var element = document.getElementById("state");
	element.style.display = "block";
}

/**
* dialog: dependant upon the browser type, opens a modal dialog or a centered window.
* arguments:
	1. url = dialog url
	2. width = dialog width
	3. height = dialog height
	4. returnVal = String name value of of the javascript variable for the return value
*/
function dialog(){
	var url = arguments[0];
	var width = arguments[1];
	var height = arguments[2];

	var returnVal = (String(arguments[3])!='undefined')?arguments[3]:'';

	if(typeof(window.showModalDialog)=='object'){
		/*
		* In IE 7 the XMLHttpRequest is a Native object, so use it to determine IE version
		*/
		if(typeof(XMLHttpRequest)!='object'){
			height = height + 50;
			width = width + 20;
		}
		var features = "center:1;dialogHeight:" + height + "px;dialogWidth:" + width + "px;scroll:0";
		if(returnVal != '')
			eval(returnVal + '=' + String(window.showModalDialog(url,'',features)));
		else
			window.showModalDialog(url,'',features);
	}else{
		var props = "width=" + width + ",height=" + height;
		if(typeof(screen.width)!='undefined'){
			props += ",top=" + ((screen.height-height)/2);
			props += ",left=" + ((screen.width-width)/2);
		}
		var win = window.open(url,'dialogWindow',props);
		if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	}
}

/**
* function newWindow()
* :launches supplied URL into a new window.
*/
function newWindow() {
	var url = arguments[0];
	var prop = (arguments.length > 1)?arguments[1]:"";

	window.open(url,'wdialog',prop);
}
function sendURL() {
	var url = arguments[0];
	var prop = (arguments.length > 1)?arugments[1]:"";

	window.open(url,'wdialog',prop);
}


// OMNITURE 
var s_pageName="";
var s_server="";
var s_channel="estore";
var s_pageType="";
var s_prop1="";
var s_prop2="";
var s_prop3="";
var s_prop4="";
var s_prop5="";
/* E-commerce Variables */
var s_campaign="";
var s_state="";
var s_zip="";
var s_events="";
var s_products="";
var s_purchaseID="";
var s_eVar1="";
var s_eVar2="";
var s_eVar3="";
var s_eVar4="";
var s_eVar5="";  

function omnitureSendClick(evnt, prod, func){
	var reportid = 'corelcom';
	s_events = evnt;
	s_products = prod;
	try{
		setTimeout("s_gs('" + reportid + "')",100);
		
		if(func!=null) eval(func);
	}catch(e){alert(e)}
}
			
function omniturePrice(price,currency){
	try{
		if(currency == "CAD"){
			return( moneyFormat(price * 0.728 ));
		}else if(currency == "EUR"){
			return( moneyFormat(price * 1.253 ));
		}else if(currency == "GBP"){
			return( moneyFormat(price * 1.85622 ));
		}else if(currency == "JPY"){
			return( moneyFormat(price * 0.008363 ));
		}else{
			return( price )
		}
	}catch(e){
		return(price);
	}
}
			
function moneyFormat(val){
	var tmp = new String(val);
	var indx = tmp.indexOf(".");
	if(indx != -1){
		if( tmp.length - indx > 3){
			tmp = tmp.substr(0,indx + 3)
		}else if( tmp.length - indx == 1){
			tmp += "0";
		}
	}else{
		tmp += ".00";
	}
	return tmp;
}

// COOKIE HANDLING FUNCTIONS

var cookieDomain = "";

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return null; 
			
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
			
function nukecookie(cookiename)
{
	var dt = new Date();
	document.cookie = cookiename + "=0;expires=" + dt.toGMTString() + ";" + ";";
	return;
}

function setcookie(name, value, expires, path, domain, secure)
{
	var cookieDomain = document.domain.substring(document.domain.indexOf("."),document.domain.length);
	
	document.cookie = name + "=" + escape(value) +
	        ((expires) ? "; expires=" + new Date(((new Date()).getTime() + expires*360)).toGMTString() : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "; domain=" + cookieDomain) +
	        ((secure) ? "; secure" : "");
}
	

//Set the campaign code if it exists within a cookie
if( getcookie("trkid") != null )
{
	if( getcookie( "trkid_" + getcookie("trkid") ) == null )
	{
		s_campaign = getcookie("trkid");
		setcookie("trkid_" + getcookie("trkid"),1,null,"/",null,null);
	}
}

if( getcookie("itrkid") != null )
{
	if( getcookie( "itrkid_" + getcookie("itrkid") ) == null )
	{
		s_eVar1 = getcookie("itrkid");
		setcookie("itrkid_" + getcookie("itrkid"),1,null,"/",null,null);
	}
}

//ensures that only numbers are entered.
function onlyNumbers(e)
{
	var keynum
	var keychar
	var numcheck

	if(window.event) // IE
	{
	keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which
	}
	keychar = String.fromCharCode(keynum)
	numcheck = /\d/
	return numcheck.test(keychar)
}
