// Created by LiuYang 12/2006    ---> http://aboutliuyang.blogspot.com/index.html
// This file is just used for cart submission

function remove( ) {
    var elem = document.getElementById("cart_table");
    for (var i = elem.rows.length-1; i >= 0 ; i--) {
        if (elem.rows[i].cells[0].firstChild.checked) {
            elem.removeChild(elem.rows[i]);
        }
    }
}

function removeAll( ) {
    var elem = document.getElementById("cart_table");
    for (var i = elem.rows.length-1; i >= 1 ; i--) {//keep rows[0] which is the title of the table
        elem.removeChild(elem.rows[i]);
    }
}


function multiSubmit( ) {    
	if ( okAfterCheck() ){//validate the form
			//document.form_wishlist.submit(); //one way, get item list from text field; this function is not recommended.
	
			//sendEmail( );//the other way, get item list from table.
	
			postOnline(form_wishlist.name.value, getInfolist());//third way, post to guestbook
			window.alert('Your WishList has been sent to iNetZone. We will contact you soon!');
	
			//refresh this page
			parent.location=parent.location;
	}
}

function sendEmail( ) {
	window.alert('Your WishList Information will be sent to iNetZone by email.');
	
    //make email subject & body
	var mailSubject = "Products wishlist to iNetZone";
	var mailBody = "Now you can send this mail to iNetZone!";

	//add item list & user info to mailBody
	mailBody += getInfolist();

	//sending...
	parent.location='mailto:inetzone42@ihug.com.au?subject='+mailSubject+'&body='+mailBody +' ';
	
}


function postOnline(postName,postBody){
	innerPg.document.post.form_name.value = postName;
	innerPg.document.post.form_message.value = postBody;
	innerPg.document.post.submit()
}



function getInfolist( ){
	var info = "";

	//add item list to infolist
	var elem = document.getElementById("cart_table");
    for (var j = 1; j <=elem.rows.length-1; j++) {
		info = info+"\n; "+elem.rows[j].cells[1].innerText;
    }
	
	//add user info to infolist
	info = info+"\n; "
				+"name:"+form_wishlist.name.value+"\n; "
				+"phone:"+form_wishlist.phone.value+"\n; "
				+"email:"+form_wishlist.email.value+"\n; "
				+"pickup date:"+form_wishlist.pickup_date.value+"\n; "
				+"address:"+form_wishlist.address.value+"\n; "
				+"other:"+form_wishlist.other.value;

	return info;

}

//user info form validation
function okAfterCheck( ){
	var userInfo = form_wishlist.name.value
				+form_wishlist.phone.value
				+form_wishlist.email.value
				+form_wishlist.address.value;
				
	if (userInfo.length<=0){
		alert('Please fill in the form and give us enough info to contact you.');
		return false;
	}else {
		return true;
	}
	
}


function itemNum( ){
	var elem = document.getElementById("cart_table");
	return elem.rows.length-1;
}
