/***************************************************************************
 *                            Dolphin Web Community Software
 *                              -------------------
 *     begin                : Mon Mar 23 2006
 *     copyright            : (C) 2007 BoonEx Group
 *     website              : http://www.boonex.com
 *
 *
 *
 ****************************************************************************/

/***************************************************************************
 *
 *   This is a free software; you can modify it under the terms of BoonEx
 *   Product License Agreement published on BoonEx site at http://www.boonex.com/downloads/license.pdf
 *   You may not however distribute it for free or/and a fee.
 *   This notice may not be removed from the source code. You may not also remove any other visible
 *   reference and links to BoonEx Group as provided in source code.
 *
 ***************************************************************************/

function setcookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

var xmlHttp // xmlHttp variable

function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.
var objXMLHttp=null // Sets objXMLHttp to null as default.
if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.
objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.
}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
} // End ElseIf.
return objXMLHttp // Returns the xhttp object.
}// Close Function

function CC_Query(formname,memberID)
{
var sUrl = "http://www.meetasugardaddy.com/";	
setcookie("formname","",0);
setcookie("selectoption","",0);
setcookie("url","",0);
selectoption = formname+"_option";
displayresult = document.getElementById(selectoption).value;
formres = formname+"_res";

xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url=sUrl+"cc_query.php?displayresult="+displayresult+"&memberID="+memberID+"&formname="+formname 

xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
result = xmlHttp.responseText.split(formres);
document.getElementById(formres).innerHTML="";
document.getElementById(formname).innerHTML="";
document.getElementById(formname).innerHTML = result[0];
document.getElementById(formres).innerHTML = result[1]; // Updates the div with the response text from check.php
} // End If.
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

function SaveSearch()
{
document.saveoption.b1.disabled = true;
document.getElementById("saveas_message").innerHTML="<b>Saving...</b>";
var sUrl = "http://www.meetasugardaddy.com/";	
setcookie("saveas","",0);
SaveAs=document.getElementById("saveas").value;
memberID=document.getElementById("memberID").value; 
StringQuery=document.getElementById("StringQuery").value; 
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url=sUrl+"savedsearch.php?SaveAs="+SaveAs+"&memberID="+memberID+"&StringQuery="+StringQuery 
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.saveoption.b1.disabled = false;
document.getElementById("saveas_message").innerHTML="";
document.getElementById("saveas_message").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.
function CheckUsername()
{
var sUrl = "http://www.meetasugardaddy.com/";	
setcookie("username","",0);
setcookie("NickName","",0);
username=document.getElementById("NickName").value; // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url=sUrl+"checkname.php?username="+username // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET
xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("usernameresult").innerHTML="";
document.getElementById("usernameresult").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.
 
 /**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
document.getElementsByClassName = function(cl,do_check) {

var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('input');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;

var idname = cl+'_'+do_check;
var idAll = cl+'_All';

if (myclass.test(classes) && this.getElementById(idname).name==idAll && elem[i].name!=idAll) {
elem[i].checked = false;
}
if (myclass.test(classes) && this.getElementById(idname).name!=idAll && elem[i].name==idAll) {
elem[i].checked = false;
}

}
return true;
}; 

document.getElementsByClassNameSearch = function(cl,do_check) {

if (cl=="Zodiac" || cl=="LookingFor")
return false;

var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('input');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;

var idname = cl+'_'+do_check;
var idAll = cl+'_0';

if (myclass.test(classes) && this.getElementById(idname).name==idAll) {
if (this.getElementById(idAll).checked==false)
elem[i].checked = false;
else
elem[i].checked = true;	
}
if (myclass.test(classes) && this.getElementById(idname).name!=idAll && elem[i].name==idAll) {
elem[i].checked = false;
}
}
return true;
};

function setCheckboxes(the_form, do_check)
{

	var elts  = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    var i = 0;

    for ( i; i < elts_cnt; i++)
    {
        elts[i].checked = do_check;
		if (the_form + "_submit" == elts[i].name)
		{
			elts[i].disabled = !do_check;
		}
    } // end for
	return true;
} // end of the 'setCheckboxes()' function

function setCheckbox(the_form)
{
    var elts      = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;

    var allUnchecked = true;

    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].checked) allUnchecked = false;
    }

    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].name == (the_form + "_submit")) elts[i].disabled = allUnchecked;
    }

    return true;
}


var win = "width=500,height=600,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
function get_gallery(id_prof)
{
   window.open("photos_gallery.php?ID="+id_prof,'gallery',win);
}

function launchTellFriend ()
{
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php",'tellfriend',win);
    return false;
}

function launchTellFriendProfile ( sID )
{
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php?ID="+sID,'tellfriendprofile',win);
    return false;
}

function BxShowBlock( id )
{

	var el;
	el = document.getElementById( id );

	if( el.style.display == 'none' )
	{
		el.style.display = 'block'
	}
	else
	{
		el.style.display = 'none'
	}

	return false;
}

function ShowShowHide ( show_name, show_name2, hide_name )
{
    if (hide_name) hide_name.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
    if (show_name2) show_name2.style.display = 'inline';
}

function ShowHideHide ( show_name, hide_name, hide_name2 )
{
    if (hide_name) hide_name.style.display = 'none';
    if (hide_name2) hide_name2.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
}

function charCounter(field,maxLength,countTarget)
{

	field = document.getElementById(field);
	countTarget = document.getElementById(countTarget);
	var inputLength=field.value.length;

	if(inputLength >= maxLength)
	{
		field.value=field.value.substring(0,maxLength);

	}
	countTarget.innerHTML=maxLength-field.value.length;


}



/**
 * change images onHover mouse action
 */
function show(FileName,jpg1Name)
{
	document.images[FileName].src = jpg1Name;
}

/**
 * set status of the browser window to 's'
 */
function ss(s)
{
	window.status = s;
	return true;
}

/**
 * set status of the browser window to empty
 */
function ce()
{
	window.status='';
}


/**
 * insert emotion item
 */
function emoticon( txtarea, text ) {

	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function launchAddToIM (id)
{
    var win = "width=600,height=160,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
    window.open("explanation.php?explain=imadd&ID="+id,'add_to_im',win);
    return false;
}

function docOpen(text)
{
	newWindow=window.open('','','toolbar=no,resizable=yes,scrollbars=yes,width=400,height=300');
	newWindow.document.open("text/html");
	newWindow.document.write(unescape(text));
	newWindow.document.close();
}

function get_data( container, url, siteUrl )
    {

        if ( container )
        {
	    var container = document.getElementById( container );
	    container.innerHTML = "loading ... ";
        }

        var XMLHttpRequestObject = false;

        if ( window.XMLHttpRequest )
        {
                XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if ( window.ActiveXObject )
        {
                XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }


	if( XMLHttpRequestObject )
        {
    	    var data_source = siteUrl + 'xml/menu.php' + url + '&_t=' + Math.random();
    	    XMLHttpRequestObject.open( "GET", data_source );
    	    XMLHttpRequestObject.onreadystatechange = function()
    	    {
        	if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 )
        	{

        	var xmlDocument = XMLHttpRequestObject.responseXML;
            delete XMLHttpRequestObject;
            XMLHttpRequestObject = null;

		   	names = xmlDocument.getElementsByTagName("name");
		    links = xmlDocument.getElementsByTagName("link");

		    list_sublinks(names, links);

        	}
    	    }

            XMLHttpRequestObject.send( null );

	}

	//container.innerHTML = '';




	function list_sublinks(names, links)
	{
    	var loopIndex, name, link, maxIndex = names.length;

	    container.innerHTML = '';
	    for ( loopIndex = 0; loopIndex < maxIndex; loopIndex++ )
   	    {

		    //if ( values[loopIndex].firstChild.nodeName=="name")
			name = names[loopIndex].firstChild.nodeValue;

		    //if ( values[loopIndex].childNodes[1].nodeName=="link")
			link = links[loopIndex].firstChild.nodeValue;

		    container.innerHTML += '<div class="innerSubmenuDiv"><a href="' + link + '">' + name + '</a></div>';
	    }

	}
}


function createNamedElement( type, name )
{

    var element;

    try
    {
        element = document.createElement('<'+type+' name="'+name+'">');
    } catch (e) { }

    if (!element || !element.name) // Cool, this is not IE !!
    {
        element = document.createElement(type)
        element.name = name;
    }

    return element;
}

function display_node(node, siteUrl)
{

    var nn = document.getElementById( node );

	var sub_name = node.split('_')[1];
    if ( 'none' == nn.style.display )
    {
	nn.style.display='block';
	if ( '' == nn.innerHTML )
	    get_data( node, '?action=menu&ID=' + sub_name, siteUrl);
    }
    else
    {
		nn.style.display='none';
    }

}

function stripSlashes(str)
{
	return str.replace(/\\/g, '');
}

//-------------------- ADDED BY TINA -----------------//
function LoginExec(){
	document.frmlogin.submit();
}
function ShowSexQ ( show_name, hide_name )
{
	var stridname; //by default, allow form submission
	var strhide; //by default, allow form submission
	var strshow; //by default, allow form submission
	
	for (i=0; i< document.jform.elements.length; i++){		
		if (document.jform.elements[i].type=="text" || document.jform.elements[i].type=="textarea" || document.jform.elements[i].type=="select-one"){			
			stridname = document.jform.elements[i].name; 
			strhide = stridname.substring(0, hide_name.length);
			strshow = stridname.substring(0, show_name.length);

			if (strhide.toLowerCase()==hide_name.toLowerCase()){ 	
				document.getElementById(stridname+'left').style.display = 'none';
				document.getElementById(stridname).style.display = 'none';				
				document.getElementById(stridname+'right').style.display = 'none';
			}
			if (strshow.toLowerCase()==show_name.toLowerCase()){ 				
				document.getElementById(stridname+'left').style.display = 'inline';
				document.getElementById(stridname).style.display = 'inline';
				document.getElementById(stridname+'right').style.display = 'inline';
			}			
		}
	}
	document.getElementById('txtsexchange').value = show_name;
}
 /*
	Header Information------------------------------------[Do Not Remove This Header]--
	Title: OO Dom Image Rollover
	Description: This script makes it easy to add rollover/ mousedown 
  	effects to any image on the page, including image submit buttons. Automatically 
  	preloads images as well. Script works in all DOM capable browsers- IE5+, NS6+, 
  	Opera7+.
	
	Legal: Copyright 2005 Adam Smith
	Author Email Address: ibulwark@hotmail.com
	Date Created: June 6, 2005
	Website: Codevendor.com | eBadgeman.com
	Script featured on Dynamic Drive: http://www.dynamicdrive.com
	-----------------------------------------------------------------------------------
*/

function imageholderclass(){
	this.over=new Array();
	this.down=new Array();
	this.src=new Array();
	this.store=store;
	
	function store(src, down, over){
		var AL=this.src.length;
		this.src[AL]=new Image(); this.src[AL].src=src;
		this.over[AL]=new Image(); this.over[AL].src=over;
		this.down[AL]=new Image(); this.down[AL].src=down;
	}
}

var ih = new imageholderclass();
var mouseisdown=0;

function preloader(t){
	for(i=0;i<t.length;i++){
		if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
			
			storeimages(t[i]);
			var checker='';
			checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
			checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
			
			switch(checker){
			case 'A' : mouseover(t[i]);mouseout(t[i]); break;
			case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
			case 'AB' : mouseover(t[i]);mouseout(t[i]); mousedown(t[i]); mouseup(t[i]); break;
			default : return;			
			}
			
			if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
		}
	}
}
function mouseup(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");this.oldmouseup();}

	}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");}}
	t.onmouseup=newmouseup;
}

function mouseup2(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");this.oldmouseup();}
		}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");}}
	t.onmouseup = newmouseup;
}

function mousedown(t){
	var newmousedown;
	if(t.onmousedown){
		t.oldmousedown=t.onmousedown;
		newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");this.oldmousedown();}}
	}
	else{newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");}}}
	t.onmousedown=newmousedown;
}

function mouseover(t){
	var newmouseover;
	if(t.onmouseover){
		t.oldmouseover=t.onmouseover;
		newmouseover=function(){this.src=this.getAttribute("srcover");this.oldmouseover();}
	}
	else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
	t.onmouseover=newmouseover;
}

function mouseout(t){
	var newmouseout;
	if(t.onmouseout){
		t.oldmouseout=t.onmouseout;
		newmouseout=function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
	}
	else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
	t.onmouseout=newmouseout;
}

function storeimages(t){
	var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
	var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
	var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
	ih.store(s,d,o);
}

function preloadimgsrc(){
	if(!document.getElementById) return;
	var it=document.getElementsByTagName('IMG');
	var it2=document.getElementsByTagName('INPUT');
	preloader(it);
	preloader(it2);
}

if(window.addEventListener){window.addEventListener("load", preloadimgsrc, false);} 
else{
	if(window.attachEvent){window.attachEvent("onload", preloadimgsrc);}
	else{if(document.getElementById){window.onload=preloadimgsrc;}}
}

function getPositionData(obj, showEvent)
	{
		if ( !showEvent )
			showEvent = window.event;
		
		var pos_X = 0, pos_Y = 0;
		if ( showEvent )
		{
			if ( typeof(showEvent.pageX) == 'number' )
			{
				pos_X = showEvent.pageX; pos_Y = showEvent.pageY;
			}
			else if ( typeof(showEvent.clientX) == 'number' )
			{
				pos_X = showEvent.clientX; pos_Y = showEvent.clientY;
				if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) )
				{
					pos_X += document.body.scrollLeft; pos_Y += document.body.scrollTop;
				}
				else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) )
				{
					pos_X += document.documentElement.scrollLeft; pos_Y += document.documentElement.scrollTop;
				}
			}
		}
		
		var scroll_X = 0, scroll_Y = 0;
		if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) )
		{
			scroll_X = document.body.scrollLeft; scroll_Y = document.body.scrollTop;
		}
		else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) )
		{
			scroll_X = document.documentElement.scrollLeft; scroll_Y = document.documentElement.scrollTop;
		}
		
		var win_size_X = 0, win_size_Y = 0;
		if (window.innerWidth && window.innerHeight)
		{
			win_size_X = window.innerWidth; win_size_Y = window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight)
		{
			win_size_X = document.documentElement.clientWidth; win_size_Y = document.documentElement.clientHeight;
		}
		else if (document.body && document.body.clientWidth && document.body.clientHeight)
		{
			win_size_X = document.body.clientWidth; win_size_Y = document.body.clientHeight;
		}
		
		pos_X += 15; pos_Y += 15;
		
		if (obj.offsetWidth && obj.offsetHeight)
		{
			if (pos_X - scroll_X + obj.offsetWidth + 5 > win_size_X)
				pos_X -= (obj.offsetWidth + 25);
			if (pos_Y - scroll_Y + obj.offsetHeight + 5 > win_size_Y)
				pos_Y -= (obj.offsetHeight + 20);
		}
		
		var res = new Array;
		res['posX'] = pos_X;
		res['posY'] = pos_Y;
		res['scrollX'] = scroll_X;
		res['scrollY'] = scroll_Y;
		res['winSizeX'] = win_size_X;
		res['winSizeY'] = win_size_Y;
		
		return res;
	}
	
function showUserDetails(showEvent, tDiv, content)
	{
		if ( !showEvent )
			showEvent = window.event;
		showDiv = document.getElementById(tDiv);

		
		showPos = getPositionData(showDiv, showEvent);
		showDiv.style.left = showPos['posX'] + 'px'; showDiv.style.top = showPos['posY'] + 'px';

		showDiv.innerHTML = content;
		showDiv.style.display = 'block';

}	
	
	function hideUserDetails(tDiv)
	{
		showDiv = document.getElementById(tDiv);
		showDiv.style.display = 'none';
	}