/* function for validating the member login screen (member_login.php) */

function MemberLoginValidate(frm) {
	if(frm.member_id.value=="") {
		alert('Please enter Member ID!!!');
		frm.member_id.focus();
		return false;
	}
	if(frm.member_pass.value=="") {
		alert('Please enter Password!!!');
		frm.member_pass.focus();
		return false;
	} else {
		return true;
	}
}

/* fucntion for adding dynamic address field in the postcard send page (postcard.php) */

function addAddressRow() {   
	var j=4;

	var tbody = document.getElementById('emailtable').getElementsByTagName('tbody')[0]; 
	var row   = document.createElement('TR'); 
	var cell1 = document.createElement('TD');    
	var inp1  = document.createElement('INPUT');      

	//First input box      
	inp1.setAttribute('type','text'); 
	inp1.setAttribute('id','email'+j);
	inp1.setAttribute('name','email'+j); 
	inp1.setAttribute('value','');
	inp1.setAttribute('size','30');
	inp1.setAttribute('style','width:200px');
	j++;

	cell1.appendChild(inp1); 
	row.appendChild(cell1); 


	tbody.appendChild(row); 
	document.getElementById("hideemail").value=document.getElementById("hideemail").value*1+1;
}

function validatePostcard() {

	var found_it; //initial value is null because we gave it no other value
	var upload_found_it;
	var count_email = 0;
	var count_validate_email = 0;
	var count_extension = 0;
	not_proceed = false;

	
	//loop to check atleast one email adddress is input
	for(i = 1; i<=document.getElementById("hideemail").value*1; i++)
	{
		 if(document.getElementById("email"+i).value != "")
		 {
				count_email++;
				break;		
		 }
	}
	
	for (var i=0; i < document.frmpostcard.postcard.length; i++)  { 
		if (document.frmpostcard.postcard[i].checked)  {

			found_it = document.frmpostcard.postcard[i].value; //set found_it equal to checked button's value

		} 
	}

	if(document.frmpostcard.postcard_image.value!="") {
			upload_found_it = document.frmpostcard.postcard_image.value;
	}
	if(!found_it && !upload_found_it){
		alert("Please Choose Your Photo or Upload your Own Photo!!!");
	} else {
		if(found_it && upload_found_it){
			alert("Please Choose Your Photo or Upload your Own Photo. You can't choose both!!!");
		} else { 
			if(document.frmpostcard.postcard_image.value!="") {
				if(LimitAttach(document.frmpostcard,document.frmpostcard.postcard_image.value)==false) {
					alert("Please upload the image type(jpg,png,bmp.gif) only");
					document.frmpostcard.postcard_image.focus();
					not_proceed = true;
				}
			}
			if(!not_proceed) {
				if(document.frmpostcard.txtname.value=="") {
					alert('Please Enter Your Name!!!');
					document.frmpostcard.txtname.focus();
				} else {
				if(!not_proceed) {
					if(document.frmpostcard.message.value=="") {
						alert('Please Enter Message!!!');
						document.frmpostcard.message.focus();
					} else {
						if(count_email <= 0) {
							alert('Please Enter Atleast One Email Address!!!');
							//alert(document.frmpostcard.1email);
						} else {
							for(j = 1; j<=document.getElementById("hideemail").value*1; j++) 
							{
								 if(document.getElementById("email"+j).value != "")
								 {
									if (echeck(document.getElementById("email"+j).value)==false){
										//alert('Invalid Email ID !!')
										document.getElementById("email"+j).focus();
										count_validate_email++;
										break;	
									}
								 }
							}
							if(count_validate_email >= 1) {
								alert('Invalid Email ID !!');
							} else {
								document.frmpostcard.action = "postcard_info.php";
								document.frmpostcard.submit();
							}
						}
						
					}
				}
			  }
			}
		}
	}
}

function resetMemberLoginForm() {
	document.frmMemberLogin.member_id.value="";	
	document.frmMemberLogin.member_pass.value="";
	
}


extArray = new Array(".jpg", ".png", ".bmp",".gif",".JPG",".wbmp",".PNG", ".BMP",".GIF",".WBMP");
function LimitAttach(form, file) {
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
	if (extArray[i] == ext) { allowSubmit = true; break; }
	}
	if (allowSubmit) {return true;}
	else
	//alert("Please upload the image type(jpg,png,bmp.gif) only");
	return false;
}

function discountPopup(id) {
	window.open('discount_info.php?id='+id,'Discount','width=470, height=350')
}

function virtualPopup() {
	window.open('virtual.php','Discount','width=500, height=440 , scrollbars=yes')
}

function reservationAction() {
	document.formReservation.mod.value='send';
	document.formReservation.action="reservations.php";
	document.formReservation.submit();
}

function index_page_redirect(obj) {
	if(obj.options[obj.selectedIndex].value!=0)
	{
		self.location= obj.options[obj.selectedIndex].value;			
	}
}