// SMCrunch2 Version 2.0.1, Copyright (C) Smart Media Ltd 2001-2005. All Rights Reserved.
//
// !!! Note: JScript by default
//
/// (c) Copyright Smart Media Limited, 2008-2009.
///
///This Software is provided under a license and may not be modified, copied or altered in any
///way by Licensee's own personnel or by any third party. This Software or parts of it,
///or its documentation may not be provided, copied, printed out or otherwise made available to
///any other person. Any attempt to copy, modify or reverse engineer the Software is strictly
///prohibited.
///
///This Software may only be used on the equipment it is licensed for.
///
///Title, copyright and all other proprietary rights in the Software and the Documentation and all
///parts and copies thereof shall remain vested with Smart Media Limited.
///
///This Software and information in it is subject to change without notice.
gresValue = ''; 
function createXMLHttp()
{
if( typeof XMLHttpRequest != 'undefined' )
{
return new XMLHttpRequest();
}
else if( window.ActiveXObject )
{
var aVersions = [ "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
for( var i=0; i< aVersions.length; i++ )
{
try
{
var oXmlHttp = new ActiveXObject(aVersions[i]);
return oXmlHttp;
}
catch(e)
{
}
}
}
return null;
}
function xmlhttpGet(url)
{
var xmlhttp = createXMLHttp();
if( xmlhttp != null )
{
xmlhttp.open('GET', url, false);
xmlhttp.send(null);
var status = xmlhttp.status;
if( status == 200 )
{
var ret = xmlhttp.responseText;
if( ret != null )
{
return ret;
}
}
}
}
function xmlhttpPost(url, post, statustext)
{
xmlhttp = createXMLHttp();
if( xmlhttp != null )
{
if(statustext)
{
xmlhttp.onreadystatechange = function()
{
displayReadyStateStatus(statustext);
}
xmlhttp.open('POST',url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(post);
}
else
{
xmlhttp.open('POST',url, false);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(post);
return xmlhttp.responseText;
}
}
}
function displayReadyStateStatus(statustext)
{
if(!updStatusTextNode)
return;
if(xmlhttp.readyState==2)
{
updStatusTextNode.innerHTML = statustext+'...';
}
else if(xmlhttp.readyState==4)
{
if(xmlhttp.status == 200 || xmlhttp.status ==304)
{
if( updStatusTextNode.innerHTML.indexOf('complete')==-1)
{
var resp = xmlhttp.responseText.split('resValue ');
if(resp[0].length>0)
{
updStatusTextNode.innerHTML += statustext+' failed.';
updStatusTextNode.innerHTML += ' '+resp[0];
}
else
{
updStatusTextNode.innerHTML += statustext+' complete.';
}
if(resp[1])
gresValue=resp[1];
}
}
else
{
if( updStatusTextNode.innerHTML.indexOf('failed')==-1)
{
updStatusTextNode.innerHTML += statustext+' failed.';
if(xmlhttp.responseText.length>0)
updStatusTextNode.innerHTML += ' '+xmlhttp.responseText;
}
}
}
}
function insertNodeAfter(newChild, refChild)
{
refChild.parentNode.insertBefore(newChild,refChild.nextSibling);
}
function processForm(url, post, statustext, ret)
{
var arr = post.split('&');
for(var i=0;i<arr.length;i++)
{
var arr1 = arr[i].split('=');
arr1[1] = encodeURIComponent(arr1[1]);
arr[i] = arr1.join('=');
}
post = arr.join('&');
if(!ret)
return xmlhttpPost(url, post, statustext);
else
return post;
}
function getRadioSel(radio)
{
for (var i=radio.length-1; i > -1; i--) {
if (radio[i].checked) {
return radio[i].value;
}
}
}
function getAncestor(e, nodes)
{
for(var i=0;i<nodes;i++)
{
e = e.parentNode;
}
return e;
}
var nooptionstext = 'No options available';
var someoptionstext = 'Select an option';
function optionChange()
{
if( this.type == 'select-one' )
{
var la = this.optionchangefields;
var optionchangehideblanks = this.optionchangehideblanks;
if( la == null ) return;
var lna = new Array();
for( var i=0; i<la.length; i++ )
{
if( la[i].type == 'select-one' )
{
lna[la[i].name]=i;
}
}
for( var i=0; i< la.length; i++ )
{
if( la[i] != null && la[i].type == 'select-one' )
{
la[i].selectedIndex = 0;
la[i].options.length = 1;
la[i].options[0].text = nooptionstext;
}
}
var rv = this.options[this.selectedIndex].value;
var xmlhttp = createXMLHttp();
if( xmlhttp != null )
{
xmlhttp.open("GET","?task=xml"+this.name+"change&"+this.name+"="+escape(rv)+'&x='+(new Date()).getTime(),true);
xmlhttp.onreadystatechange = function()
{
if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
{
var dom = xmlhttp.responseXML;
if( dom != null )
{
var list = dom.getElementsByTagName('item');
for( var i=0; i< list.length; i++ )
{
var id = null;
var name = null;
var type = null;
var li = list[i];
if( li.childNodes[0] != null && li.childNodes[0].firstChild != null )
id = li.childNodes[0].firstChild.nodeValue;
if( li.childNodes[1] != null && li.childNodes[1].firstChild != null )
name = li.childNodes[1].firstChild.nodeValue;
if( li.childNodes[2] != null && li.childNodes[2].firstChild != null )
type = li.childNodes[2].firstChild.nodeValue;
var t = lna[type];
var l = null;
if( t != null ) l = la[t];
if( l != null )
{
if( l.options.length == 1 )
{
var t = l;
while( t.nodeName != 'TR' && t.parentNode != t && t.parentNode != null )
t = t.parentNode;
if( t.nodeName == 'TR' && t.style.display == 'none' ) t.style.display = 'block'; 
}
if( l.options.length == 1 && l.options[0].text == nooptionstext )
l.options[0].text = someoptionstext;
if( id == null || id == '' )
l.options[0].text = name;
else
l.options[l.options.length] = new Option(name, id, false, false);
}
}
}
if( optionchangehideblanks == true )
{
for( var i=0; i<la.length; i++ )
{
var t = la[i];
if( t != null && t.options != null && t.options.length < 2 )
{
while( t.nodeName != 'TR' && t.parentNode != t && t.parentNode != null )
{
t = t.parentNode;
}
if( t.nodeName == 'TR' )
{
t.style.display = 'none';
}
}
}
}
}
}
xmlhttp.send(null);
}
}
}
function AJAXItemLookup(frm, descfield, idfield, search, u, ev, searchfield)
{
var k = null;
var type = null;
if( window.event )	{ k = window.event.keyCode;	type = window.event.type; } 
else			{ k = ev.keyCode;		type = ev.type;	} 
if( k == 37 || k == 39 || (k == 0 && type != 'focus') ) return true;
var df = null;
if( descfield != null ) df = frm[descfield];
var sf = null;
if( searchfield != null ) sf = frm[searchfield];
if( search == null && sf != null ) search = sf.value;
if( sf == null ) sf = df;
var e = document.getElementById(sf.id+'_ajaxlookup');
if( type == 'keydown' )
{
if( k == 13 )
{
var as = e.getElementsByTagName('A');
var asl = as.length;
var sel = null;
var i=0;
while( i < asl && sel == null )
{
if( as[i].parentNode.className == 'sel' ) sel = i;
i++;
}
if( sel != null && as[sel].onclick ) as[sel].onclick();
return false;
}
if( k == 38 || k == 40 )
{
if( e != null )
{
var lis = e.getElementsByTagName('LI');
var lisl = lis.length;
if( lisl > 0 )
{
var sel = null;
var i=0;
while( i < lisl && sel == null )
{
if( lis[i].className == 'sel' ) sel = i;
i++;
}
if( sel == null )
{
lis[0].className = 'sel';
}
else
{
if( k == 40 && (sel+1) < lisl)
{
lis[sel].className = '';
lis[sel+1].className = 'sel';
}
else if( k == 38 && sel > 0 )
{
lis[sel].className = '';
lis[sel-1].className = 'sel';
}
}
}
}
return false;
}
return true;
}
if( k == 38 || k == 40 ) return false;
var v_search = escape(search);
if( u != null && u != '' )
{
if( u.indexOf('?') > -1 )
u += '&';
else
u += '?';
u += 'x='+(new Date()).getTime();
if( search != null )
{
u += '&search='+v_search;
u += '&ajax=y';
var ei = document.getElementById(sf.id+'_ajaxlookup_if');
var o = getElementPos(sf);
if( e == null )
{
var e = document.createElement("DIV");
e.style.display = 'none';
e.id = sf.id+'_ajaxlookup';
e.className = 'itemlookupajax';
e.style.zIndex = 1000;
e.style.width = (sf.offsetWidth-1)+'px';
e.style.position = 'absolute';
e.style.left = (o.x)+'px';
e.style.top = (o.y+sf.clientHeight+2)+'px';
sf.parentNode.insertBefore(e,sf);
if( window.event )
{
ei = document.createElement("IFRAME");
ei.style.display = 'none';
ei.frameBorder=0;
ei.id = sf.id+'_ajaxlookup_if';
ei.style.zIndex = 999;
ei.style.position = 'absolute';
ei.style.left = (o.x)+'px';
ei.style.top = (o.y+sf.clientHeight+2)+'px';
sf.parentNode.insertBefore(ei,sf);
}
sf.onfocus = function (event) { if( window.event) this.onkeyup(); else this.onkeyup(event); };
sf.onkeydown = function (event) { if( window.event) return this.onkeyup(); else return this.onkeyup(event); };
}
if( e != null && o != null)
{
var xmlhttp = createXMLHttp();
if( xmlhttp != null )
{
xmlhttp.open("GET",u,true);
xmlhttp.onreadystatechange = function()
{
if( xmlhttp.readyState == 4 && xmlhttp.status == 200 )
{
var dom = xmlhttp.responseXML;
if( dom != null )
{
var list = dom.getElementsByTagName('item');
var str = '';
for( var i=0; i< list.length; i++ )
{
var t = list[i].childNodes;
var xmlid = t[0].firstChild.nodeValue;
var xmlname = t[1].firstChild.nodeValue;
str += '<li><a href="#" onclick="'+
'document.FORM1.'+descfield+'.value=\''+xmlname.replace(/\'/g,'\\\'').replace(/"/g,'&quot;')+'\';';
str += 'document.FORM1.'+descfield+'.focusnow=true;';
str += 'if(document.FORM1.'+descfield+'.onchange != null)'+
'document.FORM1.'+descfield+'.onchange();';
if( idfield != null )
{
str += 'document.FORM1.'+idfield+'.value='+xmlid+';';
if( frm[idfield].onchange != null)
str += 'if(document.FORM1.'+idfield+'.onchange != null)'+
'document.FORM1.'+idfield+'.onchange();';
}
str += 'if(document.getElementById(\''+e.id+'\'))document.getElementById(\''+e.id+'\').style.display=\'none\';';
if( ei != null )
str += 'if(document.getElementById(\''+ei.id+'\'))document.getElementById(\''+ei.id+'\').style.display=\'none\';';
str += 'return false;">'+xmlname.replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;')+'</a></li>';
}
if( str != '' )
{
str = '<ul>'+str+'</ul>'+
'<a href="#" class="close" onclick="'+
'document.getElementById(\''+e.id+'\').style.display=\'none\';';
if( ei != null )
str += 'document.getElementById(\''+ei.id+'\').style.display=\'none\';';
str += 'return false;">Close</a>';
e.innerHTML = str;
e.style.display = 'block';
if(o.y+sf.clientHeight+2+e.clientHeight > document.body.scrollHeight)
{
e.style.top = o.y-(2+e.clientHeight)+'px';
}
else
{
e.style.top = (o.y+sf.clientHeight+2)+'px';
}
if( ei != null )
{
ei.style.width = e.offsetWidth;
ei.style.height = e.offsetHeight;
ei.style.display = 'block';
if(o.y+sf.clientHeight+2+e.clientHeight > document.body.scrollHeight)
{
ei.style.top = o.y-(2+e.clientHeight)+'px';
}
else
{
ei.style.top = (o.y+sf.clientHeight+2)+'px';
}
}
}
else
{
e.style.display = 'none';
if( ei != null )
{
ei.style.display = 'none';
}
}
}
}
}
xmlhttp.send(null);
}
}
}
}
return true;
}
function getDims()
{
var dims = new Object();
dims.w = 0;
dims.h = 0;
if( typeof( window.innerWidth ) == 'number' && window.innerWidth > 0)
{
dims.w = window.innerWidth;
}
else if( typeof( document.documentElement.clientWidth ) == 'number' && document.documentElement.clientWidth > 0)
{
dims.w = document.documentElement.clientWidth;
}
else if( typeof( document.body.offsetWidth ) == 'number' && document.body.offsetWidth > 0)
{
dims.w = document.body.offsetWidth;
}
else if( typeof( document.body.clientWidth ) == 'number' && document.body.clientWidth > 0)
{
dims.w = document.body.clientWidth;
}
if( typeof( window.innerHeight ) == 'number' && window.innerHeight > 0)
{
dims.h = window.innerHeight;
}
else if( typeof( document.documentElement.clientHeight ) == 'number' && document.documentElement.clientHeight > 0)
{
dims.h = document.documentElement.clientHeight;
}
else if( typeof( document.body.offsetHeight ) == 'number' && document.body.offsetHeight > 0)
{
dims.h = document.body.offsetHeight;
}
else if( typeof( document.body.clientHeight ) == 'number' && document.body.clientHeight > 0)
{
dims.h = document.body.clientHeight;
}
return dims;
}
function getScroll()
{
var scroll = new Object();
scroll.x = 0;
scroll.y = 0;
if( typeof( window.pageYOffset ) == 'number' && window.pageXOffset > 0)
{
scroll.x = window.pageXOffset;
}
else if( typeof( document.body.scrollLeft ) == 'number' &&  document.body.scrollLeft > 0)
{
scroll.x = document.body.scrollLeft;
}
else if( typeof( document.documentElement.scrollLeft ) == 'number' && document.documentElement.scrollLeft > 0)
{
scroll.x = document.documentElement.scrollLeft;
}
if( typeof( window.pageYOffset ) == 'number' && window.pageYOffset > 0)
{
scroll.y = window.pageYOffset;
}
else if( typeof( document.body.scrollLeft ) == 'number' && document.body.scrollTop > 0)
{
scroll.y = document.body.scrollTop;
}
else if( typeof( document.documentElement.scrollLeft ) == 'number' && document.documentElement.scrollTop > 0)
{
scroll.y = document.documentElement.scrollTop;
}
return scroll;
}
function addCss(css)
{
var st = document.createElement("link");
st.type = "text/css";
st.rel = "stylesheet";
st.href = css;
document.getElementsByTagName("head")[0].appendChild(st);
}
function createTargetIFrame(f)
{
var ifr = document.getElementById('i_jstargetiframe');
if(!ifr)
{
try
{
ifr = document.createElement('<iframe name="jstargetiframe">');
}
catch (e)
{
ifr = document.createElement('IFRAME');
ifr.name = 'jstargetiframe'
}
ifr.id = 'i_jstargetiframe';
ifr.width = 0;
ifr.height = 0;
ifr.marginHeight = 0;
ifr.marginWidth = 0;
ifr.style.display = 'none';
document.body.appendChild(ifr);
}
f.target = 'jstargetiframe';
}

