	/*
		purpose	:
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	null
		out		:	
		desc	:	
	*/
	function setLanguage(object,path) {
		var str_lang	=	object.value;
		window.location	=	path+"?_ln="+str_lang;
	}//end of function
	
	function validateEmail(email) {
		var splitted	=	email.match("^(.+)@(.+)$");
		if(splitted == null)
			return false;
		if(splitted[1] != null ) {
			var regexp_user=/^\"?[\w-_\.]*\"?$/;
			if(splitted[1].match(regexp_user) == null) return false;
		}
		if(splitted[2] != null) {
			var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
			if(splitted[2].match(regexp_domain) == null) {
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if(splitted[2].match(regexp_ip) == null) return false;
			}// if
			return true;
		}
		return false;
	}//end of function
	
	/*
		purpose	:	similar to ucwords() of php
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		desc	:	usage --> <string>.toProperCase();
	*/
	String.prototype.ucWords = function() {
		return this.toLowerCase().replace(/\w+/g,function(s){
			return s.charAt(0).toUpperCase() + s.substr(1);
		})
	}//end of function
	/*
		purpose	:	remove selected product from cart
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	null
		out		:	null
		desc	:	
	*/
	function removeFromCart(str_target_path) {
		var bolDelete	=	confirm('Remove selected products from cart?');
		var objForm		=	document.frm_cart;
		if (bolDelete) {
			objForm.action	=	str_target_path;
			objForm.submit();
		}
	}//end of function
	
	/*
		purpose	:	redirect to selected path
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	string	;	path
		out		:	null
		desc	:	
	*/
	function redirect(str_target_path) {
		window.location	=	str_target_path;
	}//end of function
	
	/*
		purpose	:	open new window
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	string	:	file to open
					integer	:	window width
					integer	:	window height
		out		:	null
		desc	:	
	*/
	function openWin(strTargetFile,intWidth,intHeight) {	
		var top;
		var left;
			
		top		=	(screen.height - intHeight) / 2;
		left	=	(screen.width - intWidth) / 2;
		
		window.open(strTargetFile,"DetailWindow","scrollbars=yes,toolbars=no,status=no,width="+
					intWidth+",height="+intHeight+",top="+top+",left="+left);	
	}
	
	/*
		purpose	:	enlarge view of selected product
		date	:	2006-08-24
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	integer	:	picture id
					integer	:	product id
		out		:	null
		desc	:	TODO
	*/
	function enlargePicture(int_picture_id,int_product_id) {
		var str_path	=	'/product/enlarge/?id='+int_picture_id+'&p_id='+int_product_id;
		//alert(str_path);
		openWin(str_path,642,850);
		//TODO
	}
	
	/*
		purpose	:	mark billing and shipping information as same in form
		date	:	2006-09-08
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	object	:	form object
		out		:	null
		desc	:	
	*/
	function coForm(obj_frm) {
		bol_checked	=	obj_frm.frm_check.checked;
		
		if (bol_checked) {
			//bill part --> elements[0] - elements[10]
			//ship part --> 11 to 21
			var j = 11;
			for (var i=0; i<=9; i++) {
				var k	=	j + i;
				obj_frm.elements[k].value	=	obj_frm.elements[i].value;
				//disable ship part
				obj_frm.elements[k].disabled	=	true;
			}
		}
		else if (!bol_checked) {
			for (var i=11; i<=20; i++) {
				//enable ship part
				obj_frm.elements[i].disabled	=	false;
			}
		}
	}//end of function
	
	/*
		purpose	:	validate form
		date	:	2006-09-08
		author	:	Dipesh Nyachhyon <xcurses@hotmail.com>
		version	:	1.0.0
		in		:	array	:	required fields
					array	:	email fields
		out		:	null
		desc	:	
	*/
	function checkForm(arr_reg_fields,arr_email_fields) {
		var int_total_fields	=	arr_reg_fields.length;
		if (arr_email_fields != "")
			var int_total_emails	=	arr_email_fields.length;
		var bol_req_error		=	false;
		var str_req_error		=	"Please fill up the following fields:\n";
		var bol_email_error		=	false;
		var str_email_error		=	"Please enter a valid email address in:\n";
		
		//check required fields
		for (var i=0; i<=int_total_fields-1; i++) {
			if (document.getElementById(arr_reg_fields[i]).value == "") {
				bol_req_error		=	true;
				var str_er_field	=	arr_reg_fields[i].substring(4);
				/* remove underscore (if any) */
				str_er_field		=	str_er_field.replace(/_/g," ");
				/* remove [] (if any) */
				str_er_field		=	str_er_field.replace(/\[/g," ");
				str_er_field		=	str_er_field.replace(/\]/g," ");
				/* remove 'id' (if any) */
				str_er_field		=	str_er_field.replace(/id/g," ");
				str_er_field		=	str_er_field.ucWords();
				str_req_error		+=	"- "+str_er_field+"\n";
			}
		}
		if (bol_req_error) {
			alert(str_req_error);
			return false;
		}
		
		//check email field(s)
		if (!bol_req_error) {
			for (var i=0; i<=int_total_emails-1; i++) {
				if (!validateEmail(document.getElementById(arr_email_fields[i]).value)) {
					bol_email_error		=	true;
					var str_er_field	=	arr_email_fields[i].substring(4);
					str_er_field		=	str_er_field.replace(/_/g," ");
					str_er_field		=	str_er_field.ucWords();
					str_email_error		+=	"- "+str_er_field+"\n";
				}
			}
			if (bol_email_error) {
				alert(str_email_error);
				return false;
			}
		}
	}//end of function
	
	
	function whProductSelect(_v) {
		for(var i=0;i<document.frm_data.elements[0].length;i++)
			document.frm_data.elements[0][i].selected	=	_v;
	}
	
	