var imageArray = new Array();
var COOKIE_WISH_LIST = "COOKIE_WISH_LIST";
var COOKIE_VOTE_LIST = "COOKIE_VOTE_LIST";

function preloadImages() {
	for (var i = 0; i < arguments.length; i++) {
		var tempImage = new Image();
		tempImage.src = arguments[i];
		imageArray.push(tempImage);
	}
}

function changeImage(elem, newSrc) {
	elem.src = newSrc;
}

function popupDialog(strUrl, w, h, scrollbars, x, y) {
	var windowName = "popupWindow";
	var newWindow = null;
	if (scrollbars) {
		if (scrollbars=='yes' || scrollbars=='true' || scrollbars=='1' || scrollbars==true || scrollbars==1) scrollbars=true;
		else scrollbars=false;
	} else {
		scrollbars = false;
	}
	var strOptions = "status=no,menubar=no,toolbar=no,location=no,";
	strOptions += scrollbars ? "scrollbars," : "";
	strOptions += w ? "width=" + w + "," : "width=500,";
	strOptions += h ? "height=" + h + "," : "height=400,";
	strOptions += x ? "left=" + x + ",": "";
	strOptions += y ? "top=" + y + ",": "";
	strOptions = strOptions.substring(0, strOptions.length - 1);
	
	newWindow = window.open(strUrl, windowName, strOptions);
	newWindow.focus();
	return newWindow;
}

// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.geocities.com/~yehuda/

// Boolean variable specified if alert should be displayed if cookie exceeds 4KB
var caution = false;

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie;
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
		
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix)
	
	if (cookieStartIndex == -1)
		return null;
		
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
		
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// date - any instance of the Date object
// * you should hand all instances of the Date object to this function for "repairs"
// * this function is taken from Chapter 14, "Time and Date in JavaScript", in "Learn Advanced JavaScript Programming"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

/* to detect flash */
var agt = navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var ns = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
	nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
	pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
/* end detect flash */

function hasflash() {
	return (pluginlist.indexOf("Flash")!=-1);
}

function getFlashString(sFlash, iWidth, iHeight, sId) {
	var s = "<object id=\"" + sId + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"" + iWidth + "\" height=\"" + iHeight + "\">";
	s += "<param name=\"movie\" value=\"" + sFlash + "\" />";
	s += "<param name=\"quality\" value=\"high\" />";
	s += "<embed src=\"" + sFlash + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + iWidth + "\" height=\"" + iHeight + "\" />";
	s += "</object>";
	
	return s;
}

function getImageString(sImage, iWidth, iHeight, sAlt, sUrl) {
	var s = "";
	if (sUrl != "") {
		s += "<a href=\"" + sUrl + "\">";
	}
	s += "<img src=\"" + sImage + "\" width=\"" + iWidth + "\" height=\"" + iHeight + "\" alt=\"" + sAlt + "\" />";
	if (sUrl != "") {
		s += "</a>";
	}
	
	return s;
}

function writeFlashObject(sFlash, sImage, sUrl, sAlt, iWidth, iHeight, sId) {
	var s = "";
	if (sFlash.toLowerCase().indexOf(".swf") > -1) {
		if (hasflash()) {
			s = getFlashString(sFlash, iWidth, iHeight, sId);
		} else {
			s = getImageString(sImage, iWidth, iHeight, sAlt, sUrl);
		}
	} else {
		var strImageFile = sFlash != "" ? sFlash : sImage;
		s = getImageString(strImageFile, iWidth, iHeight, sAlt, sUrl);
	}
	//document.write("<textarea cols='60' rows='20'>" + s + "</textarea>");
	document.write(s);
}

function showbagDetail(intID) {
	popupDialog("showbagdetails.aspx?sectionid=7&id=" + intID, 550, 590, true);
}

function addToWishList(intID) {
	var expDate = new Date();
	var oldValue = getCookie(COOKIE_WISH_LIST);
	var ids = new Array();
	expDate.setMonth(expDate.getMonth() + 12);
	
	
	if (oldValue == "" || oldValue == "null" || oldValue == null) {
		oldValue = "";
	} else {
		ids = oldValue.split(",");
	}
	
	for (var i = 0; i < ids.length; i++) {
		if (ids[i] == intID) {
			if (strDuplicateWishList != null) {
				alert(strDuplicateWishList);
			}
			return;
		}
	}
	
	ids.push(intID);
	
	
	setCookie(COOKIE_WISH_LIST, ids.join(","), expDate);
	if (strWishListAdded != null) {
		//alert("This showbag has been successfully added to your wish list.");
		alert(strWishListAdded);
	}
	//deleteCookie(COOKIE_WISH_LIST);
}

function deleteFavourites(objForm) {
	var fav = new Array();
	var expDate = new Date();
	var count = 0;
	expDate.setMonth(expDate.getMonth() + 12);
	
	if (objForm.chkFavourites.length) {
		for (var i = 0; i < objForm.chkFavourites.length; i++) {
			if (!objForm.chkFavourites[i].checked) {
				fav.push(objForm.chkFavourites[i].value);
			} else {
				count++;
			}
		}
	} else {
		if (!objForm.chkFavourites.checked) {
			fav.push(objForm.chkFavourites.value)
		} else {
			count++;
		}
	}
	
	if (count != 0) {
		setCookie(COOKIE_WISH_LIST, fav.join(","), expDate);
		location.reload(true);
	}
}

function displayHighlight(isHighlight) {
	var strHighlight = isHighlight ? "block" : "none";
	var strFull = isHighlight ? "none" : "block";
	var i = 1;
	var elemHighlight = document.getElementById("eventDetails" + i + "_highlight");
	var elemFull = document.getElementById("eventDetails" + i + "_full");
	
	while (elemHighlight && elemFull) {
		elemHighlight.style.display = strHighlight;
		elemFull.style.display = strFull;
		i++;
		elemHighlight = document.getElementById("eventDetails" + i + "_highlight");
		elemFull = document.getElementById("eventDetails" + i + "_full");
	}
}

function processVoteShowBag(e) {
	if (!e) e = window.event;
	var objSource = (e.srcElement) ? e.srcElement : e.target;
	var theForm = objSource.form;
	var retVal = false;
	if (!isShowBagVoted(theForm.voteShowBagId.value)) {
		retVal = true;
		//theForm.submit();
	}
	return retVal;
}

function isShowBagVoted(strValue) {
	var retVal = false;
	var expDate = new Date();
	var oldValue = getCookie(COOKIE_VOTE_LIST);
	var ids = new Array();
	expDate.setMonth(expDate.getDay() + 1);
	
	if (oldValue == "" || oldValue == "null" || oldValue == null) {
		oldValue = "";
	} else {
		ids = oldValue.split(",");
	}
	
	for (var i = 0; i < ids.length; i++) {
		if (ids[i] == strValue) {
			if (strDuplicateWishList != null) { alert(strDuplicateVote); }
			retVal = true;
			break;
		}
	}
	
	if (!retVal) {
		ids.push(strValue);
		setCookie(COOKIE_VOTE_LIST, ids.join(","), expDate);
	}
	return retVal;
}

function paginationGoto(pagenum) {
	document.frmResubmit.pagenumber.value = pagenum;
	document.frmResubmit.submit();
}