/**
 * 陈奎
 * 	公司黄页
 */
$(document).ready(function(){

	$("#changeModel").click(function(){
		$("#model").show();
	});
	$("#reset").click(function(){
		$("#model").hide();
	});
	
	$("#corp_cat_stat").children('.sortk4').css('display','none');
	$("#corp_cat_stat .sortk1").each(function(i){
		var tip = $(this).attr('id');
		$(this).click(function(){
			var display = $('.'+tip).css('display');
			if(display == 'none')
			{
				 $('.'+tip).css('display','block');
				 $('#'+tip).addClass('sortk2');
			}
			else
			{
				 $('.'+tip).css('display','none');
				 $('#'+tip).removeClass('sortk2');
			}
		});
	});
	
});
/**
 * 添加浏览器收藏夹
 * @param {} sURL
 * @param {} sTitle
 */
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function changecss(tmpl) {
	var csshref=$("#tmpl").attr("href")
	//取得skin的css链接
	var type = 'yellowpage' + tmpl;
	csshref=csshref.replace(/yellowpage[0-9]/g,type); //把原来路径的style1替换成我们自己的str
	$("#tmpl").attr("href",csshref)  //改变一下href属性其实这里已经完成
	$('#modelType').val(tmpl);
}

function changeModel(corpid)
{
	var tmpl = $('#modelType').val();
	var param = {'corpid':corpid, 'tmpl':tmpl};
	$.ajax({
			url:        '/yellow/corp/corp_tmpl_p.php',
		    type:		'post',         //数据发送方式
		    dataType:	'json',
		    data:		param,
		    success:    function(data) { 
		    	if(data.errno == 0){
		    		window.location.reload();
		    	}
		    }, 
		    error: function(){
		    	alert('网络错误,请稍后操作');
		    }
		});
}

/**
 * 页面跳转
 * @param {} url
 */
function goto(url){
	window.location.href = url;
}
/**
 * 公司页跳转
 * @param {} corpid
 */
function profileUrl(domain){
	window.location.href =  '/yellow/corp/corp_profile.php?domain=' + domain;
}
/**
 * 黄页公司附加信息页跳转
 * @param {} corpid	公司id
 * @param {} stype	附加信息类型
 */
function extUrl(domain, stype){
	window.location.href = '/yellow/corp/corp_ext_index.php?domain=' + domain + '&stype=' + stype + '#a' + stype;
}
function profileEdit(domain, mtype){
	window.location.href = '/yellow/corp/corp_profile_modify.php?domain=' + domain + '&mtype=' + mtype;
}
/**
 * 页面定时跳转
 * @param {} secs	时间
 * @param {} surl	跳转url
 */
function countDown(secs,surl)  
 {  
 	secs--;
 	if(secs > 0){
 		setTimeout("countDown("+secs+",'"+surl+"')",1000);//设定超时时间
 	}else{
 		window.location.href=surl;  
 	}
 }  
 /**
  * 打开证书图片显示层
  * @param {} img
  */
 function openCertLayer(img){
	$('#certImg').attr('src', img);
	$("#imgDiv").dialog(
		{ 
		  title: '认证证书',
		  height: 625,    
          width: 550,    
          modal: true,
          hide: 'slide',
          overlay: {    
                backgroundColor: 'black',    
                opacity: 0.5    
          }
		}
	);
}
/**
 * 关闭图片显示层
 */
function closeCertLayer(){
	$('#imgDiv').dialog('close');
}
/**
 * 公司证书效果显示，当鼠标移上去的效果
 * @param {} certid	证书id
 */
function certMouseOver(certid){
	$('#cert' + certid).attr('class','imgkuang81');
	$('#cpic' + certid).show();
}
/**
 * 公司证书效果显示，当鼠标移走的效果
 * @param {} certid
 */
function certMouseOut(certid){
	$('#cert' + certid).attr('class','imgkuang8');
	$('#cpic' + certid).hide();
}
/**
 * 更新公司联系信息
 */
function updateContact(){
	window.location.href  = '/ucenter/corp/corp_info.php'; 
}
/**
 * 公司附加信息处理,修改或添加
 * @param {} corpid
 * @param {} extid
 * @param {} stype
 */
function updateExt(domain, extid, stype){
	if(stype == 100){
		window.location.href = '/yellow/corp/corp_cert_modify.php?domain=' + domain + '&extid=' + extid;
	}else{
		window.location.href = '/yellow/corp/corp_ext_modify.php?domain=' + domain + '&extid=' + extid + '&stype=' + stype;
	}
}
/**
 * 删除附加信息
 * @param {} corpid
 * @param {} stype
 */
function deleteExt(corpid, extid, stype){

	if(confirm("您确定要删除选中的数据！")){
		var param = {"corpid":corpid, "extid": extid, "stype": stype }; 
		$.ajax({
			url:        '/yellow/corp/corp_ext_login_p.php',
		    type:		'post',         //数据发送方式
		    dataType:	'json',
		    data:		param,
		    success:    function(data) { 
		    	if(data.errno == 0){
		    		if (stype == 104) {
		    			alert('删除成功案例成功');
		    		}else if(stype == 105){
		    			alert('删除公司动态成功');
		    		}else{
		    			alert('删除认证证书成功');
		    		}
		    		window.location.reload();
		    	}
		    }, 
		    error: function(){
		    	alert('网络错误,请稍后操作');
		    }
		});
	}
	else{
		return false;
	}
}
/**
 * 将公司加入收藏
 * @param {} domain
 * @param {} stype
 */
function addCollection(accountid,corpid){

	var param = {"corpid":corpid, "accountid":accountid}; 
	$.ajax({
		url:        '/yellow/corp/my_collection_a.php',
	    type:		'post',         //数据发送方式
	    dataType:	'json',
	    data:		param,
	    success:    function(data) { 
	    	alert(data.msg);
	    } ,
	    error: function(){
		    alert('网络错误,请稍后操作');
		  }
	});
}
/**
 * 
 * 公司附加信息查看，目前只有公司动态与成功案例的查看
 * @param {} corpid	公司id
 * @param {} id			附加信息id
 * @param {} stype	附加信息类型
 * @param {} index	当前页
 */
function extView(domain, extid, stype, index){
	window.location.href = '/yellow/corp/corp_ext_view.php?domain=' + domain + '&extid=' + extid + '&stype=' + stype + '&index=' + index;
}
/**
 * 返回黄页公司附加信息页面
 * @param {} corpid
 * @param {} stype
 */
function backToExt(domain, stype){
	window.location.href = '/yellow/corp/corp_ext_index.php?domain=' + domain + '&stype=' + stype;
}

function changeAnchor(stype){
	
	$("a[id^='tree']").each(function(){
		$(this).attr("class","lk3");
	});
	$("div[id^='dtree']").each(function(){
		$(this).attr("class","nav1");
	});
	$("#tree" + stype).attr("class","lk4");
	$("#dtree" + stype).attr("class","nav2");
	$("#location").html(">> " + $("#tree" + stype).html());
}

function openCertLayer(imgsrc)
{
	var image=new Image(); 
	image.src = imgsrc; 
	var dick=setInterval(function(){
		if(image.complete){
			clearInterval(dick);
			var width = image.width;  
			$('#certimg').attr("src",imgsrc);
			$('#certimg').attr("width",width);
		 	dialog("认证证书","id:testID","520px","auto","id");
		}
	},100);
}

function ImgError(source){ 
    source.src = "http://jic.b2b.makepolo.com/img/small_none.png"; 
    source.onerror = ""; 
    return true; 
} 
