function isWin () { return (navigator.appVersion.indexOf ("Win") != -1); }
function isMac () { return (navigator.appVersion.indexOf ("Mac") != -1); }
function isIE () { return (navigator.appName.indexOf ("Explorer") != -1); }
function isNS () { return (navigator.appName.indexOf ("Netscape") != -1); }


function isWindowClosed (o) { var s = navigator.userAgent; return (!o ? true : ((isWin () && ((s.indexOf ("Gecko") != -1) || (s.indexOf ("MSIE 4") != -1))) ? o.closed : (typeof o.document != "object"))); }

function toOpener (s) { var r = isWindowClosed (window.opener); if (!r) window.opener.location.href = s; return (r); }


function searchBlock(form)
{
 	if(form.price.value=='' && form.system.value==''  && form.brand.value=='' )
	{
		alert('請選擇搜尋條件'); 
		return false;
	}
	return true;
}
		
function flashCallPhone(id)
{
	document.location = '/channel?chid=114&pid='+id;	
}

function flashClickAD()
{
	
	window.open('/channel?chid=222','flashSearch','top=0,left=0,location=no,width=1024,height=750,left=200,scrollbars=yes,resizable=no,status=no');
}

function flashCallSearchPhone(id)
{
	var isClosed = true;
	isClosed = isWindowClosed(window.opener);
	
	if(isClosed)
	{
		var newWin = window.open('/channel?chid=114&pid='+id,'newwindow');
		newWin.focus();
		
	}else{
		
		opener.location = '/channel?chid=114&pid='+id;	
		opener.focus();
	}
}

	
function addCompareNoSelected()
{
	alert("請先加入欲比較的手機");
	document.location.replace('/channel?chid=32'); 
	return false;	
}

function addCompareTooLess()
{
	alert("請選擇2支以上的手機進行比較");
	document.location.replace('/channel?chid=32');
	return false;	
}

function ajaxObj()
{
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
      try {
        // 新版的 IE
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          // 舊版的 IE
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }
    return http_request;	
}

function addCompare(id)
{
    http_request = ajaxObj();
    http_request.onreadystatechange = function() { addCompareResponse(http_request); };                                      
	http_request.open('GET', '/cellphoneMallFeatures/addCompare/'+id, true);
	http_request.send(null);
	
}

function addCompareResponse(http_request)
{
	if(http_request.readyState == 4){
		
		if(http_request.status ==200)		
			alert(http_request.responseText);				
		else			
			alert('AJAX ERROR!');		
		
	}	
}

function goCompare()
{
    http_request = ajaxObj();
    http_request.onreadystatechange = function() { goCompareResponse(http_request); };                                      
	http_request.open('GET', '/cellphoneMallFeatures/goCompare/', true);
	http_request.send(null);
	
}

function goCompareResponse(http_request)
{
	
	if(http_request.readyState == 4){
		
		if(http_request.status ==200){
		
			if(http_request.responseText!='true')
				alert(http_request.responseText);
			else
				document.location.replace('/channel?chid=121');
				
		}else{			
			alert('目前無法提供服務!請稍後再試。');
		}	
			
		
	}	
}


function ajaxCustomerSearchPhone(id)
{
	if(id==''){ document.getElementById('phonetype').innerHTML =''; alert('請選擇手機廠牌');  return false; }
	document.getElementById('phonetype').innerHTML = "處理中請稍待...";
    http_request = ajaxObj();
    http_request.onreadystatechange = function() { goAjaxCustomerSearchPhone(http_request); };                                      
	http_request.open('GET', '/cellphoneMallFeatures/cusomterAjaxGetPhone/' + id , true);
	http_request.send(null);	
	
}
function goAjaxCustomerSearchPhone(http_request)
{
	
	if(http_request.readyState == 4){
		
		if(http_request.status ==200){

			document.getElementById('phonetype').innerHTML = http_request.responseText;
				
		}else{			
			alert('目前無法提供服務!請稍後再試。');
		}	
			
		
	}	
}


function ajaxCustomerGetResult(id)
{
	if(id==''){ document.getElementById('result').innerHTML =''; alert('請輸入型號');  return false; }
	document.getElementById('result').innerHTML = "處理中請稍待...";
    http_request = ajaxObj();
    http_request.onreadystatechange = function() { goAjaxCustomerGetResult(http_request); };                                      
	http_request.open('GET', '/cellphoneMallFeatures/cusomterAjaxGetResult/' + id , true);
	http_request.send(null);	
	
}
function goAjaxCustomerGetResult(http_request)
{
	
	if(http_request.readyState == 4){
		
		if(http_request.status ==200){

			if(http_request.responseText == 'false') 
			{
				document.getElementById('result').innerHTML = '';
				alert('無類似型號，請重新輸入'); return false;	
			}else{
				document.getElementById('result').innerHTML = http_request.responseText;
			}	
		}else{			
			alert('目前無法提供服務!請稍後再試。');
		}	
			
		
	}	
}



	function openTrial( trialUrl )
	{			
			objWin = window.open(trialUrl,'emomeOpenWin','width=250,height=100,location=0,menubar=0,toolbar=0,personalbar=0,status=0,scrollbars=0,resizable=0,left=0,top=0');
			objWin.focus();
	}
