//Standard site functions
function fnChangeImage(Obj, Img){
	Obj.src = '../images/'+Img;
}

function fnSubmitForm(Obj1, IPValue){
		Obj1.mode.value = IPValue;
		Obj1.submit();
}

function fnSubmitItem(obj){
	var i
	for (i=0; i<document.all.item(obj).options.length; i++){
			document.all.item(obj).options[i].selected = true
	}
	
	return true;
}

function fnLoadContent(url){
	document.getElementById('ContentiFrame').src = url;
}

function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}

function fnStatusChange(Obj){
	window.status = Obj
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}

function addCatItem(obj, obj1, obj2, obj3){
	var i
	
	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].selected==true){
			addNewItem(obj, obj3, obj2, document.all.item(obj1).options[i].value, document.all.item(obj1).options[i].text)
		}
	}	
}

function addNewItem(obj, obj1, obj2, id, name){
	var i
	addOption = true
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if(document.all.item(obj2).options[i].value == id){
			addOption = false
		}
	}
	
	if (addOption == true){
		document.all.item(obj2).options[document.all.item(obj2).options.length] = new Option(name, id)

		if (obj == 'event' || obj == 'categories'){
			if (document.all.item(obj2).options.length == 1){
				document.all.item(obj1).value = id
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+id
			}
		}
	}
}

function removeCatItem(obj, obj1, obj2){
	var i
	var oElements
	var CatID
	var SelCat
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if (document.all.item(obj2).options[i].selected==true){
			CatID = document.all.item(obj2).options[i].value
			document.all.item(obj2).options.remove(i)
		}
	}
	
	if (obj == 'event' || obj == 'categories'){
		for (i=0; i<document.all.item(obj2).options.length; i++){
			document.all.item(obj2).options[i].selected = true
		}
		
		oElements = document.all.item(obj2).value.split(",");
		document.all.item(obj1).value = "";
		for (i=0;i<oElements.length;i++){
			if (oElements.length == 1){
				document.all.item(obj1).value = oElements[i]
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+oElements[i]
			}
		}
	}
	
	if (obj == 'request'){
		document.location.replace("default.asp?cid=7&rid="+CatID)
	}
}

function fnValidateRequest(obj){
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide a first name");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide a last name");
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	if (document.getElementById('cboLocal').value == ""){
		alert("Please select your location");
		document.getElementById('cboLocal').focus();
		return false;
	}
	
	if (document.getElementById('cboProdSel').value == ""){
		alert("Please ensure that you have at least one product category you would be interested in.");
		document.getElementById('cboProdSel').focus();
		return false;
	}
}

function fnValidate(obj){
	if (document.getElementById('txtCompanyName').value == ""){
		alert("Please provide a company name");
		document.getElementById('txtCompanyName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactPerson').value == ""){
		alert("Please provide the name of the contact person");
		document.getElementById('txtContactPerson').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact number");
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
}

function fnValidateEmail(){
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide a email address");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
}

function fnValidateSignalUser(){
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide a first name.");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide a last name.");
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('cboUserLocations').value == 0){
		alert("Please select the location in which you reside.");
		document.getElementById('cboUserLocations').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNumber').value == ""){
		alert("Please provide a contact number.");
		document.getElementById('txtContactNumber').focus();
		return false;
	}
	
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide a email address.");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters.');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}
}

function login(){
	window.open('http://gci.global-view.com', 'contest', 'width=732,height=584,left=65,top=5, toolbar=1, scrollbars=1, resizable=1');
}

function fnOpenAccount(obj){
	window.open('/ext/alert.asp?id='+obj+'', 'Account', 'width=600,height=460,left=65,top=5,scrollbars=1,resizable=1,toolbar=1');
}

function fnMakeVisible(el){
	el.className="over";
	
}

function fnAlertMsg(){
	if (document.getElementById("detail").style.disabled == true){
		alert("Please save, complete and fax the FXKInetic agreement in order to continue the application")
	}
}

function fnMakeInvisible(el,count){
	var objID
	
	objID = getcookie('ImageBank')
	
	for (i=1;i<=count;i++){
		document.getElementById('Image'+i).className = "out";
	}
	
	document.getElementById(objID).className = "over";
}

function fnLoadLibrary(obj){
	//If part 2 of the array is 1 then load a new drop down, else expand the image library
	var oArray
	
	window.top.document.getElementById('maincontent').innerHTML = '';
	document.all.item('gallery').src = '';
	
	oArray = obj.split(":")
	if (oArray[1] == 0){
		fnMakeRequest('/process-gallery.asp?aid=photographer&id='+oArray[0]+'','',0)
	
		document.all.item('gallery').src = '/gallery.asp?gid='+oArray[0]
	}else{
		fnMakeRequest('/process-gallery.asp?aid=category&cid='+oArray[0]+'&level='+oArray[2]+'','',0)
	}
	
	//window.top.document.getElementById('toolbar').style.display = 'none';
}

function fnMakeRequest(url, action, obj) {
	var httpRequest;
	
	if (action == 'photodesc' && obj != 0){
		var txtDesc	
		
		txtDesc = document.getElementById('txtDescription'+obj).value
		url = url+'&desc='+txtDesc
	}else if (action == 'photokey' && obj != 0){
		var txtKeyword
		
		txtKeyword = document.getElementById('txtKeywords'+obj).value
		url = url+'&key='+txtKeyword
	}else if (action == 'imageload'){
		var cid
		
		cid = document.getElementById('cboCatList').value
		url = url+'&cid='+cid
	}else if (action == 'sum'){
		var iAmt
		
		url = url+'&aid=sum&amt='+obj
	}

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	httpRequest.onreadystatechange = function() { fnAlertContents(httpRequest); };
	httpRequest.open('GET', url, true);
	httpRequest.send(null);

}

function fnAlertContents(httpRequest) {
	try {
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				var rspText = httpRequest.responseText;
				var oResponseArray = rspText.split("|");
				if (oResponseArray[0] == 'photographer'){
					//document.getElementById('courtesy').value = oResponseArray[2];
					//document.getElementById('courtesycontent').innerHTML = oResponseArray[1];
				}else if (oResponseArray[0] == 'photodetail'){
					window.top.document.getElementById('maincontent').innerHTML = oResponseArray[1];
				}else if (oResponseArray[0] == 'photodesc'){
					document.getElementById(oResponseArray[2]).src = '/images/tick_on.gif'
					//setTimeout("fnMakeRequest('/process.asp?aid=photodetail&id="+oResponseArray[3]+"', '', 0);",1000);
				}else if (oResponseArray[0] == 'photokey'){
					document.getElementById(oResponseArray[2]).src = '/images/tick_on.gif'
					//setTimeout("fnMakeRequest('/process.asp?aid=photodetail&id="+oResponseArray[3]+"', '', 0);",1000);
				}else if (oResponseArray[0] == 'basket'){
					alert("The image has been added to your cart.")
				}else if (oResponseArray[0] == 'basketupdate'){
					document.location.reload()
				}else if (oResponseArray[0] == 'category'){
					window.top.document.getElementById('dropdowns').innerHTML = oResponseArray[1];
				}else {
					document.getElementById(oResponseArray[2]).value = document.getElementById(oResponseArray[2]).value +'\\'+ oResponseArray[1]
				}
			} else {
				alert('There was a problem with the request.');
			}
		}
	}
	
	catch( e ) {
		alert('Caught Exception: ' + e.description);
	}
}

function fnDisplayFloatingDiv(divId) 
{
	if (document.getElementById(divId).style.visibility == "visible"){
    	document.getElementById(divId).style.visibility = "hidden";
	}else{
		document.getElementById(divId).style.visibility = "visible";
	}
}

function fnGalleryBreakOut(obj){
	if (window.top!=window.self){
		fnMakeRequest('/process.asp?aid=photodetail&id='+obj+'','',0)
	}
}

function fnHighlightImage(obj){
	//Set a session cookie for thos 
	setcookie('ImageBank',obj,1)
	
	//window.top.document.getElementById('toolbar').style.display = 'block';
}

function setcookie(name,value,duration){
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	document.cookie=cookiestring;
}

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
 	var cookiestring=""+document.cookie;
 	var index1=cookiestring.indexOf(cookiename);
 	if (index1==-1 || cookiename=="") return ""; 
 	var index2=cookiestring.indexOf(';',index1);
 	if (index2==-1) index2=cookiestring.length; 
 	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function fnPopImage(url, width, height){
	window.open(url,'image','width='+width+', height='+height+', resizable=0, toolbar=1, menubar=0');
}

function fnLoadInvoice(){
	window.open("/ext/invoice.asp?print=1",'print','width=400, height=400, resizable=1, toolbar=1, menubar=0');
}

function fnPrint(){
	window.print();
}

function fnCheckUser(){
	if (document.getElementById('agree').checked != true){
		if (confirm("Would you be intereseted in receiving forex signals?\r\n\nIf you are, and would like a FXKinetic representative to contact you,\r\nclick ok.")){
			window.open("/ext/feedback.asp","signals","width=300,height=300")
		}
	}
}