var newWindow = null;
var orderlink = "";
var upgradelink = "";

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=no,location=no,status=no,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
	window.name='windowOpener';
}

function toggle(id,arrow)
{ var target = document.getElementById(id);
 if (target.style.display!= "none") 
 {
 target.style.display = "none"; 
 document.getElementById(arrow).src="/skins/Skin_1/images/arrdo.gif";
 }
 else 
 {
 target.style.display = "block"
 document.getElementById(arrow).src="/skins/Skin_1/images/arrup.gif";
 }
}

function toggleorder(id,arrow1,arrow2)
{ var target = document.getElementById(id);
 if (target.style.display!= "none") 
 {
 target.style.display = "none"; 
 document.getElementById(arrow1).src="/skins/Skin_1/images/arrdo.gif";
 document.getElementById(arrow2).src="/skins/Skin_1/images/arrdo.gif";
 }
 else 
 {
 target.style.display = "block"
 document.getElementById(arrow1).src="/skins/Skin_1/images/arrup.gif";
 document.getElementById(arrow2).src="/skins/Skin_1/images/arrup.gif";
 }
}

function ordernow(event,id,show)
{
var target = document.getElementById(id);
x=event.clientX;
y=event.clientY;
target.style.display = show; 
target.style.position = "absolute";
target.style.left = x;
target.style.top = y;
}

function showupgrade(id,show)
{
var target = document.getElementById(id);
x=130;
y=30;
target.style.display = show; 
target.style.position = "absolute";
target.style.left = x;
target.style.top = y;
}

function showbundle(id,show)
{
var target = document.getElementById(id);
target.style.display = show; 
}

function showupsell()
{
if (location.search != "")
{
	var x = location.search.substr(1).split("&amp;")
	for (var i=0; i<x.length; i++)
	{
		var y = x[i].split("=");
		if (y[0] == "Return")
		{
			document.write('<div style="display: block;">');
		}
	}
}
else
{
	document.write('<div style="display: none;">');
}
}

function closediv()
{
	document.write('</div>');
}


function leftlinks()
{
	// Position buy now links down left column under menu
	// Calc height under left menu
	var colheight = centercol.offsetHeight;
	var menuheight = leftmenu.offsetHeight;
	var menuleft = leftmenu.offsetLeft;
	var heightavail = colheight - menuheight;
	// divide that by 4
	var heightbyfour = heightavail / 4;
	var nextdiv = parseInt(heightbyfour)
	// place 3 links down the column
	leftlink1.style.position = "relative";
	leftlink2.style.position = "relative";
	leftlink3.style.position = "relative";

	var placethis = nextdiv / 2;
	leftlink1.style.top = placethis;
	placethis = placethis + nextdiv;
	leftlink2.style.top = placethis;
	placethis = placethis + nextdiv;
	leftlink3.style.top = placethis;
}
 
function closeupgrade() 
{
	location.href=upgradelink;
}

function linktoorder() 
{
if (orderlink=="")
	{
	showupgrade('upgrademenu','block');
	}
else
	{
	location.href=orderlink;
	}
}

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
	if(ok.indexOf(e.charAt(i))<0){
	return (false);
	}
}

if (document.images) {
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!e.match(re) && e.match(re_two)) {
	return (-1);
	}

}

}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

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
}


function ValidateForm()
{
	var mo=document.ChooseList.babyMonth.value;
	var da=document.ChooseList.babyDay.value;
	var yr=document.ChooseList.babyYear.value;
	if (mo=="-1")
		{
		document.ChooseList.babyMonth.focus();
		alert("Please select a valid month");
		return;
		}
	if (da=="-1")
		{
		document.ChooseList.babyDay.focus();
		alert("Please select a valid day");
		return;
		}
	if (yr=="-1")
		{
		document.ChooseList.babyYear.focus();
		alert("Please select a valid year");
		return;
		}

	var dt=mo+"/"+da+"/"+yr;
	if (isDate(dt)==false)
		{
		document.ChooseList.babyDay.focus();
		return false;
		}

	if(!check_email(document.ChooseList.Email.value))
	{
	alert("Your email address is invalid.  It must be in the form of yourname@domain.com");
	document.ChooseList.Email.focus();
	return;
	}

    document.ChooseList.Date.value=dt;
    document.ChooseList.submit();

 }
