var winDebug //Debug popup window

/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

//function goBack(){
//	document.location = document.getElementById('RETURN_URL').value
//}

function goBack(){
	var frm = document.createElement("Form");
	frm.name = "PV_Return";
	frm.action = document.getElementById('RETURN_URL').value;
	frm.method = "POST";
	var hdn = document.createElement("Input");
	hdn.type = "Hidden";
	hdn.name = "RestoreState"
	hdn.value = "1";
	frm.appendChild(hdn);
	frm.style.visible="hidden";
	document.body.appendChild(frm);
	frm.submit();
}

function focusLogin(){
try{
	var pw = document.forms[1].TB_PIN
	var login = document.forms[1].TB_LOGIN
	
	if(login.value==''){
		login.focus();
	}else{
		pw.focus();
	}
} catch(e){}
}

function printCSR(id){
	var options = "location=no,menubar=yes,scrollbars=yes,resizable=yes,titlebar=no,toolbar=no"
	window.open('show-sr.aspx?id=' + id,'winPrint',options)
}

function getRadioCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function showServiceDescription(service){
    var winHeight = 200
	var winWidth = 500
	var winLeft = (screen.availWidth - winWidth) / 2;
	var winTop = (screen.availHeight - winHeight) / 2;
	
	var options = "height="+winHeight+",width="+winWidth+",top=" + winTop +",left=" + winLeft + ",location=no,menubar=no,scrollbars=yes,resizable=no,modal=yes,titlebar=no,toolbar=no"
	window.open("showServiceDescription.aspx?service=" + service,"ServiceDescription",options,true)
}


function showPricePopup(productNo,cc){
    var winHeight = 400
	var winWidth = 820
	var winLeft = (screen.availWidth - winWidth) / 2;
	var winTop = (screen.availHeight - winHeight) / 2;
	
	var options = "height="+winHeight+",width="+winWidth+",top=" + winTop +",left=" + winLeft + ",location=no,menubar=no,scrollbars=yes,resizable=no,modal=yes,titlebar=no,toolbar=no"
	if (cc =='')
		window.open("Product-Service.aspx?view=BASIC&PN=" + productNo ,"Prices",options,true)
	else
		window.open("Product-Service.aspx?view=BASIC&PN=" + productNo + "&CC=" +cc,"Prices",options,true)
}

function showHelpPopup(document){
    showPopup("i18npage.aspx?doc=" + document)
}

function showPopup(url){
    var winHeight = 600
	var winWidth = 820
	var winLeft = (screen.availWidth - winWidth) / 2;
	var winTop = (screen.availHeight - winHeight) / 2;
	
	var options = "height="+winHeight+",width="+winWidth+",top=" + winTop +",left=" + winLeft + ",location=no,menubar=no,scrollbars=yes,resizable=no,modal=yes,titlebar=no,toolbar=no"
	return window.open(url ,"help",options)
}


function debug(msg,newWin){
    //opens a popup and writes debug info to it
    try{
        if(!winDebug | newWin){
            winDebug = showPopup('_blank.htm');
        }
        
        winDebug.document.write(msg + '<br>');
    } catch(e){alert('Debug error: ' + e.message);}
}