<!--// $Id: common.js 215 2009-04-20 09:42:14Z evic $ //-->
function select_tab(title_name,content_name,select_n,selected_title_css,noselected_title_css) {
	var obj_title = getElementsByName_iefix('div',title_name);
	var obj_content = getElementsByName_iefix('div',content_name);
	for(i=0;i<obj_title.length;i++)	{
		if (!obj_content[i]) {
			//alert ('the no.' + i+1 + ' content_name not exists');
			return;
		}
		if (i == select_n) {
			obj_title[i].className=selected_title_css;
			obj_content[i].className = "selected_content";
		} else {
			obj_title[i].className=noselected_title_css;
			obj_content[i].className = "noselected_content";
		}
		
	}
}
function getElementsByName_iefix(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if(att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}
function select_category(select_n){
	var title_name = 'category_title';
	var content_name = 'category_content';
	var selected_title_css = 'selected_category_title';
	var noselected_title_css = 'noselected_category_title';
	select_tab(title_name,content_name,select_n,selected_title_css,noselected_title_css)
}
function select_new_arrived(select_n){
	var title_name = 'new_arrived_title';
	var content_name = 'new_arrived_content';
	var selected_title_css = 'selected_new_arrived_title';
	var noselected_title_css = 'noselected_new_arrived_title';
	select_tab(title_name,content_name,select_n,selected_title_css,noselected_title_css)
}

/* 
* ѡѡid= id  value = value 
* 
*/

//	var obj = document.getElementsByTagName("body");
//	obj = obj[0];
//	forbidden_rightbtn(obj);
	


function select_option ( id , value ){
	if (value == '') return;
	var selected_value = value;
	var selected_index = 0;
	for (i=0;i< document.getElementById(id).length;i++){
		if ( document.getElementById(id).options[i].value == selected_value ) {
			selected_index = i;
		}				
	}
	document.getElementById(id).selectedIndex = selected_index;
}


function g(id){
	return document.getElementById(id);
}
function just_number(id){
	g(id).value = g(id).value.replace(/[^\d]/g,'');
}

function change_tr_color(id) {
	overclassName = "td_over";
	defaultclassName = "td_default";
	//var TbRow = document.getElementsByName_iefix(id);
	var TbRow = getElementsByName_iefix('table',id);
	if (TbRow){
		for (var k=0;k<TbRow.length ;k++) {
			for (var i=0;i<TbRow[k].rows.length ;i++ ){
				if (TbRow[k].rows[i].rowIndex%2==1){
					className = defaultclassName;
				} else {
					className = defaultclassName;
				}
				TbRow[k].rows[i].className=className;
				TbRow[k].rows[i].onmouseover=function (){ this.className = overclassName};
				TbRow[k].rows[i].onmouseout=function (){ this.className =  'td_default'};
			}
		}
	} else {
		alert('not exist' + id);
	}
}

function getElementsByName_iefix(tag, name) {
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if(att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}
 // add 2008.09.11 by CY
// if browser is IE then ...
function get_op(){
	if(document.all){
		return 'ie';
	}else{
		return '';	
	}
}
 // replace all blank space of js,like PHP trim();
String.prototype.strtrim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
// search action of all site, rewrite url...
//防注入,过滤特殊字符
function check(inputStr) {
	if (typeof(inputStr) != "string") { return inputStr; } //判断是否是字符串类型
	var tmpValue = inputStr;
    //以下搜索字符串中的特殊字符，如果存在，则替换成""
	while (tmpValue.indexOf(';') > -1) {tmpValue = tmpValue.replace(';',''); }
	while (tmpValue.indexOf('<') > -1) {tmpValue = tmpValue.replace('<',''); }
	while (tmpValue.indexOf('>') > -1) {tmpValue = tmpValue.replace('>',''); }
	while (tmpValue.indexOf('--') > -1) {tmpValue = tmpValue.replace('--',''); }
	while (tmpValue.indexOf(",") > -1) {tmpValue = tmpValue.replace(",",""); }
	while (tmpValue.indexOf("'") > -1) {tmpValue = tmpValue.replace("'",""); }
	while (tmpValue.indexOf("?") > -1) {tmpValue = tmpValue.replace("?",""); }
	while (tmpValue.indexOf("(") > -1) {tmpValue = tmpValue.replace("(",""); }
	while (tmpValue.indexOf(")") > -1) {tmpValue = tmpValue.replace(")",""); }
	while (tmpValue.indexOf("`") > -1) {tmpValue = tmpValue.replace("`",""); }
	while (tmpValue.indexOf('"') > -1) {tmpValue = tmpValue.replace('"',''); }
	while (tmpValue.indexOf('*') > -1) {tmpValue = tmpValue.replace('*',''); }
	while (tmpValue.indexOf('$') > -1) {tmpValue = tmpValue.replace('$',''); }
	while (tmpValue.indexOf('#') > -1) {tmpValue = tmpValue.replace('#',''); }
	while (tmpValue.indexOf('!') > -1) {tmpValue = tmpValue.replace('!',''); }
	while (tmpValue.indexOf('~') > -1) {tmpValue = tmpValue.replace('~',''); }
	while (tmpValue.indexOf('%') > -1) {tmpValue = tmpValue.replace('%',''); }
	while (tmpValue.indexOf('/') > -1) {tmpValue = tmpValue.replace('/',''); }
	while (tmpValue.indexOf('\\') > -1) {tmpValue = tmpValue.replace('\\',''); }
	while (tmpValue.indexOf(':') > -1) {tmpValue = tmpValue.replace(':',''); }
	while (tmpValue.indexOf('|') > -1) {tmpValue = tmpValue.replace('|',''); }
	return tmpValue;  //重新显示更改后的变量
}

function search_action(){
	var keywordStr = g('keyword').value.strtrim();
	var keyword = check(keywordStr);
	var act = g('act').value.strtrim();
	var orderby = g('orderby').value;
	var search_type = g('search_type').value;
	if(keyword.length >0){
		document.location.href = "/search-products--"+keyword+"--"+act+"--"+orderby+"--"+search_type+"--1.html";
	}
}
// press Enter to search keyword, only use in IE
function enter2search(){
	if(get_op() == 'ie'){
		if(window.event.keyCode==13){
			search_action();
		}
	}
}

function sel_change(){
	//alert(g('menu1').value);
	document.location = g('menu1').value;
}

// -- end 
