// JavaScript Document

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//var numb = '0123456789';
//var lwr = 'abcdefghijklmnopqrstuvwxyz';
//var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 
	function isValid(parm,val) 
	{
		if (parm == "" || parm == null) 
			return true;
			
		for (i=0; i<parm.length; i++) 
		{
			if (val.indexOf(parm.charAt(i),0) == -1) 
				return false;
		}
		return true;
	}
	 
	function isDay(parm, name) 
	{
//		parm = strtrim(parm);
		if (parm == "")
			return true;
		
		if (!isValid(parm,'0123456789'))
		{
			alert(name + ' only allow numeric input (0-9)');
			return false;		
		}
		
		if (parm.length != 8)
		{
			alert(name + ' should contains 8 digit numbers (YYYYMMDD).');
			return false;		
		}		

		var syear = parm.substring(0, 4);	
		var smth = parm.substring(4, 6); 	
		var sday = parm.substring(6, 8);
		
		var iyear = syear * 1; 	
		var imth = smth * 1;
		var iday = sday * 1;
		
		var ret = isValidDay(iyear, imth, iday)
		if (ret != 0)
		{
			//alert(name + ' is not a valid date format (YYYYMMDD)');
			switch (ret)
			{
				case 1:
					alert(name + ' not in valid date format.\nYear range should be within 1900 - 2200');
					break;
				case 2:
					alert(name + ' not in valid date format.\nMonth range should be within 01 - 12');
					break;				
				case 3:
					alert(name + ' not in valid date format.\nDay range should be within 01 - 31');
					break;	
				case 4:
					alert(name + ' not in valid date format.\nDo not have 31 day in month 4, 6, 9 & 11');
					break;														
				case 5:
					alert(name + ' not in valid date format.\nThere is only 28 or 29 days on February');
					break;																			
			}
			return false;
		}
		else
			return true;
	}
		 
	function isValidDay(y, m, d)
	{
		if (y < 1900 || y > 2200)  return 1;
		if (m < 1 || m > 12)       return 2;
		if (d < 1 || d > 31)       return 3;
		if (m == 4 || m == 6 || m == 9 || m == 11)
		{
			if (d == 31)
				return 4;
		}
		if (m == 2)
		{
			max_d = 28;
			if (y % 400 == 0)
				max_d = 29;
			else if (y % 4 == 0)
				max_d = 29;
			
			if (d > max_d)
				return 5;
		}
		return 0;
	}

	function ShowPrintDialog()
	{
		window.modal("../Member/printcheckoutconfirm.aspx",'height=750,width=730,help=no,scroll=yes,status=no,resizable=no');
	}
	
	function AlertMsgBoxKey(title, content)
	{	
		//window.showModalDialog("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&Title=5010&Content=5009", '','dialogHeight:400px; dialogWidth:600px; help:no; scroll:no; status:no; resizable:no');
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&Title="+title+"&Content="+content,'height=200,Width=500,help=no,scroll=no,status=no,resizable=no');
	}
	
	function AlertMsgBoxKeyLarge(title, content)
	{	
		//window.showModalDialog("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&Title=5010&Content=5009", '','dialogHeight:400px; dialogWidth:600px; help:no; scroll:no; status:no; resizable:no');
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&Title="+title+"&Content="+content,'height=500,width=500,help=no,scroll=no,status=no,resizable=no');
	}
		
	function AlertMsgBoxNameKey(title, content, control_name)
	{
		//var rc = window.showModalDialog('../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=False&Type=MSGBOX_TYPE_OK&Title=6000&Content=2254&Content2=2243', '','dialogHeight:400px; dialogWidth:600px; help:no; scroll:no; status:no; resizable:no'); } ShowPopUp();	
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=False&Type=MSGBOX_TYPE_OK&Title="+title+"&Content="+control_name+"&Content2="+content,'height=200,width=500,help=no,scroll=no,status=no,resizable=no');
	}
	
	function AlertMsgBoxKeyLargeMoq(title, content, content2)
	{	
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_MOQ&Title="+title+"&Content="+content + "&Content2="+content2,'height=320,width=700,help=no,scroll=no,status=no,resizable=no');
	}
		
	function AlertMsgBoxKeyQuantityRange(title, content, extraMsg)
	{	//ExtraMsg
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&ExtraMsg="+extraMsg+"&Title="+title+"&Content="+content,'height=200px,width=500,help=no,scroll=no,status=no,resizable=no');
	}	
		
	function AlertMsgBoxKeyCreditCardWarning(title, content, extraMsg, content3)
	{	//ExtraMsg
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&Type=MSGBOX_TYPE_OK&ExtraMsg="+extraMsg+"&Title="+title+"&Content="+content+"&Content3="+content3,'height=200px,width=500,help=no,scroll=no,status=no,resizable=no');
	}	
			
	function ConfirmMsgBoxKey(title, content)
	{
		var rc = window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=True&Type=MSGBOX_TYPE_OK_CANCEL&Title="+title+"&Content="+content,'height=200px,width=500,help:no,scroll=no,status:no,resizable=no'); 
		return rc;		
	}

	function ConfirmMsgBoxKeyAction(title, content, action)
	{
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=True&Type=MSGBOX_TYPE_OK_CANCEL&Title="+title+"&Content="+content+"&action="+action,'height=200px,width=500,help:no,scroll=no,status:no,resizable=no'); 	
	}
	
	function ConfirmMsgBoxKeyYesNo(title, content)
	{
		var rc = window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=True&Type=MSGBOX_TYPE_YES_NO&Title="+title+"&Content="+content,'height=200,width=500,help=no,scroll=no,status=no,resizable=no'); 
		return rc;		
	}
	
	function ConfirmMsgBoxKeyYesNoAction(title, content, action)
	{
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=True&Type=MSGBOX_TYPE_YES_NO&Title="+title+"&Content="+content+"&action="+action,'height=200,width=500,help=no,scroll=no,status=no,resizable=no'); 		
	}	
	
	
	function ScheduledListMsgBoxKeyOK(title, content)
	{
		window.modal("../Common/MsgBox.aspx?UseIntKeyNothing=Int&ReturnUseBool=True&Type=MSGBOX_TYPE_OK&Title="+title+"&Content="+content,'height=200,width=500,help=no,scroll=no,status=no,resizable=no'); 
	}
	
		
	function testingFunc()
	{
		alert('a');
		location.href = "member.aspx";			
	}
	
	function isControlEmpty(control, titlekey, contentkey)
	{
		if (control) 			
		{	
			if (control.value == '')
			{
				AlertMsgBoxKey(titlekey, contentkey)
				return true;
			}
			else
			{
				return false;
			}			
		}
		
		return false;
	}
	
	function isEmpty(control)
	{
		if (control) 			
		{	
			if (control.value == '')
			{			
				return true;
			}
			else
			{
				return false;
			}			
		}
		
		return false;
	}
		
	function isNum(parm, name) 
	{
		//return isValid(parm,'0123456789');
		if (isValid(parm,'0123456789'))
			return true;
		else
		{		
			//alert(name + ' only allow numeric input (0-9)');			
			
			if (name != '')
			{
				AlertMsgBoxNameKey(7600, 7602, name);
			}
			return false;
		}
	}
	
	function isAlpha(parm, name) 
	{
		//return isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
		if (isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
			return true;
		else
		{
			//alert(name + ' only allow alphabetical input (A-Z or a-z)');			
			AlertMsgBoxNameKey(7600, 7603, name);
			return false;
		}		
	}

	function isAlphanum(parm,name) 
	{
		//return isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+'0123456789');
		if (isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+'0123456789'))
			return true;
		else
		{
			//alert(name + ' only allow alphanumerical input (A-Z or a-z or 0-9)');			
			AlertMsgBoxNameKey(7600, 7604, name);
			return false;
		}		
	} 
	
	function isValidEmail(parm, title, content) 
	{
		if (parm == "") 
			return true;
			
		if (isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+'0123456789' + '@-_.'))
		{		
			if (parm.indexOf('@') > 0 && parm.indexOf('@') < parm.length - 1 && parm.indexOf('@') == parm.lastIndexOf('@'))
			{
				return true;
			}
			else
			{
				AlertMsgBoxKey(title, content);
				return false;			
			}
		}
		else
		{
			AlertMsgBoxKey(title, content);
			return false;
		}		
	}
	
	function isValidPassword(parm, title, content) 
	{
		if (parm == "") 
			return true;
			
		if (isValid(parm,'abcdefghijklmnopqrstuvwxyz'+'ABCDEFGHIJKLMNOPQRSTUVWXYZ'+'0123456789'))
		{		
				return true;
		}
		else
		{
			AlertMsgBoxKey(title, content);
			return false;
		}		
	}
	
		
	function isCustomFormat(parm, name, allowStr) 
	{
		return isValid(parm, allowStr);
	} 	
	
	function limitMaxLength(txtControl, len)
	{
		if (txtControl) 			
		{
			if (txtControl.value.length <= len)
				return true;
			else
			{
				txtControl.value = txtControl.value.substring(0, len)			
				return true;
			}					
		}
	}		
	
	function checkRange(parm, minlen, maxlen)
	{
		if (parm.length >= minlen && parm.length <= maxlen)
			return true;
		else
			return false;
	}			
	
	//**********************************************************************
	//	Area <--> District drop down filtering functions		
	//***********************************************************************
	function populate_data(ddlb, val, dis_info) {
		var j=0, l, i=0, count=0;
		var s = new String("")

		clear_header(ddlb);
	
		var no = new Option();
		//if (val == "all")
		if (val == "-1")
		{
			//insert_option( "all", dis_info, 0, ddlb);
			insert_option( "-1", dis_info, 0, ddlb);
		}
		else
		{
			//insert_option( "header" + dis_info, "---- " + dis_info + " ----",0, ddlb);
			insert_option( "-2", "---- " + dis_info + " ----",0, ddlb);
		}

		i = 1;
		
		var temp = new Array();
		for (j=ddlb.length-1; j > i; j--)
		{
			s = ddlb.options[j].value;
			
			temp = s.split('~');		
			
			//if (s.substr(3,2) == val)
			if (temp[0] == val)
			{
				
				insert_option(ddlb[j].value, ddlb[j].text, 1, ddlb);
					//return;
				j++;
				i++;
			}
			else
			{	
				
			}
		}

		ddlb[0].selected = true;
	}

	function insert_option(ival, itext, ix, iddlb) {
		var lno = new Option();
		var u,i,k;
		
		u = iddlb.length-1;
		// last value
		lno.value = iddlb.options[u].value;
		lno.text = iddlb.options[u].text;
		// append new object
		iddlb.options[u+1] = lno;

		u=iddlb.length-2;

		for(i=u; i>=ix; i--)
		{
			k = i+1;
			iddlb.options[k].text = iddlb.options[i].text;
			iddlb.options[k].value = iddlb.options[i].value;
		}

		iddlb.options[ix].text = itext;
		iddlb.options[ix].value = ival;

	}
				
	function clear_header(cddlb) {
		var ptr, i, j;
		
		var temp = new Array();
		for (i=0; i<cddlb.length; i++)
		{		
			temp = cddlb.options[i].value.split('~');		

			//alert("value = " + temp[0]);
			//if (cddlb.options[i].value == "all")		
			//if (cddlb.options[i].value == "-1")
			if (temp[0] == "-1")
			{
				ptr = i;
			}
		}
		
	//	alert("ptr = " + ptr);
	//	alert("cddlb.length = " + cddlb.length);
		
		j=0;
		if (ptr > 0)
		{
			for (i=ptr; i<cddlb.length; i++)
			{
				cddlb.options[i-ptr].value = cddlb.options[i].value;
				cddlb.options[i-ptr].text = cddlb.options[i].text;
				j++;
			}
			cddlb.length = j;
		}
		
	//	alert("j = " + j);
	}
	
	
	//**********************************************************************
	//	Service Type <--> Service Issue drop down filtering functions		
	//***********************************************************************
	var issue_text_temp = new Array();
	var issue_value_temp = new Array();
	function service_init(ddlb)
	{
		var i=0;
		if (issue_value_temp.length == 0 ||  issue_value_temp == null){
			for(i=0;i < ddlb.length ; i++)
			{
				issue_text_temp[i] = ddlb.options[i].text;
				issue_value_temp[i] = ddlb.options[i].value;
			}
		}
	}
	
	function service_populate_data(ddlb, val) {
		var j=0, l, i=0, count=0,k=0;
		var s = new String("")
		var no = new Option();
		var temp = new Array();
		if (issue_value_temp.length == 0 ||  issue_value_temp == null){
			for(i=0;i < ddlb.length ; i++)
			{
				issue_text_temp[i] = ddlb.options[i].text;
				issue_value_temp[i] = ddlb.options[i].value;
			}
		}
		ddlb.length = 0; 
		for (j=0; j < issue_value_temp.length; j++)
		{
			s = issue_value_temp[j];	
			temp = s.split('~');		
			if (temp[1] == val)
			{
				ddlb.options[k] = new Option(issue_text_temp[j],issue_value_temp[j]);
				k++;
			}
		}
		if (k != 0)
		{
			ddlb[0].selected = true;
		}else
		{
			ddlb.selectedIndex = 0;
		}
	}
	
	function servicetype_populate_data(ddlb, val) {
		var j=0, l, i=0, count=0,k=0;
		var temp = new Array();
		for (j=0; j < ddlb.length; j++)
		{
			temp = val.split('~');		
			if (temp[1] == ddlb[j].value)
			{
				ddlb[j].selected = true;
			}
		}
	}
	//**********************************************************************
	//	Credit card validation
	//***********************************************************************	
	function isValidCardNumber (strNum) 
	{
		var nCheck = 0;
		var nDigit = 0;
		var bEven  = false;
		   
		for (n = strNum.length - 1; n >= 0; n--) 
		{
			var cDigit = strNum.charAt (n);
			if (isDigit (cDigit))
			{
				var nDigit = parseInt(cDigit, 10);
				if (bEven)
				{
					if ((nDigit *= 2) > 9)
					nDigit -= 9;
				}
				nCheck += nDigit;
				bEven = ! bEven;
			}
			else if (cDigit != ' ' && cDigit != '.' && cDigit != '-')
			{
				return false;
			}
		}
		return (nCheck % 10) == 0;
	}
	
	function isDigit (c)
	{
		var strAllowed = "1234567890";
		return (strAllowed.indexOf (c) != -1);
	}
	
	function isCardTypeCorrect (strNum, type)
	{
		var nLen = 0;
		for (n = 0; n < strNum.length; n++)
		{
			if (isDigit (strNum.substring (n,n+1)))
				++nLen;
		}
		   
		if (type == 'Visa')
			return ((strNum.substring(0,1) == '4') && (nLen == 13 || nLen == 16));
		else if (type == 'Amex')
			return ((strNum.substring(0,2) == '34' || strNum.substring(0,2) == '37') && (nLen == 15));
		else if (type == 'Master Card')
			return ((strNum.substring(0,2) == '51' || strNum.substring(0,2) == '52'
					|| strNum.substring(0,2) == '53' || strNum.substring(0,2) == '54'
					|| strNum.substring(0,2) == '55') && (nLen == 16));
		else
			return false;	   
	}
	function DefaultButton()
	{
		if (window.event.keyCode == 13)
		{
			window.event.returnValue =false;
		}
	}

	function vSearch()
	{	
		window.open(encodeURI('../Product/products.aspx?keysearch=1&Search=' + document.forms[0].txtSearch.value),'_self');	
	}
	
	//Show Dialog
	function dialog(url,name,feature,isModal)
	{
		if(url==null){return false;}
			url = url
		if(name==null){name=""}
		if(feature==null){feature=""};
	if(window.showModelessDialog)
	{
  		var WindowFeature = new Object();
		WindowFeature["width"] = 500;
		WindowFeature["height"] = 500;
		WindowFeature["left"] = "";
		WindowFeature["top"] = "";
		WindowFeature["resizable"] = "";
		if(feature !=null && feature!="")
		{
			feature = ( feature.toLowerCase()).split(",");
		
			for(var i=0;i< feature.length;i++)
			{
				//if( feature[i].isArgument())
				//{
					var featureName = feature[i].split("=")[0];
					var featureValue = feature[i].split("=")[1];
					if(WindowFeature[featureName]!=null){WindowFeature[featureName] = featureValue; }
					if(featureName == "width")
						WindowFeature["width"] = featureValue;
					if(featureName == "height")
						WindowFeature["height"] = featureValue;
					if(featureName == "scroll")
						WindowFeature["scroll"] = featureValue;
				//}
			}
		}
	 
		if(WindowFeature["resizable"]==1 || WindowFeature["resizable"]=="1" || WindowFeature["resizable"].toString().toLowerCase()=="yes"){WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;"}
		if(WindowFeature["left"]!=""){WindowFeature["left"] ="dialogLeft:" +  WindowFeature["left"] +"px;";}
		if(WindowFeature["top"]!=""){WindowFeature["top"] ="dialogTop:" +  WindowFeature["Top"] +"px;"; }
		if(window.ModelessDialog ==null){window.ModelessDialog = new Object() ; };
		if(name!="")
		{
			if(window.ModelessDialog[name]!=null && !window.ModelessDialog[name].closed )
			{
				window.ModelessDialog[name].focus();
				return window.ModelessDialog[name];
			}
		}
		var F = WindowFeature["left"] +WindowFeature["top"] +  "dialogWidth:"+WindowFeature["width"] +" px;dialogHeight:"+WindowFeature["height"]+"px;center:1;help:0;" + WindowFeature["resizable"] +"status:0;unadorned:0;edge: raised; border:thick;help:no;scroll:"+ WindowFeature["scroll"] +";status:no;resizable:no;titlebar:no;hotkeys:no";
		if(isModal)
		{
			window.ModelessDialog[name] = window.showModalDialog(url,self,F);
			return window.ModelessDialog[name];
		}
		else
		{
			window.ModelessDialog[name] = window.showModelessDialog(url,self,F);
			return window.ModelessDialog[name];
		}	
	}
	else
	{
		if(document.getBoxObjectFor)
		{
		

			if(isModal)
			{		 
				var Modal = window.open(url,name,"modal=1," + feature);
				var ModalFocus = function()
				{
					if(!Modal.closed){Modal.focus();}
					else{Modal =null;window.removeEventListener(ModalFocus,"focus");ModalFocus = null; };					
				}
				window.addEventListener( "focus",ModalFocus, false ); 
				return Modal;
			}
			else
			{
				return window.open(url,name,"modal=1," + feature);
			}	 
		}
		else	
		{ 
			return window.open(url,name,feature);
		}
	}
	return null;
	}
   
	function modal(url,feature)
	{
		return dialog(url,"",feature,true);
	}


	
//-->

