
var _ie_  = (document.all) ? true : false;
//var nn6 = (document.getElementById && navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5) ? true : false;
//var nn4 = (!nn6 && !ie && document.layers) ? true : false;

//var prefixObjName = "tbPrefix";
//var numberObjName = "tbNumber";
//var countryObjName = "ddlCountries";
//var prefixObj;
//var numberObj;
//var countryObj;

function show_clbk_popup(url, width, height)
{
	eval("handler = window.open(url, 'tvoice', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
	handler.focus();
}

//Show a popup and return the handle
function show_popup(url, features)
{
	var handler = window.open(url, '', features);
	
	return handler;
}

function autoResizeWindow() {
  try {
    self.focus();
    if (!_ie_) return;
	//return;
	//debugger;
	var compatElement = getCompatElement();
	var clientSize = getClientSize(compatElement);
	var delta = getDeltaSize(compatElement);
	
	//var chkX = document.getElementById("myId").clientWidth;
	//var chkY = document.getElementById("myId").clientHeight;
	if(!window.top.document.getElementById("myId"))
		return;
	
	var chkX = window.top.document.getElementById("myId").clientWidth;
	var chkY = window.top.document.getElementById("myId").clientHeight;
	
	var finalX = chkX + delta.width/2;
	var finalY = chkY + delta.height/2;
	
	//window.resizeTo(finalX, finalY);
	window.top.window.resizeTo(finalX, finalY);
  }
  catch (ex) {}
}

function chat_hide(str) {
  document.all._chatFrame.style.pixelWidth = 0;
  document.all._chatFrame.style.pixelHeight = 0;
  autoResizeWindow();
}

function getCompatElement () {
	var de = window.top.document.documentElement;
	var d = window.top.document.body;

	var who = window.top.document.compatMode;
	return (who == "CSS1Compat" 
		? window.top.document.documentElement
		: window.top.document.body
	);
}

function getClientSize(compatObj) {
	var w = compatObj.clientWidth;
	var h = compatObj.clientHeight;

	return {
		width: w, height: h
	}
}

function getDeltaSize(compatObj) {
	var clientSize_0 = getClientSize(compatObj);
	
	if (window.top._globalSizeDelta == null) {
		window.top._globalSizeDelta = {width: 100, height: 100};
	}
	
	window.top.resizeTo(
		clientSize_0.width + window.top._globalSizeDelta.width, 
		clientSize_0.height + window.top._globalSizeDelta.height
	);
	
	var clientSize_1 = getClientSize(compatObj);
	
	var delta = {
		width:   clientSize_0.width - clientSize_1.width + window.top._globalSizeDelta.width,
		height:  clientSize_0.height - clientSize_1.height + window.top._globalSizeDelta.height
	};
	
	window.top.resizeTo(clientSize_0.width + delta.width, clientSize_0.height + delta.height);
	window.top._globalSizeDelta = delta;
	
	return {
			width:   window.top._globalSizeDelta.width + delta.width,
			height:  window.top._globalSizeDelta.height + delta.height
//			width:   _globalSizeDelta.width + delta.width,
//			height:  _globalSizeDelta.height + delta.height
	};
}

function UpdatePrefix()
{
  obj = GetCountriesObj();
  if (obj == null) return;
  
  var iso2_code = obj.value;
	var prefix = GetCode(iso2_code);
	prefix = "+" + prefix;
	obj = getPrefixObj();
	if (obj != null)	
		obj.value = prefix;
}

//var n;
var p;
var p1;
function ValidatePhone()
{
	numberObj = getNumberObj();
	if (numberObj == null)
		return;
		
	p = p1.value;
	if (p.length == 3)
	{
		pp = p;
		d4 = p.indexOf('(');
		d5 = p.indexOf(')');
		if(d4 == -1)
		{
			pp="(" + pp;
		}
		if(d5 == -1)
		{
			pp = pp + ")";
		}
		numberObj.value = "";
		numberObj.value = pp;
	} // if (p.length == 3)
	
	if(p.length > 3)
	{
		d1 = p.indexOf('(');
		d2 = p.indexOf(')');
		
		if (d2 == -1)
		{
			l30 = p.length;
			p30 = p.substring(0, 4);
			p30 = p30 + ")";
			p31 = p.substring(4, l30);
			pp = p30 + p31;
			numberObj.value = "";
			numberObj.value = pp;
		}
	} // if(p.length > 3)
	
	if (p.length > 5)
	{
		p11 = p.substring(d1 + 1, d2);
		if(p11.length > 3)
		{
			p12 = p11;
			l12 = p12.length;
			l15 = p.length;
			p13 = p11.substring(0, 3);
			p14 = p11.substring(3, l12);
			p15 = p.substring(d2 + 1, l15);
			numberObj.value = "";
			pp = "(" + p13 + ")" + p14 + p15;
			numberObj.value = pp;
		}
		l16 = p.length;
		p16 = p.substring(d2 + 1, l16);
		l17 = p16.length;
		if(l17 > 3 && p16.indexOf('-') == -1)
		{
			p17 = p.substring(d2 + 1, d2 + 4);
			p18 = p.substring(d2 + 4, l16);
			p19 = p.substring(0, d2 + 1);
			pp = p19 + p17 + "-" + p18;
			numberObj.value = "";
			numberObj.value = pp;
		}
	} // if (p.length > 5)
	// KP added October 2007
	if(numberObj.value == '(203)392-5621' ||
           numberObj.value == '(312)987-2054' ||
           numberObj.value == '(773)294-0454' ||
           numberObj.value == '(415)312-3418'
           )
  		numberObj.value = '**********';
	// END KP add
	setTimeout(ValidatePhone, 300);
}

function FormatPhone()
{
	//alert(countryObj);
	//alert(numberObj);
	//alert(countryObj.value);
	
	country = getCountryObj().value;
	
	//alert(country);
	if ((country == "US") ||
		(country == "CA") ||
		(country == "RU"))
	{
		
		//n = m.name;
		p1 = getNumberObj();
		//alert("About to validate");
		ValidatePhone();
	}
}


function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}

// Used by phone formatter
function GetCountriesObj()
{
	if (document.all)
	{
		return document.all["ddlCountries"];
	}
	else
	{
		return document.getElementById("ddlCountries");
	}
}

// Used by phone formatter
function getPrefixObj()
{
	if (document.all)
	{
		return document.all["tbPrefix"];
	}
	else
	{
		return document.getElementById("tbPrefix");
	}
}

// Used by phone formatter
function getNumberObj()
{
	if (document.all)
	{
		return document.all["tbNumber"];
	}
	else
	{
		return document.getElementById("tbNumber");
	}
}

// Used by phone formatter
function getCountryObj()
{
	if (document.all)
	{
		return document.all["ddlCountries"];
	}
	else
	{
		return document.getElementById("ddlCountries");
	}
}

