fieldName=new Array("User Name","Password");
indexa=new Array("0","1");

function newCustomer()
{
	
	if (window.screen.availWidth==800)
	{
	    window.open('https://www.bayline.net/MainSubscriptionForm8.htm', 'newWindow', 'scrollbars=yes,toolbar=no,status=yes,width=690,height=500,resizable=no, top=0',true);
	}
	else
	{
	    window.open('https://www.bayline.net/MainSubscriptionForm.htm', 'newWindow', 'scrollbars=yes,toolbar=no,status=yes,width=690,height=600,resizable=no, top=0',true);
	}
}

function versubmit()
{
	for(i=0; i<2; i++)
	{
		if( document.forms[0].elements[indexa[i]].value=="")
		{
			alert("Please fill-in "+fieldName[i]+" field");

			document.forms[0].elements[indexa[i]].focus();
			document.forms[0].elements[indexa[i]].select();	
			
			return false;
		}
		else if( checkMinLength(4, document.forms[0].elements[indexa[i]].value) )
		{
			alert("A minimum of 4 non-blank characters for "+fieldName[i]+" is required");
			document.forms[0].elements[indexa[i]].focus();
			document.forms[0].elements[indexa[i]].select();
		
			return false;
		}	
	}

	return true;
}

function checkNickname()
{
	if( document.forms[0].pNickname.value=="")
	{
		alert("Please type a Nickname to search for.");

		document.forms[0].pNickname.focus() ;
		return false;
	}
	return true
}


function validEmilAddr( thisEmail )
{
	if (thisEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}


function validZipCode( countryIndex, zipCode )
{
	if( countryIndex == '0' )	// US ZIP code
		 return USPostalCode(zipCode);

	else if( countryIndex == '1' )
		return CanadianPostalCode(zipCode);
}


function USPostalCode( pCode )
{
//	alert( "US zip code." );

	if( (pCode.length == 5) && !(isNaN(pCode))
			|| (pCode.length == 10) && isNaN(pCode) )
		return true;
	else
		return false;
}

function CanadianPostalCode( pCode )
{
//	alert( "Canadian postal code." );
	err = 0;
	
	if( pCode.length != 6 )
		err = 1;
	else
	{
		a = pCode.toLowerCase();

		b = a.substring(0,1);	//1st letter
		c = parseInt(a.substring(1,2));	//2nd number
		d = a.substring(2,3);	//3rd letter
		f = parseInt(a.substring(3,4));	//4th number
		g = a.substring(4,5);	//5th letter
		h = parseInt(a.substring(5,6));	//6th number

		if (b < 'a' || b > 'z')	//is not letter
			err =1;
		else if( parseInt(a.substring(0,1)) )
			err = 1;

		if (c < 0 || c > 9)	//is not number
			err = 1;
		else if( !parseInt(a.substring(1,2)) && c!=0 )
			err = 1;

		if (d < 'a' || d > 'z')	//is not letter
			err =1;
		else if( parseInt(a.substring(2,3)) )
			err = 1;

		if (f < 0 || f > 9)	//is not number
			err = 1;
		else if( !parseInt(a.substring(3,4)) && f!=0 )
			err = 1;

		if (g < 'a' || g > 'z')	//is not letter
			err =1;
		else if( parseInt(a.substring(4,5)) )
			err = 1;

		if (h < 0 || h > 9)	//is not number
			err = 1;
		else if( !parseInt(a.substring(5,6)) && h!=0 )
			err = 1;
	}
	
	if( err )
		return false;
	else return true;
}



function doMasking(maskwhat, maskhow)
{
	var ctl =  maskwhat;
	var c1;  // counter variable
	var thekey;

	if (event)
		thekey = event.keyCode;

	// if they are cursor values or enter, ignore them and return
	mask = new String(maskhow);		// this is the mask which is applied to the data
	oval = new String("");				// the old value
	nval = new String("");				// this is the formatted value

	switch( thekey )   // ignore the following cursor and control keys
	{
		case 9:  // Tab
		case 16: // Shift key
		case 35: // End
		case 36: // Home
		case 37: case 38: case 39: case 40: // cursors
		return ctl;
	}

	oval = stripMasking(ctl);

	for(c1=0; c1<mask.length; c1++)
	{
		if( c1 >= oval.length ) // past the input string?
		{
			if( thekey != 8 && thekey != 46) // backspace & delete
			{
				while( mask.charAt(c1) != '9' && mask.charAt(c1) != 'A'  && mask.charAt(c1) != 'Z' && c1 < mask.length)
				{
					nval = nval + mask.charAt(c1++);
				}
			}
			break;
		}
		else if( (mask.charAt(c1) == '9') )  // for a number...
		{
			if( oval.charAt(c1) < '0' || oval.charAt(c1) > '9' )    // not number entered
			{   // delete this character
				oval = oval.substring(0, c1) + oval.substring(c1+1, oval.length);
			}
			else
			{
				nval = nval + oval.charAt(c1);
			}
		}
		else if( (mask.charAt(c1) == 'A' ) || (mask.charAt(c1) == 'a' ))  // for a letter...
		{  // extraneous character appearing!
			if( !(oval.charAt(c1) >= 'a' && oval.charAt(c1) <= 'z') &&
				!(oval.charAt(c1) >= 'A' && oval.charAt(c1) <= 'Z') )
			{   // delete this character
				oval = oval.substring(0, c1) + oval.substring(c1+1, oval.length);
			}
			else
			{
				nval = nval + oval.charAt(c1);
			}
		}
		else if( (mask.charAt(c1) == 'Z') )  // for a alpha numeric
		{
			nval = nval + oval.charAt(c1);
		}
		else 							// for formatting
		{	// insert the mask value
			nval = nval + mask.charAt(c1);
			oval = oval.substring(0, c1) + mask.charAt(c1) + oval.substring(c1, oval.length);
		}
	}
	return nval;
}


function stripMasking(maskwhat)
{
	var ctl =  maskwhat;
	var c1;  // counter variable
	oval = new String(ctl);	// the field value

	for(c1=0;c1<oval.length;)     // discard formatting so we can re-format
	{
		if( !(oval.charAt(c1) >= '0' && oval.charAt(c1) <= '9') &&
			!(oval.charAt(c1) >= 'a' && oval.charAt(c1) <= 'z') &&
			!(oval.charAt(c1) >= 'A' && oval.charAt(c1) <= 'Z'))
		{
			if( c1 == oval.length-1 )    // if at the end of the string...
			{
				oval = oval.substring(0, c1);  // take everything before it
			}
			else
			{
				oval = oval.substring(0, c1) + oval.substring(c1+1, oval.length); // del c1
			}
		}
		else c1++;
	}
	
	return oval;
}

function highlightButton(s)
{
	event.srcElement.className=s
}


/* ============================================================= */
/* check to see if myString (trimed off) is less then thisLength */
/* - return true if myString.length < thisLength		 */
/*============================================================== */
function checkMinLength( thisLenth, myString )
{
	if( trimString(myString).length < thisLenth )
		return true;

	return false;
}



//===============================
//  functions used by toolbar.asp
//===============================

var numOfPopups = 2;

function doBlur()
{
	for( i=0; i<numOfPopups; i++)
		document.all.menuOption[i].style.display = "none";

	document.all.html.style.pixelHeight = document.body.scrollHeight;
}

function dropDown( optionId )
{
	for( i=0; i<numOfPopups; i++)
		if( i != optionId )
			document.all.menuOption[i].style.display = "none";
	
	document.all.menuOption[optionId].style.pixelTop = document.all.h[optionId].offsetTop + document.all.h[optionId].offsetHeight;
	document.all.menuOption[optionId].style.pixelLeft = document.all.h[optionId].offsetLeft;
	document.all.menuOption[optionId].style.pixelWidth = document.all.h[optionId].offsetWidth; 
	document.all.menuOption[optionId].style.display = "";
	document.all.html.style.pixelHeight = document.body.scrollHeight;
}

function doNavigate()
{
	if (event.srcElement.tagName=="A")
	{
		if (event.srcElement.code!=null)
		{
			external.raiseEvent("oncnavigate", event.srcElement.code)
		}
		else
		{
			external.raiseEvent("onnavigate", event.srcElement.href);
		}
	}

	if (event.srcElement.tagName=="P")
		if (event.srcElement.children[0].tagName=="A")
			if (event.srcElement.children[0].code!=null)
				external.raiseEvent("oncnavigate",event.srcElement.children[0].code)
	else
		external.raiseEvent("onnavigate", event.srcElement.children[0].href);
}
   
function doLoad()
{
  document.all.html.style.pixelWidth = document.body.scrollWidth
  document.all.html.style.pixelHeight = document.body.scrollHeight
}

//===============================
//  end of functions used by toolbar.htm
//===============================

function trimString( thisString )
{
	return thisString.replace(/^\s+/,'').replace(/\s+$/,'')
}


//maybe function highlightButton1() will be replaced with 2 new function:

function highlightButton1()
{
	//hint pt user
	document.F1.B1.title="Click here for submit";
	//grow width of the button
	i=parseInt(document.F1.B1.style.width);
	i=i+1;
	document.F1.B1.style.width=i;	
	//grow height of the button
	i=parseInt(document.F1.B1.style.height);
	i=i+1;
	document.F1.B1.style.height=i;
	//change the font text
	document.F1.B1.style.fontStyle='italic';
	//change border right and bottom
	document.F1.B1.style.borderRightWidth='medium';
	document.F1.B1.style.borderBottomWidth='medium';
    //change left margin
    i=parseInt(document.F1.B1.style.marginLeft);
	i=i-1;
	document.F1.B1.style.marginLeft=i.toString();
}
function highlightButton2()
{
	//replace width
	i=parseInt(document.F1.B1.style.width);
	i=i-1;
	document.F1.B1.style.width=i;
	//replace height
	i=parseInt(document.F1.B1.style.height);
	i=i-1;
	document.F1.B1.style.height=i;
	//replace font style
	document.F1.B1.style.fontStyle='normal';
	//replace border style: all
	document.F1.B1.style.borderRightWidth='thin';
	document.F1.B1.style.borderBottomWidth='thin';	
	//document.F1.B1.style.borderLeftStyle='none';
    //document.F1.B1.style.borderTopStyle='none';
    //replace left margin
    i=parseInt(document.F1.B1.style.marginLeft);
	i=i+1;
	document.F1.B1.style.marginLeft=i.toString();
}

//*********************************************************
//			the next function is for CALENDAR.Object
//*********************************************************

//show calendar in page

function showmenu(elmnt,dt,tata)
{
	vari=tata+"year.value=getyear(dt)";
	eval(vari);	
	vari=tata+"month.options[getmonth(dt)].selected=true";
	eval(vari);
	dt.setDate(1);
	bg=dt.getDay()+1;
	fn=showLastOfMonth(dt);
	for (i=1; i<=6;i++)
		for (j=1; j<=7;j++)
		{
			if ((i==1) && (j<bg))
			{
				vari=tata+"b"+String(i)+String(j)+".style.visibility='hidden'";
				eval(vari);
				//alert("i="+i+" bg="+bg+" "+eval(i<bg));
			}
			else
			{
				if (j+(i-1)*7-bg+1<=fn)
				{
					/*
					if ((i==6) && (j==1))
					{
						row8.style.visibility="visible";
					}
					*/
					vari=tata+"b"+String(i)+String(j)+".style.visibility='visible'";
					eval(vari);
					vari=tata+"b"+String(i)+String(j)+".value=j+(i-1)*7-bg+1";
					eval(vari);
				}
				else
				{
					vari=tata+"b"+String(i)+String(j)+".style.visibility='hidden'";
					eval(vari);
					
					/*
					if ((i==6) && (j==1))
					{
						row8.style.visibility="hidden";
						
					}
					*/
				}
			}			
			
		}
	
	document.all(elmnt).style.visibility="visible";
}

//hide calendar in page
function hidemenu(elmnt,tata)
{
	document.all(elmnt).style.visibility="hidden";
	for (i=1; i<=6;i++)
		for (j=1; j<=7;j++)
		{
			vari=tata+"b"+String(i)+String(j)+".style.visibility='hidden'";
			eval(vari);
		}
	
	//r1.style.visibility="hidden";
}

//return tha date value in month/day/year format:mm/dd/yyyy

function retval(month,day,year,edit,tata,elmnt)
{
	hidemenu(elmnt,tata);
	//alert(button.value);
	if (day.length==1)
	{
		day="0"+day;
	}
	edit.value=month+"/"+day+"/"+year;
}

function getyear(dt)
{
	return dt.getFullYear();
}

function getmonth(dt)
{
	return dt.getMonth();
}

function clickleft(dt,tata,elmnt)
{
	dt.setMonth(dt.getMonth()-1);
	showmenu(elmnt,dt,tata);
}

function clickright(dt,tata,elmnt)
{
	dt.setMonth(dt.getMonth()+1);
	showmenu(elmnt,dt,tata);
}

function showLastOfMonth(dt)
{
   eomDate = new Date(dt);
   eomDate.setMonth(eomDate.getMonth() + 1 );
   eomDate.setDate(1);
   eomDate.setDate( eomDate.getDate() - 1);
   return eomDate.getDate();
}

function month_onchange(dt,tata,elmnt) 
{
	vari="dt.setMonth("+tata+"month.options["+tata+"month.selectedIndex].value-1)";
	eval(vari);
	//dt.setMonth(month.options[month.selectedIndex].value-1);
	showmenu(elmnt,dt,tata);
}

function year_onchange(dt,tata,elmnt) 
{
	vari="mn=parseInt("+tata+"year.value)";
	eval(vari);
	//mn=parseInt(tata+year.value);	
	if (isNaN(mn))
		{
			alert("This is not a valid year !");
			vari=tata+"year.focus()";
			eval(vari);
			return false;
		}
	else
		if( eval("checkMinLength(4,"+tata+"year.value)") )
			{
				alert("A 4 non-blank characters for Year is required");
				eval(tata+"year.focus()");
				return false;
			} 
		else
			if ((mn<=1900) || (mn>=2200))
			{
				alert("Year value is incorect !");
				eval(tata+"year.focus()");
				return false;
			}
			else
				{
					dt.setFullYear(mn);
					showmenu(elmnt,dt,tata);
					return true;
				}
}
/**********************************************************
					BROWSER CAPABILITIES
***********************************************************/
/* This function return True if we found MSIE browser
   otherwise return false*/	

function isMSIE()
{
	if (navigator.appName.indexOf("Microsoft Internet Explorer")>-1)
	{
		if (navigator.appVersion.indexOf("MSIE")>-1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		isIE=false;
	}
}

/*this function return the version of MSIE or -1 if 
  your browser is not msie or something happened

*/

function getVersionMSIE()
{
	var sVersion,fVersion; 

	fVersion=-1;
	
	sVersion=navigator.appVersion;

	sVersion=sVersion.substring(sVersion.indexOf("MSIE"),sVersion.length);
			
	if (sVersion.indexOf(";")>-1)
	{
		sVersion=sVersion.substring(4,sVersion.indexOf(";"));
		if (!(isNaN(parseFloat(sVersion))))
		{
			fVersion=parseFloat(sVersion);
		}
		else
		{
			fVersion=-1;
		}	
	}
	else
	{
		if (!(isNaN(parseFloat(sVersion))))
		{
			fVersion=parseFloat(sVersion);
		}
		else
		{
			fVersion=-1;
		}
	}
			
		return fVersion;
}

function rolloverText1(who)
{
	switch (who)
	{
	case 1:
		show.innerHTML="<b><br>Last Number Re-Dial</b><br>"+
							"Your last called number can be dialed by push # button, "+ 
						    "even when haven't use your account for a while. "+
						    "An ideal feature for travelers. ";
		break;
	case 2:
		show.innerHTML="<b><br>International Call Back</b><br>"+
						"Traveling overseas? Why pay more on your long distance calls, have your Premium Calling Card to "+
						"call you back at your hotel room or even to a pay phone at international "+
						"airports and then make calls to home or anywhere in the world, even retrieve "+
						"your messages.<A href='MainCallBackSystem.htm' target=MainFrame><img src='images/p01_50.gif' width=11 border=0 height=9></a>";
		break;
	case 3:
		show.innerHTML="<b><br>Continuous Calling (Multiple Calls)</b><br>"+
						"To make more calls no need to hang up, make multiple calls one "+
						"after another pressing * * * after you finised the call. One session, multiple calls, ideal for public phones.";
		break;
	case 4:
		show.innerHTML="<b><br>Conference Calling</b><br>"+
					"Create a Conference of your own and speak to many people at the same time with full control Drop out, come back or talk in "+
					"private at any time, an enhanced feature that was available only to large with prior appointment and no control.";
		break;
	case 5:
		show.innerHTML="<b><br>Virtual Phone Book (Mobile Speed Dial)</b><br>"+
					"Store your frequently dialed numbers, not in your Cellular or Note Book, but in your PCS account. It is safe and easy to use, "+
					"you can attach a description to each one of them to give them a personal touch.";
		break;
	}		
}

function rolloverText(who)
{
	switch (who)
	{
	case 1:
		show.innerHTML="<b><br>Direct Dial</b><br>"+
							"The lowest rates possible for direct dial. Just pick up your phone "+
							"and dial 1 or 011 + your number and you'll get the best deal. Billed "+
							"on 6 seconds increments with a minimum of 30 seconds charge. ";
		break;
	case 2:
		show.innerHTML="<b><br>Toll Free</b><br>"+
						"You can receive calls from anywhere. Get a personal or business 800, 888, 877, 866 toll-free number "+
						"to ring on your cell phone, pager, fax machine, work phone, etc.";
						
  		
		break;
	case 3:
		show.innerHTML="<b><br>Calling Card</b><br>"+
						"Each and every calling card has demonstrated the ability to offer "+
						"a great rate as well as world-class customer service. "+
						"Treat yourself to a better rate today!";
		break;
	case 4:
		show.innerHTML="<b><br>PCS Talk to Me</b><br>"+
					"PCS Talk to me is the ideal solution for business persons who really need to "+
					"keep in touch with other parties aroud the clock.";
		break;
	case 5:
		show.innerHTML="<b><br>PCS Follow-Me+</b><br>"+
					"PCS Talk to me is the ideal solution for business persons who really need to "+
					"keep in touch with other parties aroud the clock, and many more...";
	//	show.innerHTML="<b><br>PCS Follow-Me+</b><br>"+ 
	//				"Allows users to have calls forwarded to any on-campus extension. "+
	//				"This forwarding can be redirected as you travel from one on-campus "+
	//				"location to another on-campus location.";
		break;
	case 6:
		show.innerHTML="<b><br>PCS View</b><br>"+ 
					"PCS View is the most user friendly way to mange your "+
					"communications... via internet. Receive your faxes online, "+
					"hear and save your voice mails on your PC, change your configurations "+
					"with a single mouse click!";
		break;
	case 7:
		show.innerHTML="<b><br>Private Line</b><br>"+ 
					"Bayline introduces Private Line products & services. Click "+
					"to find out exceptional rates and features.";
		break;	
	}		
}