// JavaScript Document

function changeperson(userlist,ptype,frm)
{
	if(ptype == 0)
	{
		userlist.disabled=true;
		clearform(frm);
		frm.returnfield.value='no';
		document.getElementById("divexistuser").style.visibility = "visible";
		document.getElementById("divexistuser").style.position = "static";
	}
	else
	{
		userlist.disabled=false;
		document.getElementById("divexistuser").style.visibility = "hidden";
		document.getElementById("divexistuser").style.position = "absolute";
	}
}

function submitform(frm)
{
	frm.returnfield.value='yes';
	frm.action = '/addevent.asp';
	frm.submit();
}

function clearform(frm)
{
	for(var i=0; i< frm.length; i++)
	{
		if(frm[i].type == 'text')
			frm[i].value = "";
		if(frm[i].type == 'select-one')
		{
			frm[i].selectedIndex = 0;
			if(frm[i].name == "CountryCode")
			frm[i].value="US";
		}
	}
	
}
function checkoccasion(frm)
{
	if(frm.occasion.value == "")
	{
		window.alert("You missed occasion");
		frm.occasion.focus();
		return false;
	}
	if(frm.occasiondate.value == "")
	{
		window.alert("You missed date of occasion");
		frm.occasiondate.focus();
		return false;
	}
	return true;
}
function deleteoccasion(idWish,currentPage)
{
	var res;	
	res=confirm("Do you want to delete this occasion " );	
	if (res)
	{
	window.location.href="viewoccasions.asp?delete=yes&idWish="+idWish+"&curPage="+currentPage;
	}
}
function deleteeventproduct(idWish,idevent,currentPage)
{
	var res;	
   	res=confirm("Do you want to delete this product from list " );	
	if (res)
	{
	window.location.href="vieweventproducts.asp?delete=yes&idprod="+idWish+"&idevent="+idevent+"&curPage="+currentPage;
	}
}

function checkupgrade(frm)
{
	/*if (frm.cardNumber.value =="")
	{
		window.alert("You missed credit card number ");
		frm.cardNumber.focus();
		return false;
	}
	
	return checkcardcode(frm);*/

}
function showdiv(divname,str)
{
	document.getElementById(""+divname).style.visibility='visible';
	document.getElementById(""+divname).style.position='absolute';
	if( str!="" )
	document.getElementById(""+divname).innerHTML = "<img src='/uploadimages/"+str+"' width='110' border='0'>";
}
function hidediv(divname)
{
	document.getElementById(""+divname).style.visibility='hidden';
	document.getElementById(""+divname).style.position='absolute';
}
function openmore()
{
	window.open('/about-subscription.asp','Learnmore','scrollbars=yes,status=no,width=600,height=400');
}
function openccinfo()
{
	window.open('/cc-info.asp','Learnmore','scrollbars=yes,status=no,width=700,height=600');
}
function openfreeship()
{
	window.open('/about-freeshipping.asp','Learnmore','scrollbars=yes,status=no,width=600,height=400');
}
function checkcardcode(frm)
{
	if(frm.cardType.value != "Discover")
	{
	if (frm.cardcode.value =="" )
	{
		window.alert("You missed security code");
		frm.cardcode.focus();
		return false;
	}
	}
	if(frm.cardType.value == "A" && frm.cardcode.value.length != 4 )
	{
		window.alert("CC security code should be 4 digit");
		frm.cardcode.focus();
		return false;
	}
	if(frm.cardType.value == "M" && frm.cardcode.value.length != 3 )
	{
		window.alert("CC security code should be 3 digit");
		frm.cardcode.focus();
		return false;
	}
	if(frm.cardType.value == "V" && frm.cardcode.value.length != 3 )
	{
		window.alert("CC security code should be 3 digit");
		frm.cardcode.focus();
		return false;
	}
	return true;
}

function checkshipaddress(shipaddress)
{
	
	if (shipaddress.catdesc.value =="")
	{
	window.alert("You missed address title");
	shipaddress.catdesc.focus();
	return false;
	}
	if (shipaddress.shipname.value =="")
	{
	window.alert("You missed first name");
	shipaddress.shipname.focus();
	return false;
	}
	if (shipaddress.shiplastname.value =="")
	{
	window.alert("You missed last name");
	shipaddress.shiplastname.focus();
	return false;
	}
	if (shipaddress.shpAddress1.value =="")
	{
	window.alert("You missed shipping address1");
	shipaddress.shpAddress1.focus();
	return false;
	}
	
	if (shipaddress.shpCity.value =="")
	{
	window.alert("You missed shipping city");
	shipaddress.shpCity.focus();
	return false;
	}
	if (shipaddress.shpStateCode.value == "" )
	{
		window.alert("you missed shipping state");
		shipaddress.shpStateCode.focus();
		return false;
	}
	
	if (shipaddress.shpCountryCode.value =="")
	{
	window.alert("You missed shipping  country code");
	shipaddress.shpCountryCode.focus();
	return false;
	}

	if (shipaddress.shpZip.value =="")
	{
	window.alert("You missed shipping  zip");
	shipaddress.shpZip.focus();
	return false;
	}
}
function showaddress(ptype)
{
	if (ptype == "a")
	{
		document.getElementById("addressbook").style.visibility='visible';
		document.getElementById("addressbook").style.position='static';
		document.getElementById("reminderservice").style.visibility='hidden';
		document.getElementById("reminderservice").style.position='absolute';
		document.orderform.eventslist.selectedIndex = 0;
	}
	else if(ptype == "o")
	{
		document.getElementById("reminderservice").style.visibility='visible';
		document.getElementById("reminderservice").style.position='static';
		document.getElementById("addressbook").style.visibility='hidden';
		document.getElementById("addressbook").style.position='absolute';
		document.orderform.addresslist.selectedIndex = 0;
	}
}

function subscribeform(cutR,custid)
{
	if(checkreg(cutR,custid))
	{
		//return checkupgrade(cutR);
		return true;
	}
	else
		return false;
}
function subscribeformbackend(cutR,custid)
{
	if(checkregbackend(cutR,custid))
	{
		//return checkupgrade(cutR);
		return true;
	}
	else
		return false;
}
function checkcc(cardform)
{
	if (cardform.cardNumber.value =="")
	{
		window.alert("You missed credit card number ");
		cardform.cardNumber.focus();
		return false;
	}
	return checkcardcode(cardform);
}

function checkregbackend(cutR,custid)
{
	/*if (cutR.nametitle.selectedIndex == 0)
	{
		window.alert("You missed title ");
		cutR.nametitle.focus();
		return false;
	}*/
	if (cutR.firstname.value =="")
	{
	window.alert("You missed first name ");
	cutR.firstname.focus();
	return false;
	}
	if (cutR.lastname.value =="")
	{
	window.alert("You missed last name");
	cutR.lastname.focus();
	return false;
	}
	
	if(custid == 0 )
	{
		if (cutR.email.value =="")
		{
		window.alert("You missed email");
		cutR.email.focus();
		return false;
		}
		else
		{
			if(!checkEmail(cutR.email))
				return false;
		}
		if (cutR.password.value =="")
		{
		window.alert("You missed password");
		cutR.password.focus();
		return false;
		}
		/*else
		{
			h = cutR.password.value.length;
			x = cutR.password.value;
	
			for( i=0;i<h;i++)
			{
			 
				if (  h < 6 )
				{
								alert(" Password can't be less than 6" + " characters");
								cutR.password.focus();
								cutR.password.select();
								return false;
				}
				var valid = "0123456789"
				var okn = "yes";
				var temp;
				for (var i=0; i<cutR.password.value.length; i++) 
				{
					temp = "" + cutR.password.value.substring(i, i+1);
					if(temp=="\'" || temp=="\"")
					{	
						okn = "no";
						alert("The character \',\" is not allowed in password");
						cutR.password.focus();
						cutR.password.select();
						return false;
					}
					if (valid.indexOf(temp) == "-1") 
						okn = "no";
				}
				var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
				var oka = "num";
				var temp;
				for (var i=0; i<cutR.password.value.length; i++) 
				{
					temp = "" + cutR.password.value.substring(i, i+1);
					if (valid.indexOf(temp) == "-1") 
						oka = "alp";
				}
			}
			if(okn=="yes" || oka == "num")
			{
				alert("Password should be Aplphanumeric");
				cutR.password.focus();
				cutR.password.select();
				return false;
			}
		}*/
		if (cutR.cpassword.value =="")
		{
		window.alert("You missed confirm password");
		cutR.cpassword.focus();
		return false;
		}
		if (cutR.cpassword.value !=cutR.password.value)
		{
		window.alert("Confirm password and password should be same");
		cutR.cpassword.value="";
		cutR.password.value="";
		cutR.password.focus();
		return false;
		}
	}
	
	if (cutR.address1.value =="")
	{
	window.alert("You missed address1");
	cutR.address1.focus();
	return false;
	}
	
	if (cutR.city.value =="")
	{
	window.alert("You missed city");
	cutR.city.focus();
	return false;
	}
	if (cutR.stateCode.value == "" )
	{
	window.alert("You missed state code");
	cutR.stateCode.value=""
	cutR.stateCode.focus();
	return false;
	}
	if (cutR.CountryCode.value =="")
	{
	window.alert("You missed country ");
	cutR.CountryCode.focus();
	return false;
	}
	
	/*if (cutR.zip.value =="")
	{
	window.alert("You missed zip");
	cutR.zip.focus();
	return false;
	}*/
	
	return true;
}