var g_continue, t;

//***************************************
//	Recieving calls
//***************************************
function psd(d) {
	// This function was called from response.js and the reason is because we are passing
	// html as data which follows the JSON format (see setfields), and we need to call a function
	// to do more processing for the data (ie initialize a grid)
	this.data = d.data;
	this.menu = d.menu;
	this.items = d.items;
	this.msgtyp = d.msgtyp;
	this.msgtxt = d.msgtxt;
	this.html = d.html;
	this.info = d.info;
	this.cat = d.cat;
	return;
}

psd.prototype.fill = function() {
	//We have nothing to do for psd page once it is filled
	return;
}

psd.prototype.send = function() {
	document.body.style.cursor = '';
    open_window("mail","mailarea", 20,320,400,400,this.msgtxt.toUpperCase(),"Y");
    getobj("mailarea").innerHTML=this.html;
}
//psd.prototype.refresh_date = function() {
//	document.body.style.cursor = '';
//	settext("dt_today",this.data[0].dt);
//	return;
//}

//psd.prototype.get_date = function() {
//	document.body.style.cursor = '';
//	settext("dt_today",this.data[0].dt);
//	return;
//}

psd.prototype.search = function() {
	nm='search';
	min='1'
	close='1'
	divbox=nm+"_div"
	win=nm+"_win"
	document.body.style.cursor = '';
	e=document.createElement("div");
	e.setAttribute("id",win);
	e.style.display="none";
	document.body.appendChild(e);
	style='width=500px,height=580px,top=10px,left=10px,resize=1,scrolling=1';
	divwin=dhtmlwindow.open(divbox, 'div', win, 'Search Results', min, close, style);
	o=document.getElementById(divbox);
	o.contentarea.innerHTML=this.html;
	o.style.display="block";
//    fade(document.getElementById('search'), 0, 1.0, 2000);
    return;
}

psd.prototype.get_news = function() {
	nm='news';
	min='1'
	close='1'
	divbox=nm+"_div"
	win=nm+"_win"
	document.body.style.cursor = '';
	e=document.createElement("div");
	e.setAttribute("id",win);
	e.style.display="none";
	document.body.appendChild(e);
	style='width=760px,height=524px,top=4px,left=30px,resize=1,scrolling=1';
	divwin=dhtmlwindow.open(divbox, 'div', win, 'News', min, close, style);
	o=document.getElementById(divbox);
	var h='<iframe name="newsframe" id="newsframe" src= "'+this.data+'" border=0 width="740px" height="520px">';
    h+='<p>Your browser does not support iframes.</p></iframe>';
	o.contentarea.innerHTML=h;
	o.style.display="block";
    return;
}
/*
psd.prototype.get_contents = function() {
    document.body.style.cursor = '';
	if (this.menu=="home" & this.data=="home") { 
		disable("back");
	}else{
		enable("back");
	}
	if (this.menu == "home") {
		menu(this.data);
	}else{
		menu(this.menu);
	}
    if (this.items) {
		side_menu(this.items);
    }
    getobj('frame').style.display="none";
    getobj('inner_txt').innerHTML=this.html;
    switch(this.data) {
		case 'home':
            getobj('frame_content').style.display="none";
            getobj('frame').style.display="block";
            g_continue=true;
            Show_images(0);
            break;
		case 'products':
            g_continue=false;
            break;
        default:
			break;
           
    }
    if (isobj("cat")) {
        //Show the catalog if exists
        var cat=getobj("cat");
        if (this.cat != "") {
            cat.name=this.cat;
            cat.style.display="block";
        }else{
            cat.name="";
            cat.style.display="none";
        }
    }
    resize();
    return;
}
*/

psd.prototype.open_win = function() {
	o=document.getElementById(this.data[0].id);
	o.contentarea.innerHTML=this.html;
	if (this.data[0].id=="request_div") {
		getobj("page").value=document.title;
	}
	o.style.display="block";
	if (this.data[0].fade="IN") {
		fade(o, 0, 1.0, this.data[0].interval);
	}else if (this.data[0].fade="OUT") {
		fade(o, 1.0, 0, this.data[0].interval);
	}
    return;
}
psd.prototype.get_request = function() {
	document.body.style.cursor = '';
	d="win"+this.data;
    open_window(d,this.data+"area", 20,120,600,520,this.msgtxt.toUpperCase(),"Y");
    o=getobj(this.data+"area");
    o.innerHTML=this.html;
	o.style.zIndex="3";
    if (this.info != ""){
        settext("info","You have requested more information for <u>"+this.info+"</u> page.");
    }
    return;
}
//****************************************************************************
// Calls made from popups
//****************************************************************************
/*
function srch(pth, id) {
    JObj = new Object;
    JObj.pth= pth;
    JObj.nm = id;
    JObj.flg = "Y";
	if(pth=="home") JObj.flg = "N";
    AjaxCall("psd","get_contents", JObj);
    if (isobj("search_win")) close_window("search_win");
    clearTimeout(t);
}
*/

function send_request() {
	//Get fields to send
	JObj = new Object;
	JObj.type="request";
	if (missing("email")) return;
	JObj.email=getedit("email");
	if (missing("name")) return;
	JObj.name= getedit("name");
	JObj.phone= getedit("phone");
	JObj.cmnts= getedit("comments");	
	JObj.curr_info=getedit("curr_info");
	AjaxCall("psd","send",JObj);
	close_window("winrequest");
}
function send() {
	var buf_array = new Array();			
	JObj = new Object;
	if (missing("email")) return;
	JObj.email= getedit("email");
	if (missing("name")) return;
	JObj.name= getedit("name");
	if (missing("company")) return;
	JObj.company= getedit("company");
	if (missing("phone")) return;
	JObj.phone= getedit("phone");
	JObj.title= getedit("title");
	JObj.address1= getedit("address1");
	JObj.address2= getedit("address2");
	JObj.city= getedit("city");
	JObj.state= getselecteditem("state");
	e = document.getElementById("found");
    l=e.getElementsByTagName("input");
	buf_array=[];
	j=0;
	for (i=0; i<l.length; i++) {
		if (l[i].checked) {
			buf_array[j] = {"item":""};
			buf_array[j].item = l[i].value;
			j++;
		}
	}
	JObj.found = buf_array;
	buf_array=[];
	e = document.getElementById("timeframe");
    l=e.getElementsByTagName("input");
	j=0;
	for (i=0; i<l.length; i++) {
		if (l[i].checked) {
			buf_array[j] = {"item":""};
			buf_array[j].item  = l[i].value;
			j++;
		}
	}
	JObj.timeframe = buf_array;
	buf_array=[];
	e = document.getElementById("request");
    l=e.getElementsByTagName("input");
	j=0;
	for (i=0; i<l.length; i++) {
		if (l[i].checked) {
			buf_array[j] = {"item":""};
			buf_array[j].item  = l[i].value;
			j++;
		}
	}
	JObj.type="contact";
	JObj.request = buf_array;
	JObj.cmnts= getedit("comments");
	AjaxCall("psd","send", JObj);
	close_window("wincontact");
}
function signup() {
	JObj = new Object;
	JObj.type="newsletter";
	if (missing("signup")) return;
	JObj.email=getedit("signup");
	AjaxCall("psd","send",JObj);
}


//****************************************************************************
// Calls made from listen.js
//****************************************************************************
function do_delete() {
	return;
}
function do_insert() {
	return;
}
function do_cancel() {
	return;
}
function do_changed(o) {
}

//****************************************************************************
// Inline functions
//****************************************************************************
function search(o) {
	JObj = new Object;
    JObj.keyword=getedit("search_data");
    AjaxCall("psd","search",JObj);
    
}
function get_oldnews() {
// Comment for testing
    JObj = new Object;
    JObj.mmmyyyy = getselecteditemval("ddlb_archive");
    if (isobj("newsframe")) getobj("newsframe").src="";
    if (JObj.mmmyyyy == "none") {

    }
    AjaxCall("psd","get_news",JObj);
// Uncomment for testing
//    nm = getselecteditemval("ddlb_archive");
//    open_win(nm,"news");
}
function get_news(dt) {
// Comment for testing
   	JObj = new Object;
    JObj.nm="NewsLetter";			
    JObj.mmmyyyy= dt;
    AjaxCall("psd","get_news",JObj);
//    open_win("apr2010","news");
}   

function get_catalog(pdf_nm){
	nm='catalog';
	min='1'
	close='1'
	divbox=nm+"_div"
	win=nm+"_win"
	document.body.style.cursor = '';
	e=document.createElement("div");
	e.setAttribute("id",win);
	e.style.display="none";
	document.body.appendChild(e);
	style='width=750px,height=600px,top=10px,left=30px,resize=1,scrolling=1';
	divwin=dhtmlwindow.open(divbox, 'div', win, 'PDF Catalog', min, close, style);
	o=document.getElementById(divbox);
//	var h='<OBJECT id="dhtmlobj" TYPE="application/pdf" TITLE="PDF Catalogue"';
//	h+='WIDTH=740 HEIGHT=590></object>';
	var h='<iframe id="dhtmlframe" border=0 width="740px" height="590px">';
    h+='<p>Your browser does not support iframes.</p></iframe>';
	o.contentarea.innerHTML=h;
	o.style.display="block";
//	getobj('dhtmlobj').data= "../pdf/"+pdf_nm+".pdf";
	getobj('dhtmlframe').src= "/main/pdf/"+pdf_nm+".pdf";
//alert("/main/");
    o.contentarea.style.zIndex="99";
	return;
}
/*
function side_menu(m) {
	h="";
//alert(m.length);
	for(i=0;i<m.length;i++){ 
		for(var j in m[i]) {
			//Menu
			if (i==0) {
                if (j==1) h +='<div class="items_title" id="itm_title" name="'+m[i][0]+'"style="text-align:left;">'+m[i][1]+'</div><ul>';
			}else{
				if (j==0) {
				    if (m[i][j].substr(0,5) == "http:") {
                       h += '<li><a id="" href="'+m[i][j]+'">';
					}else{   
                       h += '<li><a id="'+m[i][j]+'" href="" onclick="get_contents(this);return false;">';
                    }
				}else{
					h += m[i][j]+'</a></li>';
				}
			}
		}
	}
	h +="</ul>";
	getobj("sidebar").innerHTML=h;
	return;
}    
*/

function menu(id) {
//	getobj("leftcolumn").style.height = getobj("rightcolumn").offsetHeight+"px";
	JObj = new Object;
	e = document.getElementById("menu");
	l=e.getElementsByTagName("a");
	for (i=0; i<l.length; i++) {
		if(l[i].id == id) {
			l[i].className = "current";
		}else{
	        l[i].className = "";
		}
	}
	return;
}
/*
function back() {
	JObj = new Object;
	e = document.getElementById("crumbs");
      l=e.getElementsByTagName("a");
	JObj.pth = '';
	if (l.length > 1) {
		for (i=0; i<l.length -1; i++) {
			if (JObj.pth.length>0) {
//alert(JObj.pth);
				JObj.pth += "/";
			}
			JObj.pth += l[i].id;
		}
		JObj.nm = l[i].id;
	}else{
 	    JObj.pth="home";
	    JObj.nm ="home";
 	}
    JObj.flg = "N";
    AjaxCall("psd","get_contents", JObj);
}
function get_contents(o) {
	JObj = new Object;
	AjaxCall("psd","refresh_date");
    if (o.id=="newsletter") {
        get_news();
        return;
    }
    if (o.id=="archive") {
        alert("Select from the drop down list over on the right panel under Archive News.")
        return;
    }

    if (o.parentNode.parentNode.id=="menu") {
	    JObj.pth="home";
	    JObj.nm = o.id;
    }else if (o.parentNode.id=="crumbs") {
		//bread crumbs
		e = document.getElementById("crumbs");
        l=e.getElementsByTagName("a");
		JObj.pth = '';
		if (l.length > 1) {
            for (i=0; i<l.length; i++) {
 			    if (l[i].id == o.id) {
					JObj.nm = o.id;
                    break;
 			    }
 			    if (JObj.pth.length>0) {
//alert(JObj.pth);
					JObj.pth += "/";
				}
 			    JObj.pth += l[i].id;
 			}
 		}else{
 		    JObj.pth="home";
		    JObj.nm ="home";
 		}
//	    JObj.nm = e.getAttribute("name");
    }else{
        //side mnenu
        JObj.pth=document.getElementById("itm_title").getAttribute("name");
	    JObj.nm = o.id;
    }
    JObj.flg = "N";
//alert(JObj.pth);
//alert(JObj.pth+","+JObj.nm);
    AjaxCall("psd","get_contents", JObj);
    clearTimeout(t);
}

function image_lnk(nm) {
	JObj = new Object;
	if (document.getElementById("itm_title")==null) return;
    //from images
    JObj.pth=document.getElementById("itm_title").getAttribute("name");
    JObj.nm = nm;
    JObj.flg = "N";
    AjaxCall("psd","get_contents", JObj);
    clearTimeout(t);
}
*/
function get_request(nm) {
	JObj = new Object;
	JObj.nm = nm.name;
	JObj.txt = nm.innerHTML;
	JObj.info = gettext("curr_info");
//alert(JObj.info);
	AjaxCall("psd","get_request", JObj);
	return;
}
/*
function link_popup(nm, txt) {
	JObj = new Object;
	JObj.nm = nm;
	JObj.txt = txt;
	AjaxCall("psd","get_popup", JObj);
	return;
}
*/

function missing(o) {
	if (getedit(o) == "") {
		setfocus(o);
		getobj(o).className="req";
		return true;
	}
	getobj(o).className="norm";
	return false;
}

function Show_images(num){
	o=getobj('frame_content');
	if (!g_continue) return;
    if (getobj('frame').style.display=="none") {
        return;
    }
	e=getobj('inner_txt');
	switch(num) {
		case 0:
			o.src='/main/images/home/bld_medium.jpg';
			e.innerHTML="";
			return;
			break;
		case 1:
			o.src='/main/images/home/excellence.jpg';
			e.innerHTML="Services relating to File moves, File conversions, Scanning , Imaging, Consulting, "+
						"Equipment relocations, Records management-related services, File room outsourcing, "+
						"Centre of Excellence, and Installations.";
			break;
		case 2:
			o.src='/main/images/home/tabtrac1.jpg';
			e.innerHTML="Solutions to all aspects of records and document management. Filing systems, "+
						"Shelving systems, Mobile shelving, File cabinets, Rotating cabinets, File folders, "+
						"Labels, Labeling software, and Document management software.";
			break;
		case 3:
			o.src='/main/images/home/sort1.jpg';
			e.innerHTML="Desk consoles and sorter units for mail room and packaging operations."
 			break;			
		case 4:
			o.src='/main/images/home/paramount1.jpg';
			e.innerHTML="Complete solutions for Data Centre environments including Enclosures, Racks, "+
						"Power Distribution, Thermal management, Cable management, Blanking panels and "+
						"Floor grommets. Products for all technical environments requiring Consoles, "+
						"Bench systems, LAN management systems, Intelligent power, Media cabinets, and Tech carts.";
			break;
		case 5:
			o.src='/main/images/home/bld_medium.jpg';
			e.innerHTML="Thank you for your intrest in Pathfinder Systems Design Ltd.,<BR> "+
						"Please continue to view our products and services from the Menu!";
			break;
 		default:
			num=0;
			break;
	}
	if (num < 5){
	   set_opacity(o, 0);
	   num=num+1;
	   t=setTimeout(function(){Show_images(num);}, 9000);
	}
	return;
}
function start_fade(){
	var o=getobj('frame_content');
    if (o.src =="") return;
    fade(o, 0, 1.0, 3000);
}

/*
function moveObjRight(nm) 
{    
    var o=getobj(nm);
   	o.style.left=Hmove+"px";
   	Hmove+=1;
   	if(Hmove < 100)
   	  	window.setTimeout('moveObjRight("' +nm+ '");', 0);
}

function get_date() {
	JObj = new Object;
	AjaxCall("psd","get_date");
}
var months = new makeDate('January','February','March',
    'April','May','June','July','August','September',
    'October','November','December');
var date = new Date();
var day  = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();

var year = (yy < 1000) ? yy + 1900 : yy;
var date = new Date();
var prev_obj;

function makeDate() {
     for (i = 0; i<makeDate.arguments.length; i++)
          this[i + 1] = makeDate.arguments[i];
}
function show_err(txt, id) {
    if (!isobj("errorarea")) open_window("errors","errorarea",121,116,340,320,"Errors", "Y");
    var o = getobj("errorarea");
    o.innerHTML = txt;
}
*/
//**************NEW
function open_win(nm,typ) {
    var win=nm+"_win";
    var divbox=nm+"_div";
//    if (isobj(win)) return;
    var scroll='1';
    var resize='1';
    var min='1';
    var close='1';
    var fade='IN'
    var interval='1000';
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
    if (typ == "pop") {
        switch(nm) {
		  case 'privacy':
            var title='Privacy Statement'
            var t='29'
            var l='22'
            var w='620'
            var h='450'
			break;
		  case 'location':
            var title='Location'
            var t='20'
            var l='390'
            var w='440'
            var h='600'
			break;
		  case 'request':
            var title='Information Request'
            var t='115'
            var l='127'
            var w='630'
            var h='360'
			break;
		  case 'contact':
            var title='Contact Us'
            var t='2'
            var l='208'
            var w='590'
            var h='980'
			break;
		  case 'site':
            var title='Site Map'
            var t='2'
            var l='12'
            var w='880'
            var h='700'
			break;
		  default:
		    return;
		    break;
		}
	}else{
        var title='News Letter'
        var t='11'
        var l='58'
        var w='790'
        var h='445'
    }

	e=document.createElement("div");

	e.setAttribute("id",win);
	e.style.display="none";
	document.body.appendChild(e);
	style='width='+w+'px,height='+h+'px,top='+t+'px,left='+l+'px,resize='+resize+',scrolling='+scroll;
	
	
	divwin=dhtmlwindow.open(divbox, 'div', win, title, min, close, style);
	document.getElementById(divbox).style.display="none";
	
	var JObj=new Object;
	JObj.nm=nm;
	JObj.typ=typ;
	JObj.id=divbox;
	JObj.fade=fade;
	JObj.interval=interval;
	AjaxCall('psd','open_win', JObj);
}

function myopen() {
	Obj=document.getElementById('bld');
    getobj("leftcolumn").style.height = getobj("rightcolumn").offsetHeight+"px";
	Obj.src = "/main/images/PSD building small.jpg";
	Obj.style.height= getobj("rightcolumn").offsetHeight-20+"px";;
	fade(Obj, 1.0, 0.1, 2000, '0');
//	fade_done('0');
//    growmoveImg('1', 1, 210, 280, 100,'NW');
}


