// ===================================================================
// Author: Xiaobo Zhan
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
//check or uncheck all checkbox with same obj array directed by current checkbox
//-------------------------------------------------------------------
function checkAll(form, objName, allCheck){ 
	if( isArray( form[objName])) {
		for(var i=0;i<form[objName].length;i++){ 
			form[objName][i].checked=allCheck.checked; 
		}
	} else {
		form[objName].checked=allCheck.checked;
	}
}

//-------------------------------------------------------------------
//if these checkboxs are all not checked, display errMsg, return false
//-------------------------------------------------------------------
function requireChecked(form, objName, errMsg) { 
	var hasChecked=false; 
	if( isArray( form[objName])) {
		for(var i=0;i<form[objName].length;i++){ 
			if(form[objName][i].checked){ 
				hasChecked=true;
			} 
		} 
	} else {
		if(form[objName].checked) {
			hasChecked=true;
		}
	}

	if(hasChecked == false){ 
		alert(errMsg);
	} 
	return hasChecked;
}

function requireChecked2(form, objName) { 
	return requireChecked(form, objName, "You must select checkboxs!"); 
}

function isChecked(form, objName) { 
	var hasChecked=false; 
	if( form[objName] == null) return false;
	if( isArray( form[objName])) {
		for(var i=0;i<form[objName].length;i++){ 
			if(form[objName][i].checked){ 
				hasChecked=true;
			} 
		} 
	} else {
		if(form[objName].checked) {
			hasChecked=true;
		}
	}

	return hasChecked;
}


function getCheckedStr(form, objName) { 
	var str="|"; 
	if( form[objName] == null) return str;
	if( isArray( form[objName])) {
		for(var i=0;i<form[objName].length;i++){ 
			if(form[objName][i].checked){ 
				str = str + form[objName][i].value + "|";
			} 
		} 
	} else {
		if(form[objName].checked) {
			str = str + form[objName].value;
		}
	}

	return str;
}
 function add(){
   var obj=document.advertisementForm;
   var keyword=obj.keyword.value;
   var price =obj.price.value;
   if (keyword!=""&&price!=""){
   if(obj.txtBody.value==""){
     obj.txtBody.value=obj.txtBody.value+keyword+":"+price+"\n";
   }else{
     obj.txtBody.value=obj.txtBody.value+keyword+":"+price+"\n";
   }   
   obj.keyword.value="";
   obj.price.value="";
   }
 }
