var now = new Date();
var seed = now.getTime() % 0xffffffff;

function rand(n) 
{
/*	seed = (0x015a4e35 * seed) % 0x7fffffff;
	return ( seed >> 16 ) % n; */
	now = new Date();
	seed = now.getSeconds();
	var random_number = Math.random(seed);
	var range = random_number * n;
	var rounded_number = Math.round(range);
	if (rounded_number == n )
		rounded_number = 0 ;
	return rounded_number;
}

function popupTerms() {
	alert("We reserve the right to do whatever suits us whenever we feel like it. If you have a problem with this, you probably don’t belong in nclüdr, which would be weird since everyone and everything is in nclüdr anyway");
}
function popupHelp () {
	alert("There is no help. You're on your own, pal.");
}
function popupEditProfile () {
	alert("Need content");
}

function goToProfile() {
	window.location.href = "/profile.shtml";
}

function openCenteredWindow(mypage, w, h, scroll, resizable, menubar, toolbar) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+',menubar='+menubar+',toolbar='+toolbar
    win = window.open(mypage,'',winprops)
}

function popupBlind() {
    openCenteredWindow('/blind.shtml','300','300','no','no','no','no');
}
function popupEmailFriend() {
    openCenteredWindow('/email_friend.asp','600','400','no','no','no','no');
}

function getCookie(c_name)
{
	if (document.cookie.indexOf(c_name) != -1) // checks if a cookie is stored at all in the document.cookie object
 	{
 		c_start=document.cookie.indexOf(c_name + "=")
  		if (c_start!=-1) // check to see if our specific cookie is stored
    	{ 
    		c_start=c_start + c_name.length+1  
    		c_end=document.cookie.indexOf(";",c_start)
    		if (c_end==-1) 
    			c_end=document.cookie.length
    		return unescape(document.cookie.substring(c_start,c_end)) // return the value
    	} 
  	}
	return null
}

function setCookie(c_name,value,expiredays)
{
	document.cookie=c_name+ "=" +escape(value); // store the cookie name, cookie value and the expiration date in the document.cookie object
}
function checkTimeOnSite()
{
	cookieArrivedAtSite = getCookie("arrivedatSite");
	var timeNow = new Date();
	if ( ( (timeNow.getTime() - cookieArrivedAtSite) ) > 300000 )
		//alert("You've been on ncl&uuml;dr for over 10 minutes. Now the Flash Resolve should play.");
	{}
}

function checkNumbers(previousProfile, currentProfile) {
	if (currentProfile > previousProfile) {
		if (currentProfile - previousProfile < 12 ) {
			checkNumbers(previousProfile, rand(myObjectArray.length));
		}
	}
	if (currentProfile < previousProfile) {
		if (previousProfile - currentProfile < 12 ) {
			checkNumbers(previousProfile, rand(myObjectArray.length));
		}
	}	
	if (currentProfile < previousProfile)	
		currentProfile += 13;
	return currentProfile;
}

function writeFriendsList() {
	document.write("<ul id=\"all_friends_list\">");
	var previousProfile = 0;
	for (var jk = 0; jk < 10; jk++) {
		var usedProfiles=new Array();
		for (var i = 0; i<myObjectArray.length; i++)
		{
			var friendNum = rand(myObjectArray.length);
			while (usedProfiles[friendNum] == "yes" )
				friendNum = rand(myObjectArray.length);
			usedProfiles[friendNum] = "yes";
/*			if (i % 4 == 0)
				document.write("<li style='clear:left;'>");
			else */
			document.write("<li>");
			if (friendNum == 88)
				document.write("<a href='profile.shtml?profile=88'><img src='\/images\/profiles_friends_list\/49.jpg\'  id=\"profile_image\" alt=\"\" height='60' />");
			else
			document.write("<a href='profile.shtml?profile=" + friendNum + "'><img src='\/images\/profiles_friends_list\/" + friendNum + ".jpg\'  id=\"profile_image\" alt=\"\" height='60' />");
			document.write("<span class=\"friend_name\">");
			document.write(myObjectArray[friendNum].full_name);
			document.write("<\/span><\/a><\/li>");
		}
	}
	document.write("</ul>");
/*
for (var j = 0; j<900; j++)
{
	var c = rand(91);
if (j % 4 == 0)
	document.write("<li style='clear:left;'>");
else
	document.write("<li>");
document.write("<a href='profile.shtml?profile=" + c + "'><img src='\/images\/profiles\/" + c + ".jpg\'  id=\"profile_image\" alt=\"\" width='60'' />");
document.write("<span class=\"friend_name\">");
		document.write(myObjectArray[c].full_name);

document.write("<\/span><\/a><\/li>");
}
*/
}

function writeRegisterQuestions() {document.write("<div style=\"clear:left;\"></div>");
	var whichQuestion = rand(9);
	for (var i = 0; i < 3; i++)
	{
		var str = "q";
	str = str.concat(whichQuestion);
	document.getElementById(str).style.display = "block";
	if ( whichQuestion == 8)
		whichQuestion = 0
	else
		whichQuestion += 1;
	}
}

function submitRegisterForm(form){
	if (document.registration_form.full_name.value == "")
		alert("Please enter your name");
	else 
	{
		if (document.registration_form.i_am.value == "")
			alert("Please enter your gender");
		else
		{
			fullName=document.registration_form.full_name.value;
			gender=document.registration_form.i_am.value;

			setCookie("profileName",fullName,1800000)
			setCookie("profileGender",gender,1800000)
			window.location = "/processing.shtml";
//			Videobox.open("/flash/ProfileProcessor.swf","","vidbox 660 380");	
//		setTimeout('window.location = "/profile.shtml"', 9000);
		}
	}
}

function writeProfileImage() {
	if (params["profile"])		
	{
		profileNum = unescape(params["profile"]);
		if ( myObjectArray[profileNum].image_by != "unknown")
			document.write("<a href=\"javascript:photoCreditPopup(" + profileNum + ");\">");
		if (profileNum == 88)
			document.write("<img src='\/images\/profiles\/49.jpg\'  id=\"profile_image\" alt=\"\" />");
		else
			document.write("<img src=\"\/images\/profiles\/" + profileNum + ".jpg\"  id=\"profile_image\" alt=\"\" />");
		if (myObjectArray[profileNum].image_by != "unknown")
			document.write("<\/a>");
	}
	else
	{
		cookieSex = getCookie("profileGender");
		document.write("<img src='\/images\/profiles\/" + cookieSex + ".jpg\'  id=\"profile_image\" alt=\"\" />");		
	}
}

function photoCreditPopup(whichProfile) {
	var str = "/photo-credit.shtml?profile=" + whichProfile;
    openCenteredWindow(str,'700','300','no','no','no','no');
}
function writePhotoCredit() {
	var labelImage = "<p><strong>Image</strong>: ";
	var labelA = " a ";
	var labelImageFrom = " image from ";
	var labelBeginAnchor = "<a href='";
	var labelMiddle = "' target='_blank'>";
	var labelEndAnchor = "<\/a>";
	var labelEnd = "<\/p>";
	
	if (params["profile"])		
	{
		profileNum = unescape(params["profile"]);
		document.write(labelImage);
		document.write(myObjectArray[profileNum].source_url); 
		document.write(labelA);
		document.write(myObjectArray[profileNum].license); 
		document.write(labelImageFrom);
		if (myObjectArray[profileNum].image_by_url != "unknown") {
			document.write(labelBeginAnchor);
			document.write(myObjectArray[profileNum].image_by_url);
			document.write(labelMiddle);
			document.write(myObjectArray[profileNum].image_by);
			document.write(labelEndAnchor);
		}
		else
			document.write(myObjectArray[profileNum].image_by);
		document.write(labelEnd);
	}
}
function writeProfile () {
	var labelName = "<p class=\"profile_name\"><label>Name:<\/label>";
	var labelSex = "<\/p><\/div><p><label>Sex:<\/label>";
	var labelStatus = "<\/p><p><label>Status:<\/label>";
	var labelRelationshipStatus = "<\/p><p><label>Relationship Status:<\/label>";
	var labelLookingFor = "<\/p><p><label>Looking For:<\/label>";
	var labelPoliticalViews = "<\/p><p><label>Political Views:<\/label>";
	var labelAbout = "<\/p><p><label>About me:<\/label>";
	var labelDoneRecently = "<\/p><p><label>Things I've Done Recently:<\/label>";
	var labelInterests = "<\/p><p><label>Interests:<\/label>";
	var labelQuote = "<\/p><p><label>Favorite Quote:<\/label>";
	var labelEnd = "<\/p>";
	
	if (params["profile"])		
	{
		profileNum = unescape(params["profile"]);
		document.write(labelName);
		document.write(myObjectArray[profileNum].full_name);
		document.write(labelSex);
		document.write(myObjectArray[profileNum].sex);
		document.write(labelStatus);
		document.write(myObjectArray[profileNum].status);
		document.write(labelRelationshipStatus);
		document.write(myObjectArray[profileNum].relationship_status);
		document.write(labelLookingFor);
		document.write(myObjectArray[profileNum].looking_for);
		document.write(labelPoliticalViews);
		document.write(myObjectArray[profileNum].political_views);
		document.write(labelAbout);
		document.write(myObjectArray[profileNum].about_me);
		document.write(labelDoneRecently);
		document.write(myObjectArray[profileNum].done_recently);
		document.write(labelInterests);
		document.write(myObjectArray[profileNum].interests);
		document.write(labelQuote);
		document.write(myObjectArray[profileNum].quote);
		document.write(labelEnd);
		if (profileNum == 49)
			document.write("<p><a href=\"/profile.shtml?profile=88\">View Related Profile</a></p>");
		if (profileNum == 88)
			document.write("<p><a href=\"/profile.shtml?profile=49\">View Related Profile</a></p>");
	}
	else
	{
		var num = rand(31);
		document.write(labelName);
		cookieName = getCookie("profileName");
		document.write(cookieName);
		document.write(labelSex);
		cookieSex = getCookie("profileGender");
		document.write(cookieSex);
		document.write(labelStatus);
		document.write(randomProfilesArray[num].status);
		document.write(labelRelationshipStatus);
		document.write(randomProfilesArray[num].relationship_status);
		document.write(labelLookingFor);
		document.write(randomProfilesArray[num].looking_for);
		document.write(labelPoliticalViews);
		document.write(randomProfilesArray[num].political_views);
		document.write(labelAbout);
		document.write(randomProfilesArray[num].about_me);
		document.write(labelDoneRecently);
		document.write(randomProfilesArray[num].done_recently);
		document.write(labelInterests);
		document.write(randomProfilesArray[num].interests);
		document.write(labelQuote);
		var num2 = rand(93);
		document.write(myObjectArray[num2].quote);		
		document.write(labelEnd);	
	}
}

function writeFavFriendsItem(whichFriend) {
	document.write("<li><a href='profile.shtml?profile=" + whichFriend + "'><img src='\/images\/profiles_friends_list\/" + whichFriend + ".jpg\'  alt=\"" + myObjectArray[whichFriend].full_name + "\" width='40' /><span>"+ myObjectArray[whichFriend].full_name + "</span></a></li>");
}

function writeFavFriendsList() {
var beginFavFriendsList = "<ul>";
	document.write("<ul>");
	writeFavFriendsItem(11);
	writeFavFriendsItem(26);
	writeFavFriendsItem(44);
	writeFavFriendsItem(50);
	writeFavFriendsItem(57);
	writeFavFriendsItem(76);
	writeFavFriendsItem(84);
	writeFavFriendsItem(33);
	writeFavFriendsItem(30);
	document.write("</ul>");
}

function playFlashReg() {
//	Videobox.open("/flash/ProfileProcessor.swf","","vidbox 660 380");
// openCenteredWindow('/flash/ProfileProcessor.swf','800','800','no','no','no','no');
window.location = "/processing.shtml";
//	setTimeout('window.location = "/profile.shtml"', 9000);
}

function writeFooterPhotoCredits() {
	if (document.body.id == "profile") {
		if (params["profile"])	 {
			profileNum = unescape(params["profile"]);
			if ( myObjectArray[profileNum].image_by != "unknown")
				document.write("<li><a href=\"javascript:photoCreditPopup(" + profileNum + ");\">Photo Credits<\/a><\/li>");
		}
	}
}

window.onload = function () {
	if (document.body.id == "homepage")
	{
		var myDate = new Date();
		if ( getCookie("arrivedatSite") )
		{}
		else
			setCookie("arrivedatSite",myDate.getTime())	
	}
	else
		checkTimeOnSite();
}