function viewlineup(planID,type) {
  window.open("lineup.php?planID="+planID+"&type="+type,"lineup","width=500,height=300,scrollbars=1,resizable=1,toolbar=0");
}

function viewimage(image,w,h) {
  window.open("/image.php?img="+image,"lineup","width="+w+",height="+h+",scrollbars=no");
}

String.prototype.strReverse = function() {
	var newstring = "";
	for (var s=0; s < this.length; s++) {
		newstring = this.charAt(s) + newstring;
	}
	return newstring;
	//strOrig = ' texttotrim ';
	//strReversed = strOrig.revstring();
};

function openusercheckwindow() {
    var cool = window.open('http://ccc.gwtc.net/checkgwuser.php','checkusername','width=300,height=200,left=200,top=200,resizeable=no,scrollbar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
		cool.focus();
  return true;
} 

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject


function randomString() {
	var chars = "0123456789abcdefghiklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890123456789012345678901234567890123456789";
	var string_length = 8;
	var randomstringvalue = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstringvalue += chars.substring(rnum,rnum+1);
	}
	return randomstringvalue;
}

function newuserrandompassword() {
  document.order.pass1.value = randomString();
	return true;
}

function addemailresrandompassword() {
  document.order.add_email_pass_res.value = randomString();
	return true;
}

function addemailbusrandompassword() {
  document.order.add_email_pass_bus.value = randomString();
	return true;
}

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
    styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function toggleObjectVisibility(objectId) {
  var styleObject = getStyleObject(objectId);
	if(styleObject) {
	  currentVisibility = styleObject.visibility;
		if((currentVisibility == "") || (currentVisibility == "visible")) {
		  changeObjectVisibility(objectId, 'hidden');
		} else {
		  changeObjectVisibility(objectId, 'visible');
		}
	} else {
	  return false;
	}
}

function changeObjectDisplay(objectId, newDisplay) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
//	styleObject.visibility = newVisibility;
    styleObject.display = newDisplay;
    
    if (objectId == 'userpass' && newDisplay == '') { document.order.currentaddress.value = ""; }
    if (objectId == 'userpass' && newDisplay == 'none') {
    	document.order.user1.value = "";
    	document.order.user2.value = "";
    	document.order.pass1.value = "";
    	document.order.pass2.value = "";
    }
    
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function toggleObjectDisplay(objectId) {
  var styleObject = getStyleObject(objectId);
	if(styleObject) {
	  currentDisplay = styleObject.display;
		if((currentDisplay == "") || (currentDisplay == "visible") || (currentDisplay == "block")) {
//		  changeObjectVisibility(objectId, 'none');
		  changeObjectDisplay(objectId, 'none');
		} 
		else {
//		  changeObjectVisibility(objectId, 'visible');
		  changeObjectDisplay(objectId, '');
		}
	} 
	else {
	  return false;
	}
}

function isPasswordOK(user,pass) {
	if(pass.length < 8) {
		return "The password is not long enough.";
	}
		
	reg = new RegExp("password","i");
	if(pass.match(reg)) {
		return "The password contains the word password.";
	}
	
	reg = new RegExp("(p[\@a][\$s5][\$s5])(w[0o]rd)","i");
	if (pass.match(reg)) {
		return "The password is too similar to the word 'password'.";
	} else {
		//return "The password is too similar to the word 'password'.";
	}
	
	reg = new RegExp(user,"gi");
	if(pass.match(reg)) {
		return "The username is in the password.";
	}
	
	revuser = user.strReverse();
	reg = new RegExp(revuser,"i");
	if(pass.match(reg)) {
		return "The username reversed is in the password.";
	}
	
	reg = new RegExp(pass,"i");
	if (user.match(reg)) {
		return "The password is in the username";
	}
	
	reg = new RegExp("[0-9]");
	if(pass.match(reg)) {

	} else {
		return "The password needs a number.";
	}
	
	reg = new RegExp("[a-zA-Z]");
	if (pass.match(reg)) {
	
	} else {
		return "The password needs letters.";
	}
	
	reg = new RegExp("['\"*&$^@\\/\\-\\[\\]\\s\\\\\\[\\]\\(\\)\\{\\}]");
	if (pass.match(reg)) {
		return "The password has invalid puncuation.";
	}	
	return "OK";
}

function checkNewUserPassword1() {
	result = isPasswordOK(document.order.user1.value,document.order.pass1.value);
	if (result == "OK") {
		alert('The password is OK');
	} else {
		alert(result);
		document.order.pass1.focus();
	}
	return false;
}

function checkNewUserPasswordtest(inputname) {
	if (inputname == 1) {
	  result = isPasswordOK(document.order.user1.value,document.order.pass1.value);
	  if (result == "OK") {
		//alert('The password is OK');
		  document.order.passtest1.value = 'the password is OK';
	  } else {
		//alert(result);
		document.order.passtest1.value = result;
		document.order.pass1.focus();
	  }
	  return false;
	}
	if (inputname == 2) {
		  result = isPasswordOK(document.order.user2.value,document.order.pass2.value);
		  if (result == "OK") {
			//alert('The password is OK');
			document.order.passtest2.value = 'The password is OK';
		  } else {
			//alert(result);
			document.order.passtest2.value = result;
			document.order.pass2.focus();
		  }
		  return false;
		}
}

function checkNewUserPassword2() {
	result = isPasswordOK(document.order.user2.value,document.order.pass2.value);
	if (result == "OK") {
		alert('The password is OK');
	} else {
		alert(result);
		document.order.pass2.focus();
	}
	return false;
}

function checkAddEmailPasswordRes() {
	result = isPasswordOK(document.order.add_email_addy_res.value,document.order.add_email_pass_res.value);
	if (result == "OK") {
		alert('The password is OK');
	} else {
		alert(result);
		document.order.add_email_pass_res.focus();
	}
	return false;
}

function checkAddEmailPasswordBus() {
	result = isPasswordOK(document.order.add_email_addy_bus.value,document.order.add_email_pass_bus.value);
	if (result == "OK") {
		alert('The password is OK');
	} else {
		alert(result);
		document.order.add_email_pass_bus.focus();
	}
	return false;
}
