﻿var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
	alert('您需要安装SKYPE软件！')
    if((navigator.language && navigator.language.indexOf("ja") != -1) || (navigator.systemLanguage && navigator.systemLanguage.indexOf("ja") != -1) || (navigator.userLanguage && navigator.userLanguage.indexOf("ja") != -1)) {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops_ja.html";
    } else {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops.html";
    }
	var windowName = "oops";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isSkypeInstalled()',
        'on error resume next',
        'Set oSkype = CreateObject("Skype.Detection")',
        'isSkypeInstalled = IsObject(oSkype)',
        'Set oSkype = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function skypeCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        if(typeof(skypeMime) == "object") {
            return true;
        } else {
            return oopsPopup();
        }
    } else {
        if(isSkypeInstalled()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return oopsPopup();
}

function loadDetection() {
    if(document.getElementById && document.getElementsByTagName) {
        if (window.addEventListener) window.addEventListener('load', addDetection, false);
        else if (window.attachEvent) window.attachEvent('onload', addDetection);
    }
}

function addDetection() {
    var pageLinks = document.getElementsByTagName("a");
    for (var i=0; i < pageLinks.length; i++) {
        if(pageLinks[i].childNodes[0] && pageLinks[i].childNodes[0].src) {
            if((pageLinks[i].childNodes[0].src.indexOf('download.skype.com\/share\/skypebuttons') != -1 || pageLinks[i].childNodes[0].src.indexOf('mystatus.skype.com') != -1) && (typeof(pageLinks[i].onclick) == "undefined" || pageLinks[i].onclick == null)) {
                pageLinks[i].onclick = function sChk() { return skypeCheck(); }
            }
        }
    }
}

loadDetection();


function SendMSNMessage(name){ 
//Send a message through MSN , only for IE 
//and you must have installed MSN or Window Message 
MsgrObj.InstantMessage(name); }

function AddMSNContact(name){ 
//Add a people to MSN , only for IE 
//and you must have installed MSN or Window Message 
MsgrObj.AddContact(0, name);}

function gID(i) {
	return document.getElementById(i);	
}

function validateSearchForm() {
	var s = gID("query");
	if (s.value == "" || s.value == "产品关键字搜索 →") {
		alert("错误:\n\n - 请输入查询产品的关键字");
		s.focus();
		return false;
	} else {
		return true;
	}
}

function initInputs(tagname) {
	var inputs = document.getElementsByTagName(tagname);
	var defaultValues = new Array();
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "text" || inputs[i].type == "textarea") {
			defaultValues[inputs[i].id] = inputs[i].value;
			// focus
			inputs[i].onfocus = function() {
				if (this.value == defaultValues[this.id]) {
					this.value = "";
				}
			}
			// blur
			inputs[i].onblur = function() {
				if (this.value == "") {
					this.value = defaultValues[this.id];
				} else {
					// tidy the text field
					this.value = trim(this.value);	
				}
			}
		}
	}
}

function insertFlash(elm, url, w, h,pic,link,text,textheight) 
{
	if (!document.getElementById(elm)) return;
	if(arguments.length>4)
	{
		var fh = h - textheight;
	}
	var str = '';
	str += '<object ID="focus_flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ w +'" height="'+ h +'">';
	str += '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+url+'"><param name="quality" value="high"><param name="bgcolor" value="#FFFFFF">';
	str += '<param name="menu" value="false">';
	
	if(arguments.length>4)
	{
		str += '<param name="FlashVars" value="pics='+pic+'&links='+link+'&texts='+text+'&borderwidth='+w+'&borderheight='+fh+'&textheight='+textheight+'">';
		str += '<embed ID="focus_flash" src="'+url+'" wmode="opaque" FlashVars="pics='+pic+'&links='+link+'&texts='+text+'&borderwidth='+w+'&borderheight='+fh+'&textheight='+textheight+'" menu="false" bgcolor="#C5C5C5" quality="high" width="'+ w +'" height="'+ h +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';	
	}
	else
	{   str += '<param name="wmode" value="transparent">';
		str += '<embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" wmode="transparent"></embed></object>'
	}
	document.getElementById(elm).innerHTML = str;
}
//flv insert
function insertflv(elm,swf_width,swf_height,files,texts) 
{
	var strs=''
	strs += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ swf_width +'" height="'+ swf_height +'">';
	strs += '<param name="movie" value="/template/images/flv.swf"><param name="quality" value="high">';
	strs += '<param name="menu" value="false"><param name="allowFullScreen" value="true" />';
	strs += '<param name="FlashVars" value="vcastr_file='+files+'&vcastr_title='+texts+'">';
	strs += '<embed src="/template/images/flv.swf" allowFullScreen="true" FlashVars="vcastr_file='+files+'&vcastr_title='+texts+'" menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	document.getElementById(elm).innerHTML = strs;
}
