
function popupgoToLink(aTag){
	newWindow = window.open(aTag.href,'CommerceCM_Popup','width=580,height=400,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0')
	self.name = 'mainWindow'
	newWindow.focus()
	return false;
	//alert("Should be going to" + aTag.href);
}

function isValidEmail(emailAddress){
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(emailAddress);
}

function checkEmail(){
	try{
		var strTest = new String(document.getElementById("txtEmail").value);
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(strTest)){
			return true;
		}else{
			alert("Please enter a valid email address (abc@123.com)");
			return false;
		}
	}catch(e){
		return false;
	}
}

function popwindow_small(url)
{
	var newwindow;
	newwindow=window.open(url,'name','height=350,width=430, left=300, top=40');
	if (window.focus) {newwindow.focus()}
}

function popwindow(url, height, width, returnvalue)
{
	try{
		if (!height) height=550;
		if (!width)  width=430;
			var newwindow;
			var options = 'height='+height+',width='+width+', left=300, top=40'
			newwindow=window.open(url,null,options);
			if (window.focus) {newwindow.focus()}
			return returnvalue
		}
	catch(e){
		return true;
	}
}

function popwindowscroll(url, height, width)
{
	try{
		if (!height) height=550;
		if (!width)  width=430;

		newwindow=window.open(url,'name','height='+height+',width='+width+', left=300, top=40, scrollbars=yes');
	//	newwindow=window.open(url,'name','height=550,width=430, left=300, top=40');
		if (window.focus) {newwindow.focus()}
		return false
	}
	catch(e){
		return true;
	}
}

function PopupProduct(productid, show, imageindex){
	try{
		newwindow = window.open('/popup_Product.aspx?productid=' + productid + '&show=' + show + '&imageindex=' + imageindex, 'ProductMore', 'width=600,height=700,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no,resizable=no,top=100,left=100');
		if (window.focus) {newwindow.focus()}
		return false;
	}catch(e){
		return true;
	}
}

/* EVENT HANDLING */

function addSafeEventListener(s_event, f_function){
	if(typeof(f_function) != 'function'){
		throw(new Error(000, 'Can not assign ' + typeof(f_function) + ' as the event handler.'));
	}
	if(document.addEventListener){
		window.addEventListener(s_event, f_function, false);
		return;
	}
	if(window.attachEvent){
		window.attachEvent('on' + s_event, f_function);
		return;
	}
	var f_oldHandler = window['on' + s_event];
	if(typeof(f_oldHandler) == 'function'){
		window['on' + s_event] = function(){
			f_oldHandler();
			f_function();
		}
		return;
	}
	window['on' + s_event] = f_function;
}


// for case sensitivity
function shopperlink(link){
	shopperLink(link);
	return true;
}

// check for property change of form fields
function setListeners(){
	inputList = document.getElementsByTagName("INPUT");
	for(i=0; i<inputList.length; i++){
		try{
			inputList[i].attachEvent("onpropertychange", restoreStyles);
		}catch(ex){
			return;
		}
	}
	selectList = document.getElementsByTagName("SELECT");
	for(i=0; i<selectList.length; i++){
		try{
			selectList[i].attachEvent("onpropertychange", restoreStyles);
		}catch(ex){
			return;
		}
	}
}

// reset bg color
function restoreStyles(){
	if(event.srcElement.style.backgroundColor != "")
	event.srcElement.style.backgroundColor = "";
}

// validate newsletter email
function checkNewsletterEmail(email){
	try{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(filter.test(email)){
			return true;
		}else{
			alert("Please enter a valid email address (abc@123.com)");
			return false;
		}
	}catch(e){
		return false;
	}
}
