﻿/*------------- san pham ------------------*/
function check_all()	{
	for ( i=0;i < document.fProduct.elements.length ; i++ ){
		if (document.fProduct.elements[i].type=="checkbox" && document.fProduct.elements[i].name!="all"){
			row_id = 'item'+document.fProduct.elements[i].value;
		}else{
			row_id="";
		}
		
		if ( document.fProduct.all.checked==true ){
			document.fProduct.elements[i].checked = true;
			if (row_id!="" ){
				getobj(row_id).className = "View2 col_select";
			}
		}
		else{
			document.fProduct.elements[i].checked  = false;
			if (row_id!="" ){
				if (i%2==0)
					getobj(row_id).className = "View2 col2";
				else
					getobj(row_id).className = "View2 col1";
			}
		}
		
	}
}

function select_list(row_id)	{
	cur_class = getobj(row_id).className;
	if (cur_class=="View2 col_select"){
		getobj(row_id).className ="View2 col1";	
		
	}else{
		getobj(row_id).className = "View2 col_select";
	}

}

function selectedProduct(){
	var num_count = document.fProduct.length;

	for (i=0;i<num_count;i++){
		if (document.fProduct.elements[i].checked){
			return true;
		}
	}
	alert(mess_error['please_chose_item']);
	return false;
}
	
	
function doSubmitProduct(action) {
	if (selectedProduct()){
		document.fProduct.submit();
	}

}

/* ------------ DoAddCart -----------------*/
function DoAddCart(){
	var len = document.fProduct.ch_id.length;
	var count = 0;
	var aList = new Array;
	if (len>1){
		for (i=0;i<len;i++)	{
			if (document.fProduct.ch_id[i].checked==true){
				aList.push(document.fProduct.ch_id[i].value);
				count=count+1;
			}
		}
	}else{
		if (document.fProduct.ch_id.checked==true){
			aList.push(document.fProduct.ch_id.value);
			count=count+1;
		}	
	}
	
	if (count==0){ alert (mess_error['please_chose_item']) }
	else {
		p_id = aList.join(',');	
		location.href='?'+cmd+'=mod:product|act:cart|do:add|pID:'+p_id;	
	}
}

/* ------------ DoWishList -----------------*/
function do_AddWishList(mem_id,p_id,lang){

	if (mem_id==0){
		alert (mess_error['error_only_member']);
	}else{
		
		key='id,mem_id,action,lang';
		value = p_id+','+mem_id+',add,'+lang;
		url = 'modules/product/ajax/_wishlist.php';
		sendReq(url,key ,value,'ext_ajax_mess');
	}
}

function DoWishList(mem_id,action,lang){
	var len = document.fProduct.ch_id.length;
	var count = 0;
	var aList = new Array;
	if (mem_id==0){
		alert (mess_error['error_only_member']);
	}else{
		if (len>1){
			for (i=0;i<len;i++)	{
				if (document.fProduct.ch_id[i].checked==true){
					aList.push(document.fProduct.ch_id[i].value);
					count=count+1;
				}
			}
		}else{
			if (document.fProduct.ch_id.checked==true){
				aList.push(document.fProduct.ch_id.value);
				count=count+1;
			}	
		}
		
		if (count==0){ alert (mess_error['please_chose_item']) }
		else {
			p_id = aList.join('-');	
			key='id,mem_id,action,lang';
			value = p_id+','+mem_id+','+action+','+lang;
			url = 'modules/product/ajax/_wishlist.php';
			sendReq(url,key ,value,'ext_ajax_mess');
		}
	}
	
}

function show_comment(id,p,lang) {
	key='id,p,lang';
	value = id + ',' + p + ',' + lang;
	url ='modules/product/ajax/_show_comment.php';
	
	obj=getobj('ext_comment');
	els = dom ? obj.style : obj;
 	if (dom){
	   els.display = "";
	} else if (ns4){
			els.display = "show";
	}
	
	sendReq(url,key ,value,'ext_comment');
}

function del_item(theURL) {
   if (confirm(mess_error['are_you_sure_del'])) {
			window.location.href=theURL;
	 }
	 else {
			alert ('Phew~');
	 } 
}

function selected_item(){
		var name_count = document.manage.length;
		for (i=0;i<name_count;i++){
			if (document.manage.elements[i].checked){
				return true;
			}
		}
		alert(mess_error['please_chose_item']);
		return false;
	}
	
function del_selected(action) {
		if (selected_item()){
			question = confirm(mess_error['are_you_sure_del'])
			if (question != "0"){
				document.manage.action=action;
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	
}


function do_submit(action) {
	document.manage.do_action.value=action;
	if (action=="del"){
		if (selected_item()){
			question = confirm(mess_error['are_you_sure_del'])
			if (question != "0"){
				document.manage.submit();
			}else{
			  alert ('Phew~');
		    }
		}
	}else{
		document.manage.submit();
	}
	
}
	
function checkall()	{
	for ( i=0;i < document.manage.elements.length ; i++ ){
		if (i>0 && document.manage.elements[i].type=="checkbox"){
			row_id = 'row_'+document.manage.elements[i].value;
		}else{
			row_id="";
		}
		
		if ( document.manage.all.checked==true ){
			document.manage.elements[i].checked = true;
			if (row_id!="" ){
				getobj(row_id).className = "row_select";
			}
		}
		else{
			document.manage.elements[i].checked  = false;
			if (row_id!="" ){
				if (i%2==0)
					getobj(row_id).className = "row1";
				else
					getobj(row_id).className = "row2";
			}
		}
		
	}
}

function select_row(row_id)	{

	cur_class = getobj(row_id).className;
	if (cur_class=="row_select"){
		getobj(row_id).className ="row1";	
	}else{
		getobj(row_id).className = "row_select";
	}

}

function load_image(src)
{ 
	var subImages = document.getElementById('divImage').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			document.getElementById('divImage').appendChild(img);			
		}else img = subImages[0];
		
		img.src = src;

}
