﻿function wopen(wURL, wName, win_X, win_Y) 
{

	var clientScreenX = screen.width;
	var clientScreenY = screen.height;
	var wFeature = "";
	wFeature += "width=" + win_X + ",";
	wFeature += "height=" + win_Y + ",";
	wFeature += "left=" + ((clientScreenX - win_X) / 2) + ",";
	wFeature += "top=" + ((((clientScreenY - win_Y) / 4) * 3) / 2) + ",";
	wFeature += "channelmode=no,";
	wFeature += "directories=no,";
	wFeature += "fullscreen=no,";
	wFeature += "location=no,";
	wFeature += "menubar=no,";
	wFeature += "resizable=no,";
	wFeature += "scrollbars=no,";
	wFeature += "status=no,";
	wFeature += "titlebar=no,";
	wFeature += "toolbar=no";
	return window.open(wURL, wName, wFeature);
      
}

function voipopen(wURL, wName, win_X, win_Y) 
{

	var clientScreenX = screen.width;
	var clientScreenY = screen.height;
	var wFeature = "";
	wFeature += "width=" + win_X + ",";
	wFeature += "height=" + win_Y + ",";
	wFeature += "left=" + ((clientScreenX - win_X) / 2) + ",";
	wFeature += "top=" + ((((clientScreenY - win_Y) / 4) * 3) / 2) + ",";
	wFeature += "channelmode=no,";
	wFeature += "directories=no,";
	wFeature += "fullscreen=no,";
	wFeature += "location=no,";
	wFeature += "menubar=no,";
	wFeature += "resizable=no,";
	wFeature += "scrollbars=no,";
	wFeature += "status=no,";
	wFeature += "titlebar=no,";
	wFeature += "toolbar=no";
//	alert(wURL);
	return window.open(wURL, wName, wFeature);
      
}


function webcall(idstr,phone_number,ext_number)
{
 
 zone_code_part=phone_number.substring(1,2);  
 //alert("zone_code_part="+zone_code_part);
 phone_number_part=phone_number.substring(2,phone_number.length); 
 //alert("phone_number_part="+phone_number_part);
 sha1_salt="886" + zone_code_part + phone_number_part + ext_number + "886" + zone_code_part + phone_number_part + ext_number + "chyp1288";
 sha1_salt_str="salt=" + sha1_salt;
 
 initAJAX(idstr, 'POST', 'http://hipage.hinet.net/voip/hex_sha1_js.asp', sha1_salt_str);
 
 checksum=document.getElementById(idstr).value;
 //alert("checksum=" + checksum);
 urlstr="http://203.160.250.152/chyp/index.php?phone=886" + zone_code_part + phone_number_part + "&ext=" + ext_number + "&checksum=" + checksum;

 wopen(urlstr, 'webcall', 328, 260);
}

//webcall 改為電話先查詢後再撥
function voipcall(origarea,user1)
{
 
 urlstr="/voip/voipcall.asp?origarea=" + origarea + "&user1=" + user1;
 
//alert(urlstr);

 voipopen(urlstr, 'webcall', 328, 260);
}

//webcall 改為電話先查詢後再撥
function fvoipcall(origarea,seq)
{
 
 urlstr="/voip/voipcall.asp?origarea=" + origarea + "&seq=" + seq;
 
// alert(urlstr);

 voipopen(urlstr, 'webcall', 328, 260);
}


function initAJAX(elementID, httpMethod, httpURL, httpParameters) {

	var http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
			}
		}
	}
	if (! http_request) {
		alert("Cannot an XMLHTTP instance.");
		return false;
	}

	http_request.onreadystatechange = function() {
		alertContents(elementID, http_request);
	};

	switch (httpMethod) {
		case "GET":
			http_request.open("GET", ((httpParameters != null) ? (httpURL + "?" + httpParameters) : (httpURL)), true);
			http_request.send(null);
			break;
		case "POST":
			http_request.open("POST", httpURL, false); //true -> false
			http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http_request.setRequestHeader("Content-length", httpParameters.length);
			http_request.setRequestHeader("Connection", "close");
			http_request.send(httpParameters);
			break;
		default:
			break;
	}

}

function alertContents(elementID, httpState) {

	if (httpState.readyState == 4) {
		if (httpState.status == 200) {
			document.getElementById(elementID).value = httpState.responseText;
			//alert("ok!");
		}
		else {
			alert("There was a problem with the request.");
		}
	}

}