function uniqueID() {
	var x = Math.floor(Math.random()*100000);
	return x;
}

function pageTrack(IP, PageID, ProductID, ContactID) {
	var city = ip2location_city();
	var region = ip2location_region();
	var zip = ip2location_zip_code();
	var isp = ip2location_isp();
	var domain = ip2location_domain();
	var ac = ip2location_area_code();
	new Ajax.Request('index.php?Action=PageTrack&IP='+IP+'&PageID='+PageID+'&ProductID='+ProductID+'&ContactID='+ContactID+'&City='+city+'&Region='+region+'&Zip='+zip+'&ISP='+isp+'&Domain='+domain+'&ac='+ac+'&uid='+uniqueID(), {
	  method: 'get'
	});
	return false;
}

function openWindow(obj, width, height, title, html) {
  var effect = new PopupEffect(obj, {className: "popup_effect1"});
  var win = new Window({className:"darkX", width: width, height: height, showEffect:effect.show.bind(effect), hideEffect:effect.hide.bind(effect)});
	win.setTitle(title);
	win.getContent().update(html);
	win.setDestroyOnClose();		    
	win.showCenter(true);
	Effect.Appear(win.getId(), { duration: 0.5 });
}  		

function closeWindow() {
	Effect.Fade(top.Windows.focusedWindow.getId(), { duration: 0.5 });
	top.Windows.focusedWindow.setHTMLContent('');
	top.Windows.close(top.Windows.focusedWindow.getId());
}

function openDialog(obj, width, height, title, html) {
  var effect = new PopupEffect(obj, {className: "popup_effect1"});
  var win = new Window({className:"darkX", width: width, height: height, showEffect:effect.show.bind(effect), hideEffect:effect.hide.bind(effect), closable: false, minimizable: false, maximizable: false});
	win.setTitle(title);
	win.getContent().update(html);
	win.setDestroyOnClose();		    
	win.showCenter(true);
}

function openPhoto(obj, width, height, title, html) {
  var effect = new PopupEffect(obj, {className: "popup_effect1"});
  var win = new Window({className:"darkX", width: width, height: height, showEffect:effect.show.bind(effect), hideEffect:effect.hide.bind(effect), closable: true, minimizable: false, maximizable: false});
	win.setTitle(title);
	win.getContent().update(html);
	win.setDestroyOnClose();		    
	win.showCenter(true);
}

function showLoading(dialog) {
	document.getElementById('DIV_Loading').style.display = 'block';
	document.getElementById('DIV_LoadingMessage').innerHTML = dialog;
}

function hideLoading() {
	document.getElementById('DIV_Loading').style.display = 'none';
}

function checkPW() {
	if(document.getElementById('Password1').value == document.getElementById('Password2').value && document.getElementById('Password1').value != '' && document.getElementById('Password2').value != '') {

	}
	else {
		alert("Passwords do not match!  Please try again!");
		document.getElementById('Password1').value = "";
		document.getElementById('Password2').value = "";
		document.getElementById('Password1').focus();
	}
}

function contactUs(obj) {
	new Ajax.Request('index.php?Action=ContactUs'+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openWindow(obj, 400, 280, 'Contact Us', req.responseText);
		}
	});
}

function contactSubmit() {
  $('FORM_Contact').request({
  	onLoading: function(req){
			document.getElementById('ContactForm').innerHTML = '<div align="center" class="Title" style="height: 246px; vertical-align: middle;"><br/><br/><br/>SENDING INFORMATION...<br/><img src="/musicmerch/images/loading.gif"/></div>';
		},
  	onSuccess: function(req){
			document.getElementById('ContactForm').innerHTML = req.responseText;
		}
	});
}

function clientLogin() {
  $('FORM_Login').request({
    onSuccess: function(req){
  		temp = req.responseText.split('|');
  		if(temp[1] == 'OK') {
  			clientTasks(temp[2]);
  			document.getElementById('ClientInfo').innerHTML = temp[0];
  		}
  		else {
  			openDialog(document.getElementById('ClientInfo'), 320, 76, 'Bad Email/Password Combination', temp[0]);
  		}
		}
  });
  return false;
}

function clientLogout() {
	new Ajax.Request('index.php?Action=ClientLogout'+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
		Effect.SlideDown('ClientInfo', { duration: 2.0 });
		document.getElementById('ClientInfo').innerHTML = req.responseText;
		}
	});
  return false;
}

function clientTasks(CustomerNumber) {
	new Ajax.Request('index.php?Action=ClientTasks&CustomerNumber='+CustomerNumber+'&uid='+uniqueID(), {
	  method: 'get',
	  onCreate: function(req) { 
			showLoading('Gathering Your Information...');
		}, 
		onComplete: function(req) { 
			hideLoading();
			document.getElementById('ClientTasks').innerHTML = req.responseText;
		}
	});
}

function clientArtWindow() {
	new Ajax.Request('index.php?Action=ClientArtWindow&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) {
			temp = req.responseText.split('|');
			openWindow(document.getElementById('ClientArtIcon'), 1000, 660, 'ART FOR:&nbsp;&nbsp;'+temp[1], temp[0]);
			document.getElementById('StatusLegend').innerHTML = document.getElementById('ArtStatus').options[document.getElementById('ArtStatus').selectedIndex].text;
			clientArt(document.getElementById('ArtStatus').value);
		}
	});
}

function clientArt(Status) {
	new Ajax.Request('index.php?Action=ClientArt&Status='+Status+'&uid='+uniqueID(), {
	  method: 'get',
	  onCreate: function() {
			showLoading('Gathering Order Information...');
		},  
		onSuccess: function(req) {
			document.getElementById('StatusLegend').innerHTML = document.getElementById('ArtStatus').options[document.getElementById('ArtStatus').selectedIndex].text;
			document.getElementById('ClientArt').innerHTML = req.responseText;
		}, 
		onComplete: function(req) {
			hideLoading();
			artView(document.getElementById('ArtDates').value);
		}
	});
}

function artView(track, size) {
	if(size != undefined) {	
		new Ajax.Request('index.php?Action=ArtView&Track='+track+'&Size='+size+'&uid='+uniqueID(), {
		  method: 'get',
		  onCreate: function() {
				showLoading('Retreiving Art...');
			},  
			onComplete: function(req) {
				document.getElementById('ArtInfo').style.overflow = 'auto';
				document.getElementById('ArtInfo').innerHTML = req.responseText;
				hideLoading();
			}
		});
	}
	else {
		new Ajax.Request('index.php?Action=ArtView&Track='+track+'&uid='+uniqueID(), {
		  method: 'get',
		  onCreate: function() {
				showLoading('Retreiving Art...');
			},  
			onSuccess: function(req) {
				document.getElementById('ArtInfo').innerHTML = req.responseText;
			}, 
			onComplete: function(req) {
				hideLoading();
			}
		});
	}
}

function clientAccount(ContactID, Task, opt) {
	if(Task == 'CustomerNumberRequest') {
		new Ajax.Request('index.php?Action=ClientAccount&Task='+Task+'&uid='+uniqueID(), {
		  method: 'get',
			onSuccess: function(req) {
				openWindow(document.getElementById('CreateAccountButton'), 460, 260, 'BACKSTAGE PASS', req.responseText);
			}
		});
	}	
	if(Task == 'CustomerNumberCheck') {
		$('FORM_ClientAccount').request({
			onLoading: function(req) {
				showLoading('Searching For Your Account Information...')
			}, 
	    onSuccess: function(req){
				top.Windows.focusedWindow.getContent().update(req.responseText);
				top.Windows.focusedWindow.setSize(460, 180);
				top.Windows.focusedWindow.showCenter();
			}
		});
	}	
	if(Task == 'AccountInfo') {
		if(opt == undefined) {
			$('FORM_ClientAccount').request({
				onLoading: function(req) {
	
				}, 
		    onSuccess: function(req){
					top.Windows.focusedWindow.getContent().update(req.responseText);
					top.Windows.focusedWindow.setSize(700, 330);
					top.Windows.focusedWindow.showCenter();
				}
			});
		}
		else {
			new Ajax.Request('index.php?Action=ClientAccount&Task='+Task+'&uid='+uniqueID(), {
			  method: 'get',
				onSuccess: function(req) {
					openWindow(document.getElementById('MyPass'), 700, 330, 'BACKSTAGE PASS', req.responseText);
				}
			});
		}
	}
	
	if(Task == 'ClientAccountUpdate') {
		$('FORM_ClientAccount').request({
			onLoading: function(req) {
				showLoading('Updating Your Account...')
			}, 
	    onSuccess: function(req){
				hideLoading();
				top.Windows.focusedWindow.getContent().update(req.responseText);
				top.Windows.focusedWindow.setSize(360, 140);
				top.Windows.focusedWindow.showCenter();
			}
		});
	}
	return false;
}

function passwordHelp(obj) {
	new Ajax.Request('index.php?Action=PasswordHelp&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openWindow(obj, 340, 96, 'Reset Password', req.responseText);
		}
	});
}

function passwordResetRequest() {
	$('FORM_PasswordResetRequest').request({
	    onSuccess: function(req){
				document.getElementById('DIV_PasswordReset').innerHTML = req.responseText;
			}
	});
}

function passwordResetConfirm(obj, ContactID, CC) {
	new Ajax.Request('index.php?Action=PasswordResetConfirm&ContactID='+ContactID+'&CC='+CC+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openWindow(obj, 480, 260, 'Reset Password Confirmation', req.responseText);
		}
	})
}

function passwordReset() {
	$('FORM_PasswordReset').request({
	    onSuccess: function(req){
				document.getElementById('DIV_PasswordReset').innerHTML = req.responseText;
			}
	});
}
function passwordResetDone() {
	closeWindow();
	location.href="index.php";
}

function optOut(obj, ContactID) {
	new Ajax.Request('index.php?Action=OptOutForm&ContactID='+ContactID+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openWindow(obj, 400, 100, 'Opt-Out', req.responseText);
		}
	});
}

function optoutConfirm() {
  $('FORM_OptOut').request({
      onSuccess: function(req){
  			document.getElementById('DIV_OptOut').innerHTML = req.responseText;
			}
	});
}

function galleryView(PageID, GalleryID) {
	location.href = 'index.php?PageID='+PageID+'&GalleryID='+GalleryID+'&uid='+uniqueID()
}

function galleryImage(obj, ImageID) {
	new Ajax.Request('index.php?Action=GalleryImage&ImageID='+ImageID+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openPhoto(obj, 480, 480, 'Gallery Image', req.responseText)
		}
	});
}

function productRotate(PageID) {
	new Ajax.Request('index.php?Action=ProductRotate&PageID='+PageID+'&uid='+uniqueID(), {
	  method: 'get',
	  onLoading: function() {

		},
		onSuccess: function(req) {
			document.getElementById('ProductPreview').innerHTML = req.responseText;
		}
	});
	return false;
}

function productView(PageID, ProductID) {
	location.href = 'index.php?PageID='+PageID+'&ProductID='+ProductID+'&uid='+uniqueID()
}

function productPhoto(obj, PhotoID) {
	new Ajax.Request('index.php?Action=ProductPhoto&PhotoID='+PhotoID+'&uid='+uniqueID(), {
	  method: 'get',
		onSuccess: function(req) { 
			openPhoto(obj, 480, 480, 'Product Photo', req.responseText)
		}
	});
}