

var sFCKBase = 'fckeditor/';
var oEditor;
var last_open_win = 0;
var last_open_type = -1;
var last_bt="bt_0_0";
var res = new Array(8);
res[0] = "res/detail.php?product_id=";
res[1] = "res/parms.php?product_id=";
res[2] = "res/res_music.php?product_id=";
res[3] = "res/res_video.php?product_id=";
res[4] = "res/res_driver.php?product_id=";
res[5] = "res/res_fireware.php?product_id=";
res[6] = "res/res_photo.php?product_id=";
res[7] = "res/res_file.php?product_id=";
res[8] = "res/product_relation.php?product_id=";
function LTrim(str) 
{ 
	var i; 
	for(i=0;i<str.length;i++) 
	{ 
	if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
	} 
	str=str.substring(i,str.length); 
	return str; 
} 
function RTrim(str) 
{ 
	var i; 
	for(i=str.length-1;i>=0;i--) 
	{ 
	if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break; 
	} 
	str=str.substring(0,i+1); 
	return str; 
} 
function Trim(str) 
{ 
	return LTrim(RTrim(str)); 
}
function IsInteger(szInput)
{
	szInput=String(szInput);
	var oRegex=/^[+-]?(0|([1-9][0-9]*))$/i
	return oRegex.test(szInput);
}
function isEmail(str)
{ 
	res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/; 
	var re = new RegExp(res); 
	return !(str.match(re) == null); 
} 
function checkregform(obj)
{

	if(Trim(obj.username.value).length==0)
	{
		alert("账号不能为空");
		return false;
	}
	if(Trim(obj.userpass.value).length==0)
	{
		alert("密码不能为空");
		return false;
	}
	if(Trim(obj.userpass1.value).length==0)
	{
		alert("请确认密码");
		return false;
	}
	if(obj.userpass1.value!=obj.userpass.value)
	{
		alert("两次输入密码不相同");
		return false;
	}
	if(Trim(obj.email.value).length!=0&&
		(!isEmail(obj.email.value)))
	{
		alert("电子邮箱格式有错误");
		return false;
	}
	return true;
	
}
function runback()
{
	history.back();
}
function get_favorite_cat()
{
	favorite_cat_string = "" ; 
	obj = document.getElementById("form1").favorite_cat;
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].checked)
		{
			favorite_cat_string+=obj[i].value + ",";
		}
	}
	return favorite_cat_string;
}


function attach_editor(id)
{
	custom_editor = new FCKeditor(id) ;
	custom_editor.ReplaceTextarea();
}

function FCKeditor_OnComplete( editorInstance )
{
	oEditor = FCKeditorAPI.GetInstance('content','100%','600','blog_add');

}
function display_window(id,type,index)
{
	
	if(index==last_open_win&&last_open_type==type)
	{
		obj = document.getElementById("product_arg_viewer_"+index);
		obj.style.display ="none";
		obj = document.getElementById("bt_"+type+"_"+index);
		obj.className="" ;
		last_open_type = -1;
	}
	else
	{
		obj = document.getElementById("product_arg_viewer_"+last_open_win);
		obj.style.display ="none";
		obj = document.getElementById(last_bt);
		obj.className ="";
		obj = document.getElementById("bt_"+type+"_"+index);
		obj.className="current_btn" ;
		last_bt = "bt_"+type+"_"+index;
		last_open_win = index;
		last_open_type = type
		obj = document.getElementById("product_arg_viewer_"+index);
		if(type==6||type==2||type==3)
		{
			send_request(res[type]+id+"&iframe="+index,showphoto);
		}
		else
		{
			obj.innerHTML="<iframe scrolling='auto' width='100%' height='250' frameborder='0' src='"+res[type]+id+"&iframe="+index+"'></iframe>";
			showobj = obj;
			
		}
		obj.style.display="block";
	}
		
	
}
var showobj;
function showphoto()
{
	if (http_request.readyState == 4) 
	{ 
	
		if (http_request.status == 200) 
		{
			obj.innerHTML = http_request.responseText;
			tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
			imgLoader = new Image();// preload image
			imgLoader.src = tb_pathToImage;
	
		} 
		else { 
			alert("您所请求的页面有异常。");
		}
	}
}
function imgerr(obj,url){if(!obj)return;obj.style.visibility='hidden';obj.src=url;obj.onload=function(){this.style.visibility='';};}

function user_favorite(product_id)
{
	send_request("/user_favorite.php?product_id="+product_id,change_test);
}
function change_test()
{
	document.getElementById("is_favorite").innerHTML= "收藏";
}

function clear_img(obj)
{
	try
	{
	document.getElementById(obj).style.display = "none";
	document.getElementById(obj+"_value").value = "";
	}
	catch(e)
	{
	}
}