var displayNum = 0;
var NS = (document.layers) ? 1 : 0;

// calculate the distance between two coordinates based on radians
var radian = 180/Math.PI;
var a = 6378.14;
var f = 1/298.257;
var e = 0.08181922;
var angsgn = " ";     

//-----------------------------
//-----------------------------
function ViewImage(LgImagePath) { 
	var win;
	var sWidth;
	var sHeight;
	
	win = window.open("","imageviewer","width=300,height=300,scrollbar=auto,menubar=no,toolbar=no,resizable=yes");

	win.document.open();
	win.document.write("<html><head><title>Member Photo</title>");
	win.document.write("</head><body>");
	win.document.write("<img src='" + LgImagePath + "' border='0'/></body></html>");
	win.document.close();
	win.focus();
	}
	
//-----------------------------
//-----------------------------
function popLink(link,winname,settings){
    popup = window.open (link, winname, settings)
}	

//-----------------------------
//-----------------------------
function mediaplay(ID) {
	if (ID == 107){ 
	var allcookies = document.cookie;
	allcookies = unescape(allcookies);
	var pos = allcookies.indexOf("USERTYPE=");
	if(pos != -1) {
		var start = pos + 9; 
		var end = start + 1;
		var value = allcookies.substring(start, end);
		if(parseInt(value) != 3) {window.location.href = "locked.aspx?pagename=P"}
		else {window.open('PlayMessage.aspx', 'xyz', 'height=300,width=430,scrollbars=no');}
		}
	}
}

//-----------------------------
//-----------------------------
function ParseQuotes(sString)
{
	var iCounter;
	var iLen = sString.length;
	var sNewString ='';
	var cChar = '';
		
	for (iCounter =0;iCounter < iLen; iCounter++)	
	{
		cChar = sString.charAt(iCounter)
		if (cChar == '\'')
			sNewString += '\'';					
		else
			sNewString += cChar;			
	}	
	return sNewString
}

//-----------------------------
//-----------------------------
function sendEyeContact(MemberID, Handle, FileName, PageName, PageNum, SortID)
{
   window.location.href = "members.aspx?pagename=A5a7&MemberID=" + MemberID + "&pgid=" + FileName + "&pgname=" + PageName + "&Handle=" + Handle + "&gpg=" + PageNum + "&so=" + SortID;

}

//-----------------------------
//-----------------------------
function profileviewlinks(PageID,ID,Handle,MemberType) {

	var theForm;
	var pagenumber;
	
	//search
	if(typeof(document.frmSearch) != "undefined") 
	{
		theForm = document.frmSearch; 
		pagenumber = theForm.PageNumber.value;
	}
	//others
	else if(typeof(document.frmMemberListing) != "undefined") 
	{
		theForm = document.frmMemberListing;
		pagenumber = theForm.pgn.value;
	}
	
	//Handle = escape(Handle)
	if (PageID == '70')
	{
		window.open('http://www.microsoft.com/windows/windowsmedia/en/Download/default.asp','i','scrollbars=yes');
	}
	if (PageID == '71')//SEND A MESSAGE
	{ 
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		if(pos != -1) 
		{
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			/* Gold members can send messages */
			if(parseInt(value)==3) 
			{
				//alert('3');
				//window.open('members.aspx?pagename=A5a2&ID_Member=' + ID + '&MemberType=' + MemberType,'j','height=500,width=420,scrollbars=yes');
				window.location.href = "members.aspx?pagename=A5a2_2&ID_Member=" + ID + "&MemberType=" + MemberType;
			}		
			/* Allow all users to send messages to Platinum members */
			else if(parseInt(value)==4) 
			{
				//alert('4');
				//window.open('members.aspx?pagename=A5a2&ID_Member=' + ID + '&MemberType=' + MemberType,'j','height=500,width=420,scrollbars=yes');
				window.location.href = "members.aspx?pagename=A5a2_2&ID_Member=" + ID + "&MemberType=" + MemberType;
			}
			//else if(parseInt(value)==2)
			//{
			//	var rdirStr = "members.aspx?pagename=A5a2_2&ID_Member=" + ID + "&MemberType=" + MemberType
			//	window.location.href = "locked.aspx?pagename=P&RedirectLogin=" + escape(rdirStr);
			//}
			else 
			{
				//window.location.href = "locked.aspx?pagename=P4"
				//alert('Else');
				window.location.href = "members.aspx?pagename=A5a2_2&ID_Member=" + ID + "&MemberType=" + MemberType;
			}
		}
		else 
		{
			//alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
			window.location.href = "members.aspx?pagename=A5a2_2&ID_Member=" + ID + "&MemberType=" + MemberType;
		}
	}
	
	if (PageID == '72') 
	{
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		var gotoHRef = ""
		if(pos != -1) 
		{
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			if(parseInt(value) != 1) 
			{
				//window.open('members.aspx?pagename=A5a7&MemberID=' + ID + '&Handle=' + Handle,'y','height=320,width=400,scrollbars=no');
				gotoHRef = "members.aspx?pagename=A5a7&MemberID=" + ID + "&Handle=" + Handle;
			}
			else 
			{
				//window.location.href = "locked.aspx?pagename=P1"
				gotoHRef = "members.aspx?pagename=A5a7&MemberID=" + ID + "&Handle=" + Handle;
			}
		}
		else 
		{
			//alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
			gotoHRef = "members.aspx?pagename=A5a7&MemberID=" + ID + "&Handle=" + Handle;
		}

		if (searchtype == 1)
		{
			//coming from expanded search
			gotoHRef += "&fp=es";
		}
		else if(searchtype == 3)
		{
			//coming from quicksearch
			gotoHRef += "&fp=qs";
		}
	
		window.location.href = gotoHRef;
	}

	if (PageID == '73') //SEND TO A FRIEND
	{
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		if(pos != -1) 
		{
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			if(parseInt(value) != 1) 
			{
				//window.open('members.aspx?pagename=A5a9&MemberID=' + ID + '&Handle=' + Handle,'y','height=400,width=480,scrollbars=no');
				window.location.href = "members.aspx?pagename=A5a9&MemberID=" + ID + "&Handle=" + Handle;
			}
			else 
			{
				//window.location.href = "locked.aspx?pagename=P2"
				window.location.href = "members.aspx?pagename=A5a9&MemberID=" + ID + "&Handle=" + Handle;
			}
		}
		else 
		{
			//alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
			window.location.href = "members.aspx?pagename=A5a9&MemberID=" + ID + "&Handle=" + Handle;
		}
	}
	
	if (PageID == '74') 
	{
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		if(pos != -1) 
		{
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			if(parseInt(value) != 1) 
			{
				//window.open('members.aspx?pagename=A5a10&MemberID=' + ID + '&Handle=' + Handle,'y','height=320,width=400,scrollbars=no');
				window.location.href = "members.aspx?pagename=A5a10&pagemode=input&formMode=submit&MemberID=" + ID + "&Handle=" + Handle;
			}
			else 
			{
				//window.location.href = "locked.aspx?pagename=P2"
				window.location.href = "members.aspx?pagename=A5a10&pagemode=input&formMode=submit&MemberID=" + ID + "&Handle=" + Handle;
			}
		}
		else 
		{
			//alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
			window.location.href = "members.aspx?pagename=A5a10&pagemode=input&formMode=submit&MemberID=" + ID + "&Handle=" + Handle;
		}
	}
	
	if (PageID == '75') 
	{
		window.location.href = "members.aspx?pagename=A5a8&MemberID=" + ID;
	}
	
	if (PageID == '76') 
	{
		var allcookies = document.cookie;
		allcookies = unescape(allcookies);
		var pos = allcookies.indexOf("UserType=");
		if(pos != -1) 
		{
			var start = pos + 9; 
			var end = start + 1;
			var value = allcookies.substring(start, end);
			if(parseInt(value) != 1) 
			{
				//window.open('members.aspx?pagename=A5a6&MemberID=' + ID + '&Handle=' + Handle,'y','height=300,width=390,scrollbars=no');
				window.location.href = "members.aspx?pagename=A5a6_2&ID_Member=" + ID + "&Handle=" + Handle;
			}
			else 
			{
				//window.location.href = "locked.aspx?pagename=P2"
				window.location.href = "members.aspx?pagename=A5a6_2&ID_Member=" + ID + "&Handle=" + Handle;
			}
		}
		else 
		{
			//alert('There is a problem with your cookies, check your browser to make sure cookies are turned on')
			window.location.href = "members.aspx?pagename=A5a6_2&ID_Member=" + ID + "&Handle=" + Handle;
		}
	}
	
	if (PageID == '77')//SEND AN EYE CONTACT
	{
		if (theForm == null)
		{ 
			var gotoHRef = "";
		// 	var pagenumber = 0;
		// 	if (document.frmCupidFavorite!= null)
		//	{ 	
		// 		 pagenumber = document.frmCupidFavorite.pgn.value;
		//	}
			gotoHRef = escape(document.location.pathname + document.location.search);
		//	alert(gotoHRef);
		//	document.write("Pathname: " + document.location.pathname + " Search: " + document.location.search)
		//	alert("members.aspx?pagename=A5a7&MemberID=" + ID + "&pgid=myCupid&Handle=" + Handle + "&gpg=" + pagenumber + "&fp=" + gotoHRef);
			window.location.href = "members.aspx?pagename=A5a7&MemberID=" + ID + "&pgid=myCupid&Handle=" + Handle + "&gpg=" + pagenumber + "&fp=" + gotoHRef;
		}
		else 
		{
			var theFormfield = "MemberID_" + pagenumber;
			document.getElementById("pageAction").value = "eyeContact";
			document.getElementById("memHandle").value = Handle;
			document.getElementById("memberID").value = ID;
			GoToNext(pagenumber,0,theForm[theFormfield],0, 10)
		}
	}
	
	if (PageID == '78') //ADD TO FRIENDS
	{
	//document.location.href;
	var startpageat = document.domain.length + 8; //8 to cover http:// and the / after the domain name
	var endpageat = document.location.href.indexOf(".aspx") + 5;
	var pagenameat = document.location.href.indexOf("pagename") + 9;
	var endat = document.location.href.length;
	if (document.location.href.indexOf("&", pagenameat) > 0) endat = document.location.href.indexOf("&", pagenameat);
	var thispage = document.location.href.substring(startpageat, endpageat);
	var pagename = document.location.href.substring(pagenameat, endat);

	if (thispage.substring(0,8) == "_profile")
	{
		thispage = "";
		pagename = "";
	}
	
		window.location.href = "members.aspx?pagename=A9&pageMode=output&fi=" + ID + "&fg="  + MemberType.toLowerCase() + "&fp=" + thispage + "&pn=" + pagename ;
	}
	
	if (PageID == '79') //REMOVE FROM SEARCH
	{
		//flag id for removal process
		//set remove_member hidden feild to memberid being clicked for removal
		theForm.remove_member.value = ID;
		document.getElementById("memHandle").value = Handle;
		//  var pagenumber = theForm.PageNumber.value; 
		//grab name of field that holds current list of ids for this page 
		var theFormfield = "MemberID_" + pagenumber;
		//refresh page but now the flag has been set for removal of this ID
		GoToNext(pagenumber,0,theForm[theFormfield],0, 10)
	}
	
	if(PageID == '80')//ADD TO FAVORITES
	{
		//  var pagenumber = theForm.PageNumber.value; 
		var theFormfield = "MemberID_" + pagenumber;
		document.getElementById("pageAction").value = "fav";
		document.getElementById("memHandle").value = Handle;
		document.getElementById("memberID").value = ID;
		GoToNext(pagenumber,0,theForm[theFormfield],0, 10)
	}
	
	if(PageID == '81')//BLOCK MEMBER
	{
		//  var pagenumber = theForm.PageNumber.value; 
		var theFormfield = "MemberID_" + pagenumber;
		document.getElementById("pageAction").value = "block";
		document.getElementById("memHandle").value = Handle;
		document.getElementById("memberID").value = ID;
		GoToNext(pagenumber,0,theForm[theFormfield],0, 10)
	}
}



//-----------------------------
//-----------------------------
function askmephoto(ID,Handle) {
	Handle = escape(Handle)
	window.location.href = "members.aspx?pagename=A10&ID_Member=" + ID + "&Handle=" + Handle;
}
//-----------------------------
//-----------------------------
function DisplayImage(dir,priv)
{
	if (dir == -1)
	{
		displayNum = displayNum - 1;
	} else if (dir == 0) {
		displayNum = displayNum + 1;
	} else {
		displayNum = dir-1;
	}
	
	
	//if the photos are private photos display them securely in the page so they will not be cached
	//took out https because images will not display due to security certificate conflicts ~JSkibitsky 3/26/07
	/*if (priv == 1){
		document.images['displayImg'].src = 'https://' + window.location.hostname + arrImages[displayNum][0];
		}
	else if(priv == 0){*/
		document.images['displayImg'].src = arrImages[displayNum][0];
		//}
		
	if (document.getElementById('frmRatePhoto') != null)
	{
		if (displayNum > 0 || dir > 1)
		{
			document.getElementById('frmRatePhoto').style.display = "none";
		}
		if(displayNum == 0 || dir == 1 )
		{
			document.getElementById('frmRatePhoto').style.display = "inline";
		}
	}
	
	
	//document.images['smallDisplayImg'].src = arrImages[displayNum][1];
	//determine what browser, so we know how to write the DHTML
	if (document.layers){
      //Netscape 4 specific code
      pre = 'document.';
      post = '';
   }
   if (document.getElementById){
      //Netscape 6 specific code
      pre = 'document.getElementById("';
      post = '").';
   }
   if (document.all){
      //IE4+ specific code
      pre = 'document.all.';
      post = '.';
   }


	for (i=1; i<=arrImages.length; i++)
	{
		if (i == (displayNum+1))
		{
			eval(pre + "disLink" + i + post + "className = 'dark'");
		} else {
			eval(pre + "disLink" + i + post + "className = 'nodec'");
		}
	}
	
	if (arrImages.length > 1)
	{

		if (displayNum == arrImages.length-1)
		{
			eval(pre + "nextLink" + post + "style.display = 'none'");
			//document.getElementById("nextLink").style.display = "none";
		} else {
			eval(pre + "nextLink" + post + "style.display = ''");
			//document.getElementById("nextLink").style.display = "";
		}

		if (displayNum == 0)
		{
			eval(pre + "prevLink" + post + "style.display = 'none'");
			//document.getElementById("prevLink").style.display = "none";
		} else {
			eval(pre + "prevLink" + post + "style.display = ''");
			//document.getElementById("prevLink").style.display = "";
		}
	} else {
		eval(pre + "nextLink" + post + "style.display = 'none'");
		//document.getElementById("nextLink").style.display = "none";
	}

}
//-----------------------------
//-----------------------------
function gobacktosearch()
{
	if (searchtype == 1)
	{
		document.search_results.action = "_profile_search_ext.aspx?" + Query;
		document.search_results.submit();
	}
	else if(searchtype == 3)
	{
		document.search_results.action = "_profile_search.aspx?" + Query;
		document.search_results.submit();
	}
	else if(searchtype == 4)
	{
		document.search_results.action = "_profile_search_handle.aspx?" + Query;
		document.search_results.submit();
	}
	else if(searchtype == "5")
	{
		if (viewtype == "a")
		{
			window.location.href = "dating-chat.aspx";
		}
		else if (viewtype == "b")
		{
			window.location.href = "members.aspx?pagename=A12";
		}
		else if (viewtype == "c")
		{
			window.location.href = "members.aspx?pagename=A15";
		}
	
	}
	else
	{
		window.location.href = "mycupid.aspx";
	}
}
//-----------------------------
//-----------------------------
function gotonextprofile(dir)
{
	if(dir == 'forward') 
	{
		var step = -1;
		document.search_results.id_member.value = document.search_results.next_member.value;
	}
	if(dir == 'back') 
	{
		var step = 1;
		document.search_results.id_member.value = document.search_results.previous_member.value;
	}
	document.search_results.selected_position.value =  (document.search_results.selected_position.value - 1*step);
	document.search_results.action = "_profile_myview.aspx?id_member=" + document.search_results.id_member.value;	
	document.search_results.sp.value = "";
	document.search_results.type.value = "";
	document.search_results.submit();
}

//-----------------------------
//-----------------------------
//added 9/19/06 by J. Skibitsky
//link on view photos page to go back to profile, when 
//you're coming from Search Result page
function gobacktoprofile()
{
	if (typeof(document.search_results) != "undefined")
	{
	    document.search_results.action = "_profile_myview.aspx?id_member=" + document.search_results.id_member.value;	
		document.search_results.sp.value = "";
		document.search_results.type.value = "";
		document.search_results.submit();
	}
}
//-----------------------------
//-----------------------------
function getpicture(id_member, pictype, sp)
{
document.search_results.sp.value = sp;
document.search_results.type.value = pictype;
document.search_results.action = "_profile_myview.aspx?id_member=" + id_member;
document.search_results.submit();
}

//-----------------------------
//-----------------------------
//function takes in radians user coordinates of where they live 
//and coordinates of profile they are viewing
//also country of person they are viewing
function getDistanceFromMe(lat1,long1,lat2,long2,country) {
	
	//set all verbage for return message
	var inAreaText = 'We\'re practically neighbors!'
	var prefixText = 'I am about ';
    var formatText = 'km';
    //if in US we use mile else we use km
    if (country == 'United States')
       {
       formatText = 'miles';
       }
    var endText = ' ' + formatText + ' from you.';
	//set all verbage for return message

    F = (lat1+lat2)/2;
	G = (lat1-lat2)/2;
	lambda = (long1-long2)/2;
	with(Math) {
	S = pow(sin(G)*cos(lambda),2)+pow(cos(F)*sin(lambda),2);
	C = pow(cos(G)*cos(lambda),2)+pow(sin(F)*sin(lambda),2);
	omega = atan(sqrt(S/C));
	R = sqrt(S*C)/omega;
	D = 2*omega*a;
	H1 =(3*R-1)/2/C;
	H2 =(3*R+1)/2/S;
	s = D*(1+f*H1*pow(sin(F)*cos(G),2)-f*H2*pow(cos(F)*sin(G),2));
		}
    s = Math.round(s)
	//alert(s);
    //if s is not a number that means we are in same postal code 
    //so we show them 'inAreaText'.
    if(isNaN(s))
	  {
	   return inAreaText;
	  }
	  else
	  { 
	    //format for km
	    if(formatText=="km") 
	     { 
	       return (prefixText + s + endText);
	     }
	     else
	     {
		   //we format for miles --- 1.6 km  = 1 mile
		   s = Math.round(s/1.6);
	       return (prefixText + s + endText);
	     }	   
	  }	
}
//-----------------------------
//-----------------------------
function confirm_rated()
{
	var i;
		
	if(document.getElementById("photo_rating").value != 0)
	{
		
		document.write('<tr>');
		
		for(i=1; i<11; i++)
		{
		if (i == document.getElementById("photo_rating").value)
			{
			document.write('<td width="28" align="right"><input TYPE="radio" name="rating" value="' + i + '" onClick="submit();" disabled="true" checked="true" /></td><td valign="top">' + i +'</td>');
			}
			else
			{
			document.write('<td width="28" align="right"><input TYPE="radio" name="rating" value="' + i + '" onClick="submit();" disabled="true" /></td><td valign="top">' + i + '</td>');
			}
		}
		
		document.write('</tr>');
	}

}
//-----------------------------
//-----------------------------
function resetviewcount(IDMember)
{
	//redirect2Submit(ID);
	window.location.href = "members.aspx?pagename=a5a7&pagemode=input&formmode=resetviewcount";
}


