function MaxLengthValidate(event, control, length)
{
	var isNetscape=(navigator.appName=="Netscape")?1:0;

	if(!isNetscape)
	{
		var val = document.getElementById(control).value;

		if (val.length >= length)
			event.returnValue=false;
	}
	else
	{
		var val = document.getElementById(control).value;

		if (val.length >= length)
			return false;
		//if(event.which==8)return true;
		//if((event.which<45||event.which>57))return false;
	}
}
function ShowPopUpBlock()
{
	var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
	
	if(mine)
	{
	}
	else
	{
		alert('We have detected popup blocking on your browser.\nPlease disable this to allow confirmation email to be sent.');
	}

	mine.close();
}

function displayProperties(obj)
{
	var str = "";
	var prop;
	if(typeof(obj.length) != "undefined" && typeof(obj[0]) != "undefined")
	{
		for(prop = 0;prop < obj.length;prop++)
		{
			str += "\n" + prop + "=" + obj[prop];
		}
	}
	else
	{
		for(prop in obj)
		{
			str += "\n" + prop + "=" + eval("obj." + prop);
		}
	}
	alert(str);
}

 function SetFocus(elementInst)
 {
    document.forms[0].elements[elementInst].focus();
 }

  function ShowConfirmation()
  {
	var retVal = confirm("Are you sure ?");
	return retVal;
  }
  
  function NotImplemented()
  {
	alert("Coming Soon!");
	return false;
  }  
  
 
  function NotAllowed()
  {
	var sign_up = confirm("You must sign in to use this feature.\nIf you are not a registered customer, you may open an account now. \n\nClick OK to Sign In or Sign up");	
	// alert("This feature is available to registered users only. \n If you are a registered user then you need to \n login first.");
	if (sign_up == true)
	{
		var currLocation = window.location;
		window.location = '../myaccount/sign-in.aspx?ReturnUrl=' + currLocation;
	}
	
	return false;
  }  
  

////   Email a Friend START
///	   called from EmailFriend.aspx

	function CheckSubjectSelected()
				{
					var objList = document.getElementById('lstSubjectLine');
					if(typeof(objList) == 'undefined')
						return args=false;
					if(objList.selectedIndex != -1)
						return args = true;
					else
						return args = false;
				}
				function CheckFriendNameTwo()
				{
					var objFriendEmail = document.getElementById('txtFriendEmailTwo'); 
					var objFriendName  =  document.getElementById('txtFriendNameTwo');
					if(typeof(objFriendEmail) == 'undefined' && typeof(objFriendName) == 'undefined')
						return args = false;
					if(objFriendEmail.value != '' && objFriendName.value == '')
						return args = false;
					else
						return args = true;
				}
				function CheckFriendNameThree()
				{
					var objFriendEmail = document.getElementById('txtFriendEmailThree'); 
					var objFriendName  =  document.getElementById('txtFriendNameThree');
					if(typeof(objFriendEmail) == 'undefined' && typeof(objFriendName) == 'undefined')
						return args = false;
					if(objFriendEmail.value != '' && objFriendName.value == '')
						return args = false;
					else
						return args = true;
				}
				function CheckFriendNameFour()
				{
					var objFriendEmail = document.getElementById('txtFriendEmailFour'); 
					var objFriendName  =  document.getElementById('txtFriendNameFour');
					if(typeof(objFriendEmail) == 'undefined' && typeof(objFriendName) == 'undefined')
						return args = false;
					if(objFriendEmail.value != '' && objFriendName.value == '')
						return args = false;
					else
						return args = true;
				}

////   END Email a Friend

	function textLimitonpropertychange(objCtrl,Limit) 
	{
		
		field=document.getElementById(objCtrl.id);
		if(field.value.length > Limit)
		{
			field.value = field.value.substring(0, Limit-1);
			return false;
		}
		else
			return true;
	}

////   Multiline TextBox Max Length Limit for both Firefox & IE

	function MultilinetextLimitonpropertychange(objCtrl,Limit) 
	{
		field=document.getElementById(objCtrl.id);
		if(field.value.length > Limit)
		{
			field.value = field.value.substring(0, Limit);
			return false;
		}
		else
			return true;	
	}




// VALIDATIONS

function isNumber(obj)
{	
		
	if(obj.value.search(/[^0-9^.^ ]/) != -1)  
	{
		//obj.value="";
		obj.focus();
		return false;			
	}
		
	
	return true;
	
}


// END VALIDATIONS


function CheckSpecialChars(event)
{

	var isNS4 = (navigator.appName=="Netscape")?1:0;
	
	if(!isNS4)
	{
	 if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) event.returnValue = false;
	}
	else
	{
	 if ((event.which > 32 && event.which < 48) || (event.which > 57 && event.which < 65) || (event.which > 90 && event.which < 97)) return false;
	}
}

function CheckNumbers(event)
{
	
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	
	if(!isNS4)
	{
	  if(event.keyCode < 45 || event.keyCode > 57)
	   event.returnValue = false;
	}
	else
	{	
		
	  if(event.which < 45 || event.which > 57) return false;
	}
}
//chek for integer--Anand Raval,13-Feb-2006
function CheckInteger(event)
{
	
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	
	if(!isNS4)
	{
	  if(event.keyCode < 47 || event.keyCode > 57)
	   event.returnValue = false;
	}
	else
	{	
		
	  if(event.which < 47 || event.which > 57) return false;
	}
}
//this function allows only 0-9 and "." not even "-" also.
function CheckCurrency(event)
{		
	var isNS4 = (navigator.appName=="Netscape")?1:0;	
	if(!isNS4)
	{
	  if(event.keyCode < 46 || event.keyCode > 57 || event.keyCode == 47)
	   event.returnValue = false;
	}
	else
	{	
		if (event.which == 8 || event.which == 0 )  return true;					
		if(event.which < 46 || event.which > 57 || event.which == 47) return false;
	}
}

// US Phone End


// CANADIAN CODES ONLY

function IsValidZIP()
{ 
	var obj		 = document.getElementById('txtZipCode');
	
	if (obj != null && obj != 'undefined')
	{
		if(obj.value.length > 4)
		{
		
			var pattern1 = /^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)?\d[a-z]\d\s*$/i;
			var pattern2 = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

			var re1;
			re1 = new RegExp(pattern1);
			
			var re2;
			re2 = new RegExp(pattern2);	

			return args = ( re1.test(obj.value) || re2.test(obj.value) );
		}
		else
		{
			return args = false;
		}
	}
	else
	{
		return args = false;
	}		
}

// EN CANADA


// PRINT RECEIPT AND GC

function PrintDocument()
{
	try
	{
		var objTablePrint = document.getElementById('tblPrint');
		
		if(objTablePrint!=null)
			objTablePrint.style.display = "none";
		window.print();
		if(objTablePrint!=null)
			objTablePrint.style.display = "";
	}
	catch(exc)
	{
		alert(exc.message);
	}
}

// PEINT END

// VALIDATION functions from QFORMS


function Field_isEmail(email)
{
	var pattern = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]+$/;
	// \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
	var re;
	re = new RegExp( pattern);
	if(!re.test(email))
	{
		return false;	
	}
	else
	{
		return true;	
	}
}

function Field_isNumeric(numeric)
{
	if(isNaN(numeric))
	{
		return false;		
	}
	else
	{
		return true;
	}
}

// END


//check date in in mm/dd/yyyy format ...
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range

return false;
}
if (day < 1 || day > 31) {

return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {

return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {

return false;
   }
}
return true;  // date is valid
}

function NoRightsMsg()
{
	alert("You have no Rights of this function !")
	return false;
}
function MoveFocus(Control, limit, FocusControlId)
{	
	if (Control == null || document.getElementById(FocusControlId) == null)
		return ;
	if (Control.value.length == limit)
	{
		SetFocus(FocusControlId)
	}
}
function PopupPage(pageUrl, pageWidth, pageHeight)
{
	//Code to display in the center goes here
	var left = (screen.width - pageWidth)/2;
	var top = (screen.height - pageHeight)/2;
	if (isNaN(left)) 
		left = 0;
	if (isNaN(top)) 
		top = 0;
		
	var newPopup = window.open(pageUrl, "_blank", "dependent=yes, directories=no, location=no, menubar=no, personalbar=no, resizable=no, scrollbars=no, status=no, toolbar=no, height=" + pageHeight + ", width=" + pageWidth + ", left=" + left + ", top=" + top + ", dialog=yes");
	return newPopup;
}

/* This window will open the image in pop-up with same height */

function PopupImage(imageUrl)
{
	
	var imgShow = new Image();
	imgShow.src = imageUrl;
	
	PopupPage(imageUrl, imgShow.width + 20,imgShow.height + 30);
}

function PopupImageD(imageUrl, width, height)
{
	
	var imgShow = new Image();
	imgShow.src = imageUrl;
	
	PopupPage(imageUrl, width + 20, height + 30);
}

/* This window will open the video in pop-up with same height */

function PopupVideo(h, w, videoUrl)
{
	PopupPage("../Home/Open-Video.aspx?Width=" + w + "&Height=" + h + "&FileName=" + videoUrl , w, h);
	
	/*
	if (null != popUp && popUp != 'undefined' && popUp != '')
	{
		popUp.document.title = "Watch Video";
	}
	*/
	
}


function NotImplemented()
{
	alert("Coming Soon!");
	return false;
}
  
function textLimitonpropertychange(objCtrl,Limit) 
	{
		
		field=document.getElementById(objCtrl.id);
		if(field.value.length > Limit)
		{
			field.value = field.value.substring(0, Limit-1);
			return false;
		}
		else
			return true;
	}
function OpenDialog(openFile, varTop, varLeft,varHeight,varWidth, varScroll, winName)
{
	window.open(openFile,winName, "top=" + varTop + ",left=" + varLeft + ",height=" + varHeight + ",width=" + varWidth + ",scroll=" + varScroll + ",toolbar=no,menubar=no,location=no,center=yes,resizable=no,scrollbars=" + varScroll + "");
	return false;
}

//only allows 0-9
function CheckDigit(event)
{
	
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	
	if(!isNS4)
	{
	  if(event.keyCode < 47 || event.keyCode > 57)
	   event.returnValue = false;
	}
	else
	{
	 if (event.which == 8 || event.which == 0 )  return true;			
	  if(event.which < 47 || event.which > 57) return false;
	}
}
///////////////////////////////////////////////////////
// method for phone number check in my accounts pages
function PhoneNumberCheck()//validate phone number 
		{
			
			var ph1 = document.getElementById('txtPhone');
			var ph2 = document.getElementById('txtPhone2');
			var ph3 = document.getElementById('txtPhone3');
			var phone = ph1.value+"-"+ph2.value+"-"+ph3.value;			
			if(phone.length!=12)
			{
				return false;
			}
			return true;
		}
/////////////////////////////////////////////////

function SubmitButton(button, event)
{
	
	if ((event.which ? event.which : event.keyCode) == 13)
	{		
		document.getElementById(button).click(); return false;
	}
}	

function CloseWindow()
{
	window.close();
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : MM/DD/YYYY")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/*****************Cookie Related functions**************/
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}