/***************************************************************************
 *                            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.
 *
 ***************************************************************************/

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */

function getCookieValue(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    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 "";
}


function bookmarksite(){ 
	if(document.all){window.external.AddFavorite('http://www.alpha.co.il',document.title); }
	else{ if(window.sidebar) window.sidebar.addPanel(document.title,'http://www.alpha.co.il', "");}
}

function opencrm(UID)
{
    var win = "width=550,height=350,left=250,top=200,copyhistory=no,directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes";
    window.open("moderators/crm.php?UID="+UID,"Crm",win);
}
// end - function for crm

// open profile function
function open_profile(user_id,nickname)
{
	var user = "profile.php?ID="+user_id+"&pop";
	window.open(user,nickname,'width=681,height=700,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,copyhistory=no,resizable=no');
}

// end - profile function
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 (sID)
{
    var win = "width=500,height=290,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php?ID="+sID,'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 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" onmouseover="this.className=\'innerSubmenuDivHover\'" onmouseout="this.className=\'innerSubmenuDiv\'"><div class="innerSubmenuLink"><a href="' + link + '">' + name + '</a></div></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)
{
	if (document.getElementById( node ))
	{
		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, '');
}

// WORLDCITIES INSTALL

// declare a global  XMLHTTP Request object
var geo_XmlHttpObj;
var geo_fl_country;
var geo_fl_region;
var geo_fl_city;
var geo_fl_prefix;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function geo_CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		geo_XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			geo_XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
	catch(oc)
		{
			geo_XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!geo_XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		geo_XmlHttpObj = new XMLHttpRequest();
	}
}

// called from onChange or onClick event of the continent dropdown list
function CountryListOnChange(pfl_country,pfl_region,pfl_city,pfl_prefix) 
{
    // update public variable
    geo_fl_country = pfl_country;
    geo_fl_region  = pfl_region;
    geo_fl_city    = pfl_city;
    geo_fl_prefix  = pfl_prefix
    
    
    window.status = "Loading Region .....";	

    var Geo_Country = document.getElementById(geo_fl_country).value;

    var requestUrl;
    var s = current_date_txt();
    requestUrl = site_url + "modmysite/worldcities/geo_data_provider.php" + "?action=r&country=" + encodeURIComponent(Geo_Country) + '&date=' + s + '&prefix=' + geo_fl_prefix;
    //requestUrl = site_url + "https://dev.alpha.org.il/modmysite/worldcities/geo_data_provider.php" + "?action=r&country=" + encodeURIComponent(Geo_Country) + '&date=' + s + '&prefix=' + geo_fl_prefix;
    
    //alert(requestUrl + ' sd');
  	geo_CreateXmlHttpObj();
	 
	  if(geo_XmlHttpObj)
	    { 
		  geo_XmlHttpObj.onreadystatechange = RegionStateChangeHandler;
		  geo_XmlHttpObj.open("GET", requestUrl,  true);
		  geo_XmlHttpObj.send(null);		
	    }
}


function RegionStateChangeHandler()
{ 
 if (  geo_XmlHttpObj.readyState == 4  )
    {
		if( geo_XmlHttpObj.status == 200 )
		{	
      document.getElementById('div_' + geo_fl_region).innerHTML =  geo_XmlHttpObj.responseText;
      RegionListOnChange(geo_fl_country,geo_fl_region,geo_fl_city,geo_fl_prefix);
      window.status = ""; 								
		}
  }					
}


// called from onChange or onClick event of the continent dropdown list
function RegionListOnChange(pfl_country,pfl_region,pfl_city,pfl_prefix) 
{
    // update public variable
    geo_fl_country = pfl_country;
    geo_fl_region  = pfl_region;
    geo_fl_city    = pfl_city;
    geo_fl_prefix  = pfl_prefix
    
    window.status = "Loading City .....";	
//alert( geo_fl_country + ' sdd ' +   geo_fl_region);
    var Geo_Region = document.getElementById(geo_fl_region).value;
    var Geo_Country = document.getElementById(geo_fl_country).value;

    var requestUrl;
    var s = current_date_txt();
    requestUrl = site_url + "modmysite/worldcities/geo_data_provider.php" + "?action=c&region=" + encodeURIComponent(Geo_Region) + "&country=" + encodeURIComponent(Geo_Country)  + "&date=" + s + '&prefix=' + geo_fl_prefix;
    //requestUrl = site_url + "https://dev.alpha.org.il/modmysite/worldcities/geo_data_provider.php" + "?action=c&region=" + encodeURIComponent(Geo_Region) + "&country=" + encodeURIComponent(Geo_Country)  + "&date=" + s + '&prefix=' + geo_fl_prefix;
    
    
//    alert(requestUrl);
  	geo_CreateXmlHttpObj();
	 
	  if(geo_XmlHttpObj)
	    { 
		  geo_XmlHttpObj.onreadystatechange = CityStateChangeHandler;
		  geo_XmlHttpObj.open("GET", requestUrl,  true);
		  geo_XmlHttpObj.send(null);		
	    }
}


function CityStateChangeHandler()
{
  if (  geo_XmlHttpObj.readyState == 4  )
     {
		 if( geo_XmlHttpObj.status == 200  )
		    {	
        document.getElementById('div_' + geo_fl_city).innerHTML =  geo_XmlHttpObj.responseText;
        window.status = "";								
		   }
		}   	   	
}

function yesno(msg)
{
var truthBeTold = confirm(msg);
if (!truthBeTold)
   {
   alert("CANCELLED!");
   return false;
   }
return true;
}


function current_date_txt()
{
	 var d,s;
	 d = new Date();
	 s = (d.getMonth() + 1) + '-'  ;
  	 s += d.getDate() + '-' ;
  	 s += d.getFullYear() + '-';
	 s += d.getHours() + '-' ;
  	 s += d.getMinutes() + '-';
  	 s += d.getSeconds();
  	 return s;
}


function SubmitOnEnter()
{	
if (window.event && window.event.keyCode == 13)
	{
		document.forms[0].submit();
	}
}



//START CHECK NICKNAME AVAILABILITY
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 CheckUsername()
{
setcookie("username","",0);
setcookie("NickName","",0);
username=document.getElementById("NickName_check").value; // This function we will use to check to see if a username is taken or not.
if (!username)
{
	return;
}
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 s =  current_date_txt();
var url="checkname.php?username="+username + "&s=" + s; // 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.
//END CHECK NICKNAME AVAILABILITY


function SaveUserMemoAjax(memo,id)
    {
    
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
          }
        catch (e)
          {
          alert('Your browser does not support AJAX!');
          return false;
          }
        }
      }     
      xmlHttp.onreadystatechange=function()
        {
            
        if(xmlHttp.readyState == 4)
        {
            //document.getElementById(id).style.display = "none"; 
        }
        }
      
      xmlHttp.open('GET','seach_result_ajax_actions.php?id='+id+'&memo='+memo,true);
      xmlHttp.send(null);
}


