function swapCSSClass(class1, class2, fieldName)
{
	obj = document.getElementById(fieldName); 
	if (obj.className == class1)
		obj.className = class2; 
	else if (obj.className == class2)
		obj.className = class1; 
}

function hideShowLayers(layer1, layer2)
{
	swapCSSClass("hiddenBlock", "visibleBlock", layer1);
	swapCSSClass("hiddenBlock", "visibleBlock", layer2); 
}

function confirmDelete(url, rec)
{
	//alert("hello"); 
	question = "Are you sure you want to delete "+rec; 
	if (confirm(question))
	{
		window.location = url; 
	}
	else
		return; 

}

function PopUpWin(url, properties)
{
	//alert(properties); 
	prop = "status=yes,resizable=yes,scrollbars=yes,toolbar,top=50,left=100," + properties; 
	myWindow = window.open(url, "", prop)
}

function isEmailValid(email)
{
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
    var regex = new RegExp(emailReg);
    return regex.test(email);	
}

function validateSubscribeForm(obj)
{
	frm 	= obj.form; 
	email 	= frm.txtEmail.value; 
	if (isEmailValid(email))
	{
		frm.submit(); 
	}
	else
	{
		alert("The email address you entered is not valid.  Please try again."); 
		return false; 
	}
}

function validateRegisterForm(obj)
{
	
	var frm = document.form1; 
	var err1 = ""; 
	// name
	name1 = frm.txtName; 
	if (name1.value == "")
	{
		err1 += "- Name \n"; 
		name1.style.backgroundColor = "#EEE8AA"; 
	}
	else
		name1.style.backgroundColor = "#fff"; 
	
	 
	// address
	address = frm.txtAddress; 
	if (address.value == "")
	{
		err1 += "- Address \n";
		address.style.backgroundColor = "#EEE8AA"; 
	}
	else
		address.style.backgroundColor = "#fff"; 
	
	// city
	city = frm.txtCity; 
	if (city.value == "")
	{
		err1 += "- City \n";
		city.style.backgroundColor = "#EEE8AA"; 
	}
	else
		city.style.backgroundColor = "#fff"; 
	
	province = frm.txtProvince; 
	
	pc1 = frm.pc1; 
	pc2 = frm.pc2; 
	pc = pc1.value +"-"+pc2.value; 
	if ( !(isPostalCodeValid(pc)) )
	{
		err1 += "- Postal Code \n"; 
		pc1.style.backgroundColor = "#EEE8AA"; 
		pc2.style.backgroundColor = "#EEE8AA"; 
	}
	else
	{
		pc1.style.backgroundColor = "#fff"; 
		pc2.style.backgroundColor = "#fff"; 
	}
	
	pnh1 = frm.pnh1; 
	pnh2 = frm.pnh2; 
	pnh3 = frm.pnh3; 
	pnh = pnh1.value+"-"+pnh2.value+"-"+pnh3.value; 
	if ( !(isPhoneNumberValid(pnh)) )
	{
		err1 += "- Home Phone Number \n"; 
		pnh1.style.backgroundColor = "#EEE8AA"; 
		pnh2.style.backgroundColor = "#EEE8AA"; 
		pnh3.style.backgroundColor = "#EEE8AA"; 
	}
	else
	{
		pnh1.style.backgroundColor = "#fff"; 
		pnh2.style.backgroundColor = "#fff"; 
		pnh3.style.backgroundColor = "#fff"; 
	}
	
	if (err1 != "")
	{
		err1 = "Please make sure the following fields are properly filled in: \n\n" + err1; 
		alert(err1); 
		return false; 
	}
	else
	{
		frm.submit(); 
	}
	
}



function isPostalCodeValid(pc)
{
	var pcReg = "^[A-Za-z][0-9][A-Za-z]-[0-9][A-Za-z][0-9]$";
    var regex = new RegExp(pcReg);
    return regex.test(pc);	
}

function isPhoneNumberValid(pn)
{
	var pnReg = "^[2-9][0-9][0-9]-[2-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$";
    var regex = new RegExp(pnReg);
    return regex.test(pn);	
}

