//---------------------------------------------------------------------------------------------------------------------\\
//                                                      AJ Parkes Website                                              \\
//                                          Developed and Maintained by E-volution                                     \\
//---------------------------------------------------------------------------------------------------------------------\\
//  All code, images and data collected remains the property of AJ Parkes & Co and may not be edited, re-distributed   \\
//            copied or sold. All work is subject to copyright and infringement may result in legal action.            \\
//---------------------------------------------------------------------------------------------------------------------\\
//          Phone: 07 3349 7224     ---     Mobile: 0401 499 477     ---     E-mail: admin@e-volution.com.au           \\
//---------------------------------------------------------------------------------------------------------------------\\
//                                      Designer: Brent Wilkinson     Date: Mar, 2008                                  \\
//                                       ----- AJ Parkes Javascript Functions -----                                    \\
//---------------------------------------------------------------------------------------------------------------------\\

function ImgSwap(el,val)
{	
	if(event.type == 'mouseover')
	{	el.src = window.sht + '/img/ajparkes_' + val + '_hi.jpg';	}
	else
	{	el.src = window.sht + '/img/ajparkes_' + val + '.jpg';	}
}

function ImgSwap_Rev(el,ref,val,nme)
{	
	if(ref == 'brands') {
		var mark	= window.brands;
	}	
	else {
		var mark	= window.menu;
	}
	
	if(event.type == 'mouseover')
	{	
		for(a = 0; a < mark.length; a++) {
			if(nme == mark[a]) {
				document.getElementById(val + '_' + mark[a]).src = window.sht + '/img/ajparkes_' + val + '_' + mark[a] + '.jpg';		
			}
			else {
				document.getElementById(val + '_' + mark[a]).src = window.sht + '/img/ajparkes_' + val + '_' + mark[a] + '_hi.jpg';	
			}
		}
	}
	else
	{	
		for(a = 0; a < mark.length; a++) {
			document.getElementById(val + '_' + mark[a]).src = window.sht + '/img/ajparkes_' + val + '_' + mark[a] + '.jpg';	
		}
	}
}

function managePopUps(tgt_window, tgt_width, tgt_height, tgt_url)
{ 
	if	(!tgt_width)
	{ tgt_width = '150'; }

	if	(!tgt_height)
	{ tgt_height = '250'; }

	if	(!window.activePopups)
	{ window.activePopups = new Array(); }
	
	// Create popup and populate popup registry
	if		(tgt_url)
	{ window.activePopups[tgt_window] = window.open(tgt_url, tgt_window,"location=1,status=0,resizable=1,scrollbars=1,width="+tgt_width+",height="+tgt_height); }
	else
	{ alert('No target URL entered, window could not be opened'); }
	// End of the above
}


// Custom request object
function cvConnect() {}

// Creates new XMLHttpRequest to server
cvConnect.prototype.create				= function(procID,optID,optVL) {
	if(optVL)
	{
		optVL							= optVL.replace('&','--AMPISAND--');
		optVL							= optVL.replace(';',' ');
	}
	this.newRequest						= new XMLHttpRequest();
	// Create new XMLHttpRequest
	this.newRequest.open("GET", '?nav=124;oP='+procID+';iD='+optID+';vL='+optVL, true);
	this.newRequest.onreadystatechange 	= this.read;
  	// Set custom request headers to access secure server
    this.newRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");			// Stop caching
	this.newRequest.setRequestHeader("X-AJP-REQ", "true");											
	this.newRequest.setRequestHeader("Connection", "close");
	this.newRequest.send(null);
};

// Reads response from new XMLHttpRequest
cvConnect.prototype.read				= function() { 
	if(this.readyState == 4) 
	{	
		if(this.status == 200) { 
			if(this.responseText != 'false')
			{
				returns		= this.responseText.split('---SPLIT---');
				if(returns[0] != '' && returns[0] != 'false')
				{
					document.getElementById('GCAM_Order_Details').innerHTML	= returns[0];
				}
				if(returns[1] != '' && returns[1] != 'false')
				{
					document.getElementById('notebar_body').innerHTML		= returns[1];
				}
			}
			else
			{
				document.getElementById('GCAM_Order_Details').innerHTML	= 'Help';
			}
		}
		else {
			document.getElementById('main_body').innerHTML	= 'ERROR: Failed to load object....';
		}
	}
};

cvConnect.prototype.textUpdate		= function(idnum,refnum) {
	this.create('update',idnum,document.getElementById(idnum).value); 
	document.getElementById('preview'+refnum).src = '?gdimage=true;gdtype=preview;srcImage=GCAM_'+document.getElementById(refnum+'_mType').value+'.jpg;text1='+document.getElementById(refnum+'_mLine1').value.replace('&','--AMPISAND--')+';text2='+document.getElementById(refnum+'_mLine2').value.replace('&','--AMPISAND--')+';text3='+document.getElementById(refnum+'_mLine3').value.replace('&','--AMPISAND--')+';text4='+((!document.getElementById(refnum+'_mLine4')) ? 'NA' : document.getElementById(refnum+'_mLine4').value.replace('&','--AMPISAND--'));	
};

// Custom request object
function cvConnect2() {}

// Creates new XMLHttpRequest to server
cvConnect2.prototype.create				= function(procID,optID,optVL) {
	if(optVL)
	{
		optVL							= optVL.replace('&','--AMPISAND--');
		optVL							= optVL.replace(';',' ');
	}
	this.newRequest						= new XMLHttpRequest();
	// Create new XMLHttpRequest
	this.newRequest.open("GET", '?nav=126;oP='+procID+';iD='+optID+';vL='+optVL, true);
	this.newRequest.onreadystatechange 	= this.read;
  	// Set custom request headers to access secure server
    this.newRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");			// Stop caching
	this.newRequest.setRequestHeader("X-AJP-REQ", "true");											
	this.newRequest.setRequestHeader("Connection", "close");
	this.newRequest.send(null);
};

// Reads response from new XMLHttpRequest
cvConnect2.prototype.read				= function() { 
	if(this.readyState == 4) 
	{	
		if(this.status == 200) { 
			if(this.responseText != 'false')
			{
				returns		= this.responseText.split('---SPLIT---');
				if(returns[0] != '' && returns[0] != 'false')
				{
					document.getElementById('GCAM_Order_Details').innerHTML	= returns[0];
				}
				if(returns[1] != '' && returns[1] != 'false')
				{
					document.getElementById('notebar_body').innerHTML		= returns[1];
				}
			}
			else
			{
				document.getElementById('GCAM_Order_Details').innerHTML	= 'Help';
			}
		}
		else {
			document.getElementById('main_body').innerHTML	= 'ERROR: Failed to load object....';
		}
	}
};

cvConnect2.prototype.textUpdate		= function(idnum,refnum) {
	this.create('update',idnum,document.getElementById(idnum).value); 
	document.getElementById('preview'+refnum).src = '?gdimage=true;gdtype=preview;srcImage=AUSUNI_'+document.getElementById(refnum+'_mType').value+'.jpg;text1='+document.getElementById(refnum+'_mLine1').value.replace('&','--AMPISAND--')+';text2='+document.getElementById(refnum+'_mLine2').value.replace('&','--AMPISAND--')+';text3='+document.getElementById(refnum+'_mLine3').value.replace('&','--AMPISAND--')+';text4='+((!document.getElementById(refnum+'_mLine4')) ? 'NA' : document.getElementById(refnum+'_mLine4').value.replace('&','--AMPISAND--'));	
};



// Custom request object
function cvRegister() {}

// Creates new XMLHttpRequest to server
cvRegister.prototype.oAction			= function(oCommand,oField,oValue) {
	if(oValue)
	{
		oValue							= oValue.replace('&','--AMPISAND--');
	}
	this.newRequest						= new XMLHttpRequest();
	// Create new XMLHttpRequest
	this.newRequest.open("GET", '?nav=125;oCommand='+oCommand+';oField='+oField+';oValue='+oValue, true);
	this.newRequest.onreadystatechange 	= this.oRead;
  	// Set custom request headers to access secure server
    this.newRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");			// Stop caching
	this.newRequest.setRequestHeader("X-AJP-REQ", "true");											
	this.newRequest.setRequestHeader("Connection", "close");
	this.newRequest.send(null);
};

// Reads response from new XMLHttpRequest
cvRegister.prototype.oRead				= function() { 
	if(this.readyState == 4) 
	{	
		if(this.status == 200) { 
			if(this.responseText != 'false')
			{
				document.getElementById('NBP_Registration').innerHTML	= this.responseText;
				if(this.responseText.indexOf('<!-- Registration Complete -->') != -1)
				{
					window.scroll(0,0);
				}
			}
		}
		else {
			document.getElementById('main_body').innerHTML	= 'ERROR: Failed to load object....';
		}
	}
};

window.defaultStatus	= 'Welcome to the AJ Parkes company portal....';