/*  ==================================================
    Standar dialogs of ScriptServer
    The syntax is described at help.scriptserver.com
    
    You can open dialogs modal or modeless by calling
    w3ss_openDialog or w3ss_openPopUp respectively. 
    ==================================================  */
    function w3ss_openPopUp(dialogName, onCompleteEventName, userParam)
    {
        var url = w3ss_composeDialogURL(dialogName, arguments);
        
        // skip width and height for now, perhaps we want to add it later on 
        w3ss_createDialog(url, onCompleteEventName, userParam, true);
    }
    
    function w3ss_openDialog(dialogName, onCompleteEventName, userParam)
    {
        var url = w3ss_composeDialogURL(dialogName, arguments);
        
        // skip width and height for now, perhaps we want to add it later on 
        w3ss_createDialog(url, onCompleteEventName, userParam, false);
    }


    function w3ss_composeDialogURL(dialogName, args)
    {
        var url;
        
        function composeParam(argNo, paramName)
        {
            if(argNo >= args.length)
                return '';
            
            
            return '&'+paramName+'='+args[argNo];
        }

        switch(dialogName.toLowerCase())
        {
            case('properties'):
                url = '/sys/common/dialogs/properties?key='+args[3];
                break;
            
            case('security'):
                url = '/sys/common/dialogs/security?keyOrPath='+args[3];
                break;

            case('mediamanager'):
                url = '/sys/MediaManager?nil=nil';
                url += composeParam(3, 'restrictToBranch');
                url += composeParam(4, 'browseToFolder');
                url += composeParam(5, 'selectionLimit');
                break;
            
            case('createfilefolder'):
                url = '/sys/MediaManager/createFileFolder?path='+args[3];
                break;
            
            case('renamefileandfolder'):
                url = '/sys/MediaManager/renamefileandfolder?path='+args[3];
                break;
         
            case('upload'):
                url = '/sys/common/Dialogs/upload?nil=nil';
                url += composeParam(3, 'restrictToFolder');
                url += composeParam(4, 'restrictToBranch');
                url += composeParam(5, 'suggestedFolder');
                url += composeParam(6, 'restrictToFileName');
                url += composeParam(7, 'maxUploads');
                url += composeParam(8, 'allowOverwrite');
                break;

            case('pickaccounts'):
                url = '/sys/common/dialogs/pickAccounts?nil=nil';
                url += composeParam(3, 'selectionLimit');
                url += composeParam(4, 'restrictToType');
                url += composeParam(5, 'restrictToProvider');
                url += composeParam(5, 'displayAutoAccounts');
                break;
            
            case('picklcid'):
                url = '/sys/common/dialogs/pickLCID?limit='+arguments[3];
                break;
            
            case('pickcolor'):
                url = '/sys/common/dialogs/pickColor';
                break;

            case('pickpage'):
                url = '/sys/common/dialogs/pickPage?nil=nil';
                url += composeParam(3, 'selectionLimit');
                url += composeParam(4, 'expandToKeyOrPath');
                url += composeParam(5, 'docType');
                break;

            case('pickfilefolder'):
                url = '/sys/common/dialogs/pickFileFolder?nil=nil';
                url += composeParam(3, 'selectedFolderPath');
                url += composeParam(4, 'restrictToBranch');
                break;

            case('createlink'):
                url = '/Sys/Common/Dialogs/CreateLink';
                break;

            case('insertrichedittable'):
                url = '/Sys/Common/Dialogs/RichEditTable';
                break;

            case('richedittableproperties'):
                url = '/Sys/Common/Dialogs/RichEditTable/TableProperties';
                break;

            case('testadoconnection'):
                url = '/sys/common/dialogs/testadoconnection?nil=nil';
                url += composeParam(3, 'conString');
                break;

            case('testsmtp'):
                url = '/sys/common/dialogs/testSMTP?nil=nil';
                url += composeParam(3, 'SMTPAddress');
                break;

            default:
                url = dialogName;
                if(url.indexOf('?') == -1)
                    url += '?nil=nil';
                break;
        }
        
        return url;
    }

    
    var w3ss_DialogParamValues = new Array();
    
    function w3ss_createDialog(url, onCompleteEventName, userParam, forceModeless, width, height)
    {
        var ua = navigator.userAgent.toLowerCase(); 
    	if(!forceModeless && (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) && parseInt(navigator.appVersion) >= 4)
        {
            if(!height)
                height = '500';
            
            if(!width)
                width = '500';
            
            var retVal = window.showModalDialog(url, window, 'dialogHeight:'+height+'; dialogWidth:'+width+'; edge:raised; unadorned:yes; status:no; scroll:yes;');
            
            if(onCompleteEventName)
                eval( onCompleteEventName+'(retVal, userParam)' );
        }
        else
        {
            if(!height) height = '500';
            if(!width)  width = '500';
            
            // Center the dialog
            var x = screen.width;
       		var y = screen.height;
            
            var top = parseInt(y/2-height/2-16);
            var left = parseInt(x/2-width/2-5);
            
            // save the userParam for later return
            var idx = w3ss_DialogParamValues.length;
            w3ss_DialogParamValues [idx] = userParam;
            
            // create a unique dialog name to avoid window reuse
            var dlgName = "dlg_"+ Date.parse(new Date());
            
            if(url.indexOf('?') == -1)
                url += '?nil=nil';
            
            window.open(url+'&onCompleteEventName='+onCompleteEventName+'&userParamIdx='+idx, dlgName, "width="+width+",height="+height+",top="+top+",left="+left+",scrollbars=yes,resizable=yes");
        }
    }
    
    function w3ss_returnFromDialog(retVal, idx, onCompleteEventName)
    {
        if(onCompleteEventName)
            eval( onCompleteEventName+'(retVal, w3ss_DialogParamValues [Number(idx)])' );
    }


     
		var w3c=(document.getElementById)? true: false;
var ie5=(w3c && document.all)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
currIDb=null; xoff=0; yoff=0;
currRS=null; rsxoff=0; rsyoff=0;
oldac=null; newac=null; zdx=1; mx=0; my=0;
var w3ss_lastId = null;

var theWindowDiv;
var isDragging = false;

var idlist=new Array();
idlist.btns=new Array();
idlist.btns[0]=new Image(); idlist.btns[0].src="http://tp.hardwaresuppliers.com/systemImages/popup/min.gif";
idlist.btns[1]=new Image(); idlist.btns[1].src="http://tp.hardwaresuppliers.com/systemImages/popup/max.gif";
idlist.btns[2]=new Image(); idlist.btns[2].src="http://tp.hardwaresuppliers.com/systemImages/popup/close.gif";
idlist.btns[3]=new Image(); idlist.btns[3].src="http://tp.hardwaresuppliers.com/systemImages/popup/resize.gif";

function truebody(){ //Dynamic Drive added function
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidebox(id){
if(w3c){
document.getElementById(id+'_b').style.display='none';
document.getElementById(id+'_s').style.display='none';
}}


function showbox(id){
if(w3c){
var bx=document.getElementById(id+'_b').style;
var sh=document.getElementById(id+'_s').style;
bx.display='block';
sh.display='block';
sh.zIndex=++zdx;
bx.zIndex=++zdx;
}}

function minimize(){
if(w3c){
this.IDS[0].style.height=(ie5)? '28px':'24px';
this.IDS[3].style.height='28px';
this.IDS[2].style.display='none';
this.IDS[4].style.display='none';
setTimeout('ns6bugfix()',100);
}}

function restore(){
if(w3c){
var h=this.IDS[10];
this.IDS[0].style.height=h+'px'; //box
this.IDS[3].style.height=(ie5)? h+'px':h+5+'px'; //shd
this.IDS[2].style.display='block';
this.IDS[4].style.display='block'; 
setTimeout('ns6bugfix()',100);
}}

function ns6bugfix(){
self.resizeBy(0,1);
self.resizeBy(0,-1);
}

function trackmouse(evt){
	mx=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
	my=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
	if(!ns6)movepopup();
	if((currIDb!=null)||(currRS!=null))
		return false;
}

function movepopup(){
if((currIDb!=null)&&w3c&&isDragging){
var x=mx+xoff;
var y=my+yoff;
currIDb.style.left=x+'px';
currIDs.style.left=x+8+'px';
currIDb.style.top=y+'px';
currIDs.style.top=y+8+'px';
}
if((currRS!=null)&&w3c&&isDragging){
var rx=mx+rsxoff;
var ry=my+rsyoff;
var c=currRS;
c.style.left=Math.max(rx,((ie5)?88:92))+'px';
c.style.top=Math.max(ry,((ie5)?68:72))+'px';
c.IDS[0].style.width=Math.max(rx+((ie5)?12:8),100)+'px';
c.IDS[0].style.height=Math.max(ry+((ie5)?12:8),80)+'px';
c.IDS[1].style.width=Math.max(rx+((ie5)?4:3),((ns6)?95:92))+'px';
c.IDS[5].style.left=parseInt(c.IDS[1].style.width)-48+'px';
c.IDS[3].style.width=Math.max(rx+12,((ie5)?100:104))+'px';
c.IDS[3].style.height=Math.max(ry+((ie5)?12:13),((ie5)?80:86))+'px';
c.IDS[2].style.width=Math.max(rx-((ie5)?-5:5),((ie5)?92:87))+'px';
c.IDS[2].style.height=Math.max(ry-((ie5)?24:28),44)+'px';
c.IDS[10]=parseInt(c.IDS[0].style.height);
}}

function startRS(evt){
isDragging = true;
theWindowDiv.setCapture(true);
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
rsxoff=parseInt(this.style.left)-ex;
rsyoff=parseInt(this.style.top)-ey;
currRS=this;
if(ns6)this.IDS[2].style.overflow='hidden';
return false;
}

function stopdrag(){
isDragging=false;
if(document.releaseCapture) document.releaseCapture();
isDragging = false;
currIDb=null;
ns6bugfix();

}

function grab_id(evt){
//alert(isDragging);
isDragging = true;
theWindowDiv.setCapture(true);
var ex=(ie5)?event.clientX+truebody().scrollLeft:evt.pageX;
var ey=(ie5)?event.clientY+truebody().scrollTop:evt.pageY;
xoff=parseInt(this.IDS[0].style.left)-ex;
yoff=parseInt(this.IDS[0].style.top)-ey;
currIDb=this.IDS[0];
currIDs=this.IDS[3];
return false;
}

function subBox(x,y,w,h,bgc,id){
var v=document.createElement('div');
v.setAttribute('id',id);
 
v.style.position='absolute';
v.style.left=x+'px';
v.style.top=y+'px';
v.style.width=w+'px';
v.style.height=h+'px';

v.style.backgroundColor=bgc;


v.style.visibility='visible';
v.style.overflow='hidden';
v.style.padding='0px 0px 0px 0px';
return v;
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function w3ss_popUp(x,y,w,h,cid,text,bgcolor,textcolor,fontstyleset,title,titlecolor,titletextcolor,bordercolor,scrollcolor,shadowcolor,showonstart,isdrag,isresize,oldOK,POPPERSESSION){

x += document.body.scrollLeft;
y += document.body.scrollTop;

var tempWidth;
var tempHeight;

if(ns6)
{
	tempWidth 	= window.innerWidth;
	tempHeight 	= window.innerHeight;
}
else
{
	tempWidth 	= screen.availWidth;
	tempHeight 	= screen.availHeight;
}

if(w>tempWidth && (tempWidth - 80)>0)
	w = tempWidth - 80;
else if(w>tempWidth && (tempWidth - 80)<0)
	w = tempWidth;

if(h>tempHeight && (tempHeight - 80)>0)
	h = tempHeight - 80;
else if(h>tempHeight && (tempHeight - 80)<0)
	h = tempHeight;

var proceedtopop=false
if (POPPERSESSION){
if (get_cookie(cid)==""){
proceedtopop=true
document.cookie=cid+"=yes"
}
}
else
proceedtopop=true

if (proceedtopop){
if(w3c){
var tw, th;
w=Math.max(w,100);
h=Math.max(h,80);
var rdiv=new subBox(w-((ie5)?12:8),h-((ie5)?12:8),7,7,'',cid+'_rs');
if(isresize){
rdiv.innerHTML='<img src="http://tp.hardwaresuppliers.com/systemImages/popup/resize.gif" width="7" height="7">';
rdiv.style.cursor='se-resize';
}
tw=(ie5)?w:w+4;
th=(ie5)?h:h+6;
var shadow=new subBox(x+4,y+4,tw,th,shadowcolor,cid+'_s');
if(ie5)shadow.style.filter="alpha(opacity=50)";
else shadow.style.MozOpacity=.5;
shadow.style.zIndex=++zdx;
var tw,th;
var outerdiv=new subBox(x,y,w,h,bordercolor,cid+'_b');
theWindowDiv = outerdiv;
outerdiv.style.borderStyle="outset";
outerdiv.style.borderWidth="2px";
outerdiv.style.borderColor=bordercolor;
outerdiv.style.zIndex=++zdx;
tw=(ie5)?w-8:w-5;
th=(ie5)?h+4:h-4;
var titlebar=new subBox(2,2,tw,20,titlecolor,cid+'_t');
titlebar.style.overflow="hidden";
titlebar.style.cursor="default";
titlebar.innerHTML='<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:'+titletextcolor+'; height:18px; overflow:hidden; clip-height:16px;">'+title+'</span><span id="'+cid+'_btt" style="position:absolute; width:48px; height:16px; left:'+(tw-48)+'px; top:2px;"><img src="http://tp.hardwaresuppliers.com/systemImages/popup/min.gif" width="16" height="16" id="'+cid+'_min"><img src="http://tp.hardwaresuppliers.com/systemImages/popup/max.gif" width="16" height="16"  id="'+cid+'_max"><img src="http://tp.hardwaresuppliers.com/systemImages/popup/close.gif" width="16" height="16" id="'+cid+'_cls"></span>';
tw=(ie5)?w-7:w-13;
th=(ie5)?h-36:h-36;
var content=new subBox(2,24,tw,th,bgcolor,cid+'_c');
content.style.borderColor=bordercolor;
content.style.borderStyle="inset";
content.style.borderWidth="2px";
content.style.overflow="auto";
content.style.padding="0px 2px 0px 4px";
content.style.font=fontstyleset;
content.style.color=textcolor;
if(ie5)content.style.scrollbarBaseColor=scrollcolor;
content.innerHTML=text;
outerdiv.appendChild(titlebar);
outerdiv.appendChild(content);
outerdiv.appendChild(rdiv);
document.body.appendChild(shadow);
document.body.appendChild(outerdiv);
if(!showonstart)hidebox(cid);
var IDS=new Array();
IDS[0]=document.getElementById(cid+'_b');
IDS[1]=document.getElementById(cid+'_t');
IDS[2]=document.getElementById(cid+'_c');
IDS[3]=document.getElementById(cid+'_s');
IDS[4]=document.getElementById(cid+'_rs');
IDS[5]=document.getElementById(cid+'_btt');
IDS[6]=document.getElementById(cid+'_min');
IDS[7]=document.getElementById(cid+'_max');
IDS[8]=document.getElementById(cid+'_cls');
IDS[9]=cid;
IDS[10]=h;

this.IDb=IDS[0]; this.IDb.IDS=IDS;
this.IDt=IDS[1]; this.IDt.IDS=IDS;
this.IDc=IDS[2]; this.IDc.IDS=IDS;
this.IDs=IDS[3]; this.IDs.IDS=IDS;
this.IDrs=IDS[4]; this.IDrs.IDS=IDS;
this.IDbtt=IDS[5]; this.IDbtt.IDS=IDS;
this.IDmin=IDS[6]; this.IDmin.IDS=IDS;
this.IDmax=IDS[7]; this.IDmax.IDS=IDS;
this.IDcls=IDS[8]; this.IDcls.IDS=IDS;
this.IDb.activecolor=titlecolor;

this.IDb.inactivecolor=scrollcolor;
if(oldac!=null)oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
oldac=this.IDb;
this.IDcls.onclick=new Function("hidebox('"+cid+"');");
if(isresize){
this.IDmin.onclick=minimize;
this.IDmax.onclick=restore;
this.IDrs.onmousedown=startRS;
var release = (document.releaseCapture) ? document.releaseCapture : nukk
this.IDrs.onmouseup=new Function("currRS=null;currIDb=null;release;isDragging=false;alert();");
}
this.IDb.onmousedown=function(){
   if(oldac!=null){
   oldac.IDS[1].style.backgroundColor=oldac.inactivecolor;
   }
   if(ns6)this.IDS[2].style.overflow='auto';
   oldac=this;
   this.IDS[1].style.backgroundColor=this.activecolor;
   this.IDS[3].style.zIndex=++zdx;
   this.style.zIndex=++zdx;
   }
if(isdrag){
this.IDt.onmousedown=grab_id;
this.IDt.onmouseup=stopdrag;
}
}else{
if(oldOK){
var ctr=new Date();
ctr=ctr.getTime();
var win=window.open("" , "abc"+ctr , "status=no,menubar=no,width="+w+",height="+h+",resizable=yes,scrollbars=yes");
var t='<html><head><title>'+title+'</title></head><body bgcolor="'+bgcolor+'"><font style="font:'+fontstyleset+'; color:'+textcolor+'">'+text+'</font></body></html>';
win.document.write(t);
win.document.close();
}}}}

if(ns6)setInterval('movepopup()',40);

if(w3c){
document.onmousemove=trackmouse;
var release = (document.releaseCapture) ? document.releaseCapture : null;
document.onmouseup=new Function("currRS=null;currIDb=null;release;isDragging=false;");
}

   function logonStatus(status)
        {
            if( status == 0 )
            {
                alert("Logon failed!");
                return;
            }
            //locked
            else if( status == 1 )
            {
                alert("This account has been locked. Most likely due to too many failed log in attempts in sequence. Contact your system administrator for help.");
                return;
            }
            //admin
            else if( status == 99 )
            {
                parent.document.location.href = "http://tp.hardwaresuppliers.com/websys/Frameset?page=/admin";
                return;
            }
            
            parent.document.location.href = "http://tp.hardwaresuppliers.com/websys/Frameset?page=/selfservice";
        }
        
        function sendPassword()
        {
            try
            {
                w3ss_openPopUp('http://tp.hardwaresuppliers.com/TradePoint/SendPwd', null, null);
            }   
            catch(e){}
        }
        
        function validateExistingCustomer()
        {
            try
            {
                w3ss_openPopUp('http://tp.hardwaresuppliers.com/TradePoint/ValidateExistingCustomer', null, null);
            }
            catch(e){}
            
        }
		

 var w3ss_lastId = null;
            var hasShownWrongBrowserWin = false;
                                  
        		function openSpecialPopup(x,y,w,h,theSrc,title)
        		{
        			// Get random no for unique Div name
                var tempRnd = Math.random()*1000000000;
            	tempRnd = Math.round(tempRnd);
                if(theSrc.indexOf("?")!=-1)
                    theSrc += "&inPopUp=yes";
                else
                    theSrc += "?inPopUp=yes";
                    
                if(w3ss_lastId)
                {
                    document.getElementById(w3ss_lastId+"_b").style.display = "none";
                    document.getElementById(w3ss_lastId+"_s").style.display = "none";
                }
                w3ss_lastId = "Div"+tempRnd;
                lastDivId = tempRnd;
                //new w3ss_popUp(x, y, w, h, "Div"+tempRnd, "<iframe style='postition:absolute;top:0px;left:0px;border:0px solid transparent;' marginheight='0' marginwidth='0' frameborder='0' width='100%' height='99%' src='"+theSrc+"?inPopUp=yes'></iframe> ", "white", "black", "bold 10pt sans-serif", "  " + title, "#EF9F51", "white", "#dddddd", "gray", "black", true, true, true, true, false);
                  new w3ss_popUp(x, y, w, h, "Div"+tempRnd, "<iframe id='thePopUpWin"+lastDivId+"' name='thePopUpWin"+lastDivId+"' style='display:inline;postition:absolute;top:0px;left:0px;border:0px solid transparent;' marginheight='0' marginwidth='0' frameborder='0' width='100%' height='99%' src='"+theSrc+"'></iframe> ", "#ACA181", "black", "bold 10pt sans-serif", "  " + title, "#ACA181", "white", "#ACA181", "gray", "#444444", true, true, true, true, false);
        		}
        
            function closeSpecialPopUp()
            {
                try
                {
                    document.getElementById(w3ss_lastId+"_b").style.display = "none";
                    document.getElementById(w3ss_lastId+"_s").style.display = "none";
                }
                catch(e){}
            }
        
            function hideConfirm()
            {
                var el = document.getElementById("confirmDiv");
                el.style.display = "none";   
            }
            
            function showConfirm()
            {
                var tempWidth;
                var tempHeight;
                
            	tempWidth 	= document.body.clientWidth;
            	tempHeight 	= document.body.clientHeight;
                
                var el = document.getElementById("confirmDiv");
                
                var x = ((tempWidth/3)-(Number(el.style.width.substr(0,el.style.width.length-2))/3 )) + document.body.scrollLeft;
                var y = ((tempHeight/4)-(Number(el.style.height.substr(0,el.style.height.length-2))/4 )) + document.body.scrollTop;
                
                el.style.left   = x;
                el.style.top    = y;
                el.style.display = "inline";
                setTimeout('hideConfirm()',2000);
            }
            
            function showPriceDiv( theText , theRows)
            {
                var tempWidth;
                var tempHeight;
                tempWidth 	= document.body.clientWidth;
                theText = '<div style="position:absolute;top:1px;left:20px;">'+theText+'</div>';
                
                var el  = document.getElementById("priceDiv");
                var el2 = document.getElementById("pricePic");
                var el3 = document.getElementById("pricePicBottom");
                
                //alert(theRows);
                el.style.width  = "382px";
                el.style.height = ((theRows*18) + 103 ) + "px";
                
                
                var x = ((tempWidth/2)-(Number(el.style.width.substr(0,el.style.width.length-2))/2 )) + document.body.scrollLeft;
                var y = 44 + document.body.scrollTop;
                
                el.style.left   = 4;//x;
                el.style.bottom = 2;
                
                el2.style.left      = 4;
                el2.style.bottom    = 2 + ((theRows*18) + 103 );  
                
                el3.style.left      = 4;
                el3.style.bottom    = 2;
                  
                //el.style.top      = y;
                el.innerHTML        = theText;
                el.style.display    = "inline"; 
                document.getElementById("pricePic").style.display = "inline";  
                
                document.getElementById("pricePicBottom").style.display = "inline";  
            }
            
            function hidePriceDiv()
            {
                document.getElementById("priceDiv").style.display       = "none";
                document.getElementById("pricePic").style.display       = "none";
                document.getElementById("pricePicBottom").style.display = "none";
            }
