// JavaScript Document
var checkedUsers = new Array();
var checkedNicks = new Array();

function clickUserCheckBox( userCheckBox ){	
	if( userCheckBox.checked ){
		checkedUsers.push( userCheckBox.value );
		checkedNicks.push( userCheckBox.name );
	}
	else{
		$numUsers = checkedUsers.length;
		for(i=0;i<$numUsers;i++){
			if( checkedUsers[i] == userCheckBox.value ){
				checkedUsers.splice( i, 1 );
				checkedNicks.splice( i, 1 );
				break;
			}
		}		
	}
}

function massiveUnBookmark(){
	form = document.massiveAction;	
	if( checkedUsers.length == 0 ){
		alert( 'You have not selected a friend' );
	}else if( confirm( 'Are you sure?' ) ){
		form.action.value = "massiveUnbookmark";
		form.selectedUsers.value = checkedUsers.join(',');
		form.submit();
	}
}

function massiveBlock(){
	form = document.massiveAction;	
	if( checkedUsers.length == 0 ){
		alert( 'You have not selected a friend' );
	}else if( confirm( 'Are you sure?' ) ){
		form.action.value = "massiveBlock";
		form.selectedUsers.value = checkedUsers.join(',');
		form.submit();
	}
}

function massiveGreeting(){
	form = document.massiveGreetings;	
	if( checkedUsers.length == 0 ){
		alert( 'You have not selected a friend' );
	}else{
		form.receiverUser.value = checkedNicks.join(',');
		form.submit();
	}
}

function filterFriends(dropdown){
	//alert(dropdown.selectedIndex);
	if (dropdown.selectedIndex == 1)
		document.getElementById("filterNew").value = 6;
	else if (dropdown.selectedIndex == 2)
		document.getElementById("filterOnline").value = 1;
	dropdown.form.submit();
}
function putdataprofile(DivID, iState, iduser, nickname,currentPic){
	document.getElementById("FloatingLayer").innerHTML ="<div id='ProfileHiddenCont'><div id=\"ProfileHiddenTitle\">Add <font id=\"nick\"></font>&nbsp;as a friend?</div><div id=\"AddToFriendTx\" align=\"justify\"><div id=\"BookImg\"><img src=\"\" width=\"100\" border=\"0\" id=\"bookpic\" /></div><div>Add a personal message:<form action=\"viewProfile.php\" method=\"get\" name=\"addfriend\" style=\"border-top:0\"><textarea name=\"personalmessage\" cols=\"35\"rows=\"5\"></textarea><input type=\"hidden\" name=\"action\" value=\"bookmark\"><input type=\"hidden\" id=\"idToView\" name=\"idToView\" value=\"\"><input type=\"hidden\" id=\"bookmark\" name=\"bookmark\" value=\"\"><input class=\"BookBut\" type=\"submit\" value=\"Add Friend\"><input class=\"BookBut\" type=\"button\" value=\"Cancel\" onClick=\"FloatingLayerAction('FloatingLayer',0);return false\"></form></div></div></div>";
	
	FloatingLayerAction (DivID, iState, iduser, nickname,currentPic,1);	
}
function putdata(DivID, iState, iduser, nickname,currentPic){
	document.getElementById("FloatingLayer").innerHTML ="<div id='ProfileHiddenCont'><div id=\"ProfileHiddenTitle\">Add <font id=\"nick\"></font>&nbsp;as a friend?</div><div id=\"AddToFriendTx\" align=\"justify\"><div id=\"BookImg\"><img src=\"\" width=\"100\" border=\"0\" id=\"bookpic\" /></div><div>Add a personal message:<form action=\"myMatch.php\" method=\"get\" name=\"addfriend\" style=\"border-top:0\"><textarea name=\"personalmessage\" cols=\"35\"rows=\"5\"></textarea><input type=\"hidden\" name=\"action\" value=\"bookmark\"><input type=\"hidden\" id=\"bookmark\" name=\"bookmark\" value=\"\"><div><input class=\"BookBut\" type=\"submit\" value=\"Add Friend\"><input class=\"BookBut\" type=\"button\" value=\"Cancel\" onClick=\"FloatingLayerAction('FloatingLayer',0);return false\"></div></form></div></div></div>";

	FloatingLayerAction (DivID, iState, iduser, nickname,currentPic, 0);	
}

function FloatingLayerAction(DivID, iState, iduser, nickname,currentPic, toView) // 1 visible, 0 hidden
{
	if (toView==1)
	document.getElementById('idToView').value=iduser;
	document.getElementById('bookmark').value=iduser;
	document.getElementById("nick").innerHTML = nickname;
	document.getElementById("bookpic").src = "users/images/"+currentPic; 
    if(document.layers)	   //NN4+
    {
       document.layers[DivID].visibility = iState ? "show" : "hide";
	   document.layers['FloatingLayer1'].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(DivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[DivID].style.visibility = iState ? "visible" : "hidden";
    }
	document.getElementById('imgprev').src = "users/images/"+currentPic;
	
	preview(document.getElementById('imgprev'),'imgprev');
	return false;
}
/***** Add Hot List *****/
function addHotlist(idadded){
	if( window.XMLHttpRequest )
		ajaxHotlist = new XMLHttpRequest();
	else
		ajaxHotlist = new ActiveXObject("Microsoft.XMLHTTP");
	ajaxHotlist.onreadystatechange = funcionCallbackAddHotlist;
	ajaxHotlist.open( "GET", "addHotlistAjax.php?idadded="+idadded+"&cache="+Math.random(), true );
	ajaxHotlist.send( "" );
}

function funcionCallbackAddHotlist(){
	if( ajaxHotlist.readyState == 4 ){
		if( ajaxHotlist.status == 200 ){	
			ajaxRows = ajaxHotlist.responseText;									
			if (ajaxRows!=''){
				document.getElementById("myspan_"+ajaxRows).innerHTML ='Added to Hotlist';
			}
			else{
				document.getElementById("myspan_"+ajaxRows).innerHTML ='Add To Hotlist';
			}
		} 
	}
}  

/***** End Add Hot List *****/

/***** Add A Flirt *****/

function putdataflirt(DivID, iState, iduser, other){
	document.getElementById("FloatingLayerFlirt").innerHTML ="<div style=\"width:100px; border:1px solid #911; background:#FFF\"><div id=\"ProfileHiddenTitle\"><div style=\"float:left; width:80px\">Flirt </div><div style=\"cursor:pointer;\" onclick=\"FloatingLayerFlirt('FloatingLayerFlirt',0);return false\">X</div></div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Hugged');\">Hug</div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Kissed');\">Kiss</div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Smiled');\">Smile</div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Spanked');\">Spank</div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Waved');\">Wave</div><div style=\"width:40px; margin:0 10px 5px; cursor:pointer; color:#911; font-size:13px; text-decoration:underline\" onclick=\"addFlirt("+iduser+", 'Winked');\">Wink</div></div>";
	//showPopup(other, event);
	FloatingLayerFlirt (DivID, iState, iduser);	
}
function FloatingLayerFlirt(DivID, iState, iduser) // 1 visible, 0 hidden
{

    if(document.layers)	   //NN4+
    {
       document.layers[DivID].visibility = iState ? "show" : "hide";
	   document.layers['FloatingLayerFlirt'].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(DivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[DivID].style.visibility = iState ? "visible" : "hidden";
    }
	
	return false;
}
function addFlirt(idreceiver, flirt){
	if( window.XMLHttpRequest )
		ajaxFlirt = new XMLHttpRequest();
	else
		ajaxFlirt = new ActiveXObject("Microsoft.XMLHTTP");
	ajaxFlirt.onreadystatechange = funcionCallbackAddFlirt;
	ajaxFlirt.open( "GET", "addFlirtAjax.php?idreceiver="+idreceiver+"&flirt="+flirt+"&cache="+Math.random(), true );
	ajaxFlirt.send( "" );
}

function funcionCallbackAddFlirt(){
	if( ajaxFlirt.readyState == 4 ){
		if( ajaxFlirt.status == 200 ){	
			ajaxRows = ajaxFlirt.responseText;									
			if (ajaxRows!=''){
				ajaxData = ajaxRows.split('-');
				hideCurrentPopup();
				document.getElementById("myflirt_"+ajaxData[0]).innerHTML =ajaxData[2]+" <img src='templates/default/images/flirts/icon-flirt-"+ajaxData[1]+".gif'/>";
			}
			else{
				document.getElementById("myflirt_"+ajaxData[0]).innerHTML ='Flirt';
			}
		} 
	}
}
/***** End Add A Flirt *****/

function validateFieldSearch(form) {
	var messageA = "To search you need to enter a name, nickname or mail.";
	var CanSubmit = false;
    CanSubmit = ForceEntry(form.fieldsearch,messageA);
	return CanSubmit;
}
/******Second pass*********/
function validatemypass(){
	var messageA = "Please type first password.";
	var CanSubmit = false;
	CanSubmit1 = ForceEntry(loginForm.authPassword,messageA);
	if (CanSubmit1){
		document.getElementById('authPassword').style.visibility = 'visible'; 
		document.getElementById('pass').style.visibility = 'visible'; 
		CanSubmit2 = ForceEntry(loginForm.pass,'Please type second password');
		if (CanSubmit2){
			CanSubmit=secondPass();
		}
	}
	
return CanSubmit;
}

function secondPass(){
    var passOfuser1=document.getElementById("authPassword").value;
	var passOfuser2=document.getElementById("pass").value.toLowerCase();
	var contOfuser=document.getElementById("cont").value;
	
	if (passOfuser1!='' && passOfuser2=='toyota'){
		document.getElementById("cont").value='yes';
		
		return true;
	}
	else {
		 alert ('SECOND-PASS IS INCORRECT');
		  return false;}
	/*
	if( window.XMLHttpRequest )
		ajaxPass = new XMLHttpRequest();
	else
		ajaxPass = new ActiveXObject("Microsoft.XMLHTTP");
	ajaxPass.onreadystatechange = funcionCallbackSecondPass;
	ajaxPass.open( "GET", "secondPassAjax.php?pass2="+passOfuser2+"&pass1="+passOfuser2+"&cont="+contOfuser+"&cache="+Math.random(), true );
	ajaxPass.send( "" );*/
}

function funcionCallbackSecondPass(){
	if( ajaxPass.readyState == 4 ){
		if( ajaxPass.status == 200 ){	
			ajaxRows = ajaxPass.responseText;									
			if (ajaxRows==1){
				
				document.getElementById("cont").value='yes';
			}
			else{

				document.getElementById("cont").value='not';
				
			}

		} 
	}
}
