function addRemoveMyList(objCheckBox, famId){	
	formElement = document.getElementById(objCheckBox);
	formElement.checked ? addToMyList(formElement.value, famId): removeFromMyList(formElement.value, famId);
}

function checkLink(objCheckBox, famId){	
	formElement = document.getElementById(objCheckBox);
	formElement.checked ? formElement.checked=false: formElement.checked=true;
	formElement.checked ? addToMyList(formElement.value, famId): removeFromMyList(formElement.value, famId);
}



function addToMyList(checkBoxValue, famId)
{	
	var i = 0;
	var strNewCookie = "";
	var cookieName = "myList";
	//alert(cookieName);
	var strCurrentCookie = getcookie(cookieName);

	strCurrentCookie=strCurrentCookie.replace(';','');
	var aCurCookiesInfo = strCurrentCookie.split(",");
	while(i < aCurCookiesInfo.length) {
			if (aCurCookiesInfo[i] != checkBoxValue) {
				if (aCurCookiesInfo[i].length > 0) {
					strNewCookie += aCurCookiesInfo[i] + ",";
				}
			}
			i++;
		}
		strNewCookie += checkBoxValue;
		document.cookie = cookieName+"="+strNewCookie+"; expires=Tue, 3 Aug 2010 20:47:11 UTC; path=/";
}

function removeFromMyList(checkBoxValue, famId)
{	
	var i = 0;
	var strNewCookie = "";
	var cookieName = "myList";
	var strCurrentCookie = getcookie(cookieName);
	if (strCurrentCookie.match(','+checkBoxValue)){
			strNewCookie = strCurrentCookie.replace(','+checkBoxValue,"");
		} else if (strCurrentCookie.match(checkBoxValue+',')) {
			strNewCookie = strCurrentCookie.replace(checkBoxValue + ',',"");
		}
         else if (strCurrentCookie.match(checkBoxValue)) {
			strNewCookie = strCurrentCookie.replace(checkBoxValue,"");
		
		}else {
		strNewCookie= strCurrentCookie;
		}
	document.cookie = cookieName+"="+strNewCookie+"; expires=Tue, 3 Aug 2010 20:47:11 UTC; path=/";
}


function checkMyList(objCheckBox, famId) {
	
	var i = 0;
	var cookieName = "myList";
	var myListCookie = getcookie(cookieName);
	//alert(cookieName);
	var cookieArray = myListCookie.split(",");
	for(i=0;i<objCheckBox.length;i++) {
		for(j=0; j<cookieArray.length; j++){
			if (objCheckBox[i][1] == cookieArray[j]) {
			document.getElementById(objCheckBox[i][0]).checked = true;
				}
		}
	}
}

function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

// These are the My List Functions

function updateMyList() {
	var strCookie = "";
	for(i=0;i<document.myList.myListId.length;i++) {
		if (!document.myList.myListId[i].checked) {
			strCookie = strCookie + document.myList.myListId[i].value + ",";
		}
	}
	if (strCookie.charAt(strCookie.length -1) == ",") {
		strCookie = strCookie.substring(0,strCookie.length -1);
	}
	document.cookie = "opecMyList=" + strCookie + "; expires=Tue, 3 Aug 2010 20:47:11 UTC; path=/";
	self.location.reload(true);
}

function clearMyList() {
	if (confirm ("Are you sure you want to clear your entire list?")) {
		document.cookie = "opecMyList=; expires=Tue, 3 Aug 2010 20:47:11 UTC; path=/";
		self.location.reload(true);
	} else {
		return false;
	}
}

function printMyList() {
	alert('print functionality to be added when page information finalised');
}

function emailMyList(strWhere) {
	document.myList.emailtype.value = strWhere;
	if (strWhere == "friend") {
		document.myList.action = "../getFriendEmail.asp";
	}
	document.myList.submit();
}

// End My List Functions

function popupWindow(strUrl) {
	window.open(strUrl, "popupWindow", 'toolbar=no,width=800,height=600,resizable=yes,scrollbars=1') 
}

function addNewItem(strType) {
	var strURL = "edit" + strType + "item.asp?id=new";
	window.open(strURL, "EditWindow", 'toolbar=no,resizable=yes,scrollbars=1') 
}

function openEditItem(strType, intID, intSCID, intCID, intFID) {
	var strURL = "edit" + strType + "item.asp?id=" + intID + "&scid=" + intSCID + "&cid=" + intCID + "&fid=" + intFID;
	window.open(strURL, "EditWindow", 'toolbar=no,width=800,height=600,resizable=yes,scrollbars=1') 
}

function validateForm(objForm, strFormType) {
	var strErr = "";
	
	if (strFormType == 'product') {
		if (!(objForm.name.value.length > 0)) {
			strErr = strErr + "Please add a product name\n";
		}
		if (!(objForm.category_id.value > 0)) {
			strErr = strErr + "Please select a category\n";
		}
	} else if (strFormType == 'case') {
		if (!(objForm.title.value.length > 0)) {
			strErr = strErr + "Please add a title\n";
		}
		if (!(objForm.type_id.value > 0)) {
			strErr = strErr + "Please select a type\n";
		}
		if (objForm.sort_order.value == "") {
			strErr = strErr + "Please enter a numeric sort order\n";
		}
	} else if (strFormType == 'project') {
		if (!(objForm.title.value.length > 0)) {
			strErr = strErr + "Please add a title\n";
		}
		if (objForm.sort_order.value == "") {
			strErr = strErr + "Please enter a numeric sort order\n";
		}
	} else if (strFormType == 'category') {
		if (!(objForm.name.value.length > 0)) {
			strErr = strErr + "Please add a name\n";
		}
		if (objForm.sort_order.value == "") {
			strErr = strErr + "Please enter a numeric sort order\n";
		}	
	} else if (strFormType == 'editorial') {
		if (!(objForm.publication.value.length > 0)) {
			strErr = strErr + "Please add a publication\n";
		}
	} else if (strFormType == 'family') {
		if (!(objForm.name.value.length > 0)) {
			strErr = strErr + "Please add a name\n";
		}	
	} else if (strFormType == 'homewares') {
		if (objForm.sort_order.value == "") {
			strErr = strErr + "Please enter a numeric sort order\n";
		}
		if (objForm.image_url.value == "") {
			strErr = strErr + "Please enter an image\n";
		}
	} else if (strFormType == 'vendor') {
		if (!(objForm.name.value.length > 0)) {
			strErr = strErr + "Please enter a name\n";
		}	
	} else {
		if (!(objForm.title.value.length > 0)) {
			strErr = strErr + "Please add a title\n";
		}
	}
	
	if (strErr == "") {
		return true
	} else {
		alert(strErr);
		return false;
	}
}

function SetUrl(strURL, width, height, alt, strWhat, base) {
	eval("document.frm1."+strWhat+".value=\""+strURL+"\"");
	eval("document."+strWhat+"_image.src=\""+base+strURL+"\"");
}

// Cross Browser DOM
// copyright Stephen Chapman, 4th Jan 2005
// you may copy this code but please keep the copyright notice as well
var aDOM = 0; /* var ieDOM = 0; */ 
var nsDOM = 0;
var stdDOM = document.getElementById;
if (stdDOM) aDOM = 1; else {/*ieDOM = document.all; if (ieDOM) aDOM = 1; else { */
var nsDOM = ((navigator.appName.indexOf('Netscape') != -1)
&& (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1; /* } */ }

function xDOM(objectId, wS) {
	if (stdDOM) return wS ? document.getElementById(objectId).style:document.getElementById(objectId);
	if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId];
	if (nsDOM) return document.layers[objectId];
}



 
