/* CONFIGS */
var CurrentCell = "";
var CurrentField = "";

var HS_SubCategories = new Array;
var HS_CategoriesField;
var HS_SubCategoriesField;

var tempTimeout = 0;
var closeTimeout = null;
var NotiTimer = new Array;
var BlindIDCount = 0;	

MainURL = '';

/*******************************
 * HS_StatesPopulate
 *
 *
 */
 
 function HS_StatesPopulate(FormHandler,AllowEmpty){		
	for(var k = FormHandler.state.options.length-1; k>=0; k--){
		FormHandler.state.options[k] = null;
	}//for
	for(var k = FormHandler.city.options.length-1; k>=0; k--){
		FormHandler.city.options[k] = null;
	}//for
	FormHandler.state.options[0] = new Option("...loading...");
	FormHandler.city.options[0] = new Option("...loading...");
	var Country = FormHandler.country.options[FormHandler.country.selectedIndex].value;
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
    	self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject) {
    	self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) {
        HS_PullData(self.xmlHttpReq.responseXML,FormHandler.state,'state');
        HS_PullData(self.xmlHttpReq.responseXML,FormHandler.city,'city');
	}//if
    }//function
	self.xmlHttpReq.send("handler=geo&action=states&country="+Country+"&allow_empty="+AllowEmpty);
}//HS_StatesPopulate
	
	
/*******************************
 * HS_CitiesPopulate
 *
 *
 */

function HS_CitiesPopulate(FormHandler,AllowEmpty){
	for(var k = FormHandler.city.options.length-1; k>=0; k--){
		FormHandler.city.options[k] = null;
	}//for
	FormHandler.city.options[0] = new Option("...loading...");
	var Country = FormHandler.country.options[FormHandler.country.selectedIndex].value;
	var State = FormHandler.state.options[FormHandler.state.selectedIndex].value;
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
    	self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject) {
    	self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) {
        HS_PullData(self.xmlHttpReq.responseXML,FormHandler.city,'city');
	}//if
    }//function
	self.xmlHttpReq.send("handler=geo&action=cities&&country="+Country+"&state="+State+"&allow_empty="+AllowEmpty);
}//HS_CitiesPopulate

/*******************************
 * HS_PullData
 *
 *
 */
 
function HS_PullData(XMLData,FieldHandler,ItemName){
	for(var k = FieldHandler.options.length-1; k>=0; k--){
		FieldHandler.options[k] = null;
	}//for
	var Items = XMLData.getElementsByTagName(ItemName);
	for(var i=0;i<Items.length;i++){
		var ItemID = Items[i].firstChild.firstChild.nodeValue;
		var ItemName = Items[i].firstChild.nextSibling.firstChild.nodeValue;
		FieldHandler.options[i] = new Option(ItemName,ItemID);
	}//for
}//HS_PullData

/*******************************
 * HS_viewPhoto
 *
 *
 */

function HS_viewPhoto(per_id, pho_id){
   url = "/index.php?page=photos&section=album&per_id="+per_id+"&pho_id="+pho_id;   
   phowin = window.open(url, "PHOTOALBUM", "width=382,height=460,scrollbars=no,menubar=no,resizable=no,location=no");
   phowin.focus();
}

/*******************************
 * HS_UpdatePhoto
 *
 *
 */

function HS_UpdatePhoto(FieldHandler,Page){
	var SelectedMembers = "";
	for(var i=0;i<FieldHandler.options.length;i++){
		if(FieldHandler.options[i].selected == true){
			SelectedMembers+= ","+FieldHandler.options[i].value;
		}//if
	}//for		
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
    	self.xmlHttpReq = new XMLHttpRequest();
	}//if
	// IE
	else if (window.ActiveXObject) {
    	self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}//else if
	self.xmlHttpReq.open('POST', "index.php", true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) {
        HS_LoadCard(self.xmlHttpReq.responseText);
	}//if
    }//function
	self.xmlHttpReq.send("handler=profile&action=card&members="+SelectedMembers+"&p="+Page);
    
}//HS_UpdatePhoto

/*******************************
 * HS_LoadCard
 * 
 *
 */

function HS_LoadCard(CardHTML){
	var CardHandler = document.getElementById("MemberCard");
	CardHandler.innerHTML = CardHTML;
}//HS_LoadCard


/*******************************
 * HS_Position
 * 
 *
 */

function HS_Position(Obj){
	var Position = new Array();
	Position['Top']  = 0;
	Position['Left'] = 0;
	if (Obj.offsetParent){
		while (Obj.offsetParent){
			Position['Top']+= Obj.offsetTop;
			Position['Left']+= Obj.offsetLeft;
			Obj = Obj.offsetParent;
		}//while
	}//if
	else if (Obj.x && Obj.y){
		Position['Left']+= Obj.x;
		Position['Top']+= Obj.y;
	}//else if
	return Position;
}//HS_Position

/*******************************
 * HS_SelectColor
 * 
 *
 */

function HS_SelectColor(ColorField,ColorCell){
	var Selector = document.getElementById("HS_ColorSelector");
	var Position = HS_Position(document.getElementById(ColorCell));
	Selector.style.top = Position['Top'];
	Selector.style.left = Position['Left']+20;
	Selector.style.visibility = "";
	CurrentCell = ColorCell;
	CurrentField = ColorField;
}//HS_SelectColor

/*******************************
 * HS_DoSelectColor
 * 
 *
 */

function HS_DoSelectColor(HexCode){
	var Cell = document.getElementById(CurrentCell);
	Cell.style.backgroundColor = HexCode;
	CurrentField.value = HexCode;
	var Selector = document.getElementById("HS_ColorSelector");
	Selector.style.visibility = "hidden";
}//HS_DoSelectColor

/*******************************
 * HS_ShowCardPreview
 * 
 *
 */
 
function HS_ShowCardPreview(TempPath){
	var HS_PreviewWin = window.open(TempPath,"_blank");
	HS_PreviewWin.focus();
}//HS_ShowCardPreview


/*******************************
 * HS_LoadOptions
 * 
 *
 */

function HS_LoadOptions(FieldHandler, OptionsLine){
	if(OptionsLine != ''){
		ListItems = OptionsLine.split("|");
		OptionsHandler = FieldHandler.options;
		for(i=0;i<(ListItems.length/2);i++){
			j = i*2;
			OptionsHandler[i] = new Option(ListItems[j+1],ListItems[j]);
		}//for
	}//if
}//HS_LoadOptions

/*******************************
 * HS_MoveOptions
 * 
 *
 */

function HS_MoveOptions(FieldHandlerFrom, FieldHandlerTo){
	var TransferOptions = new Array();
	var j=0;
	var k=0;		
	OptionsHandlerFrom = FieldHandlerFrom.options;
	OptionsHandlerTo = FieldHandlerTo.options;		
	for(i=0;i<OptionsHandlerFrom.length;i++){
		if(OptionsHandlerFrom[i].selected == true){
			OptionsHandlerTo[OptionsHandlerTo.length] = 
			new Option(OptionsHandlerFrom[i].text,OptionsHandlerFrom[i].value);
			OptionsHandlerFrom[i] = null;
			TransferOptions[j] = i;
			j++;
			i--;				
		}//if
	}//for
}//HS_MoveOptions

/*******************************
 * HS_PrepareData
 * 
 *
 */

function HS_PrepareData(FieldHandlerSrc, FieldHandlerResult){
	var ResultLine = "";
	OptionsHandlerSrc = FieldHandlerSrc.options;
	for(i=0;i<OptionsHandlerSrc.length;i++){
		ResultLine+= OptionsHandlerSrc[i].value + ",";
	}//for
	FieldHandlerResult.value = ResultLine;		
}//HS_PrepareData

/*******************************
 * HS_LoadCard
 * 
 *
 */

function HS_LoadCard(CardHTML){
		var CardHandler = document.getElementById("PhotoCard");
		CardHandler.innerHTML = CardHTML;
}//HS_LoadCard

/*******************************
 * HS_GetURL
 * 
 *
 */

function HS_GetURL(Link){
	window.location = Link;
}//HS_GetURL


/*******************************
 * HS_ExpandEvent
 * 
 *
 */

function HS_ExpandEvent(EventID){
	var EventHandler = document.getElementById(EventID);
	EventHandler.style.display = "inline";
	var EventButtonHandler = document.getElementById(EventID+"_hide_button");
	EventButtonHandler.style.display = "inline";
}//HS_ExpandEvent

/*******************************
 * HS_ContractEvent
 * 
 *
 */

function HS_ContractEvent(EventID){
	var EventHandler = document.getElementById(EventID);
	EventHandler.style.display = "none";
	var EventButtonHandler = document.getElementById(EventID+"_hide_button");
	EventButtonHandler.style.display = "none";
}//HS_ContractEvent

/*******************************
 * HS_SubCategoriesInit
 * 
 *
 */

function HS_SubCategoriesInit(SubCategoriesLine,CatField,SubCatField){
	var Items = SubCategoriesLine.split("=|=");
	var CatID;
	var SubCatID;
	for(var Item in Items){
		var SubItems = Items[Item].split("|");
		CatID = SubItems[0];
		SubCatID = SubItems[1];
		if(!HS_SubCategories[CatID])
			HS_SubCategories[CatID] = new Array;
			
		HS_SubCategories[CatID][SubCatID] = SubItems[2];
	}//for
	HS_CategoriesField = CatField;
	HS_SubCategoriesField = SubCatField;		
}//HS_SubCategoriesInit

/*******************************
 * HS_SubCategoriesPopulate
 * 
 *
 */

function HS_SubCategoriesPopulate(AllowEmpty){
	var Category = HS_CategoriesField.options[HS_CategoriesField.selectedIndex].value;
	for(var k = HS_SubCategoriesField.length-1; k>=0; k--){
		HS_SubCategoriesField.options[k] = null;
	}//for
	var i = 0;
	if(AllowEmpty == 1){
		HS_SubCategoriesField.options[i] = new Option("::LANGUAGE:Please, select...::",0);
		i++;
	}//if
	for(var Item in HS_SubCategories[Category]){			
		HS_SubCategoriesField.options[i] = new Option(HS_SubCategories[Category][Item],Item);
		i++;
	}//for
}//HS_SubCategoriesPopulate
	
/*******************************
 * HS_ViewClassifiedAdPhoto
 * 
 *
 */	

function HS_ViewClassifiedAdPhoto (cls_id){
   url = MainURL+"index.php?page=classifieds&section=view_photo&cls_id="+cls_id;
   phowin = window.open(url, "PHOTOALBUM", "width=382,height=460,scrollbars=no,menubar=no,resizable=no,location=no");
   phowin.focus();
}

/*******************************
 * HS_ViewClubPhoto
 * 
 *
 */	

function HS_ViewClubPhoto (clb_id, pho_id){
   url = MainURL+"index.php?page=clubs&section=view_photo&clb_id="+clb_id+"&pho_id="+pho_id;   
   phowin = window.open(url, "PHOTO", "width=382,height=460,scrollbars=no,menubar=no,resizable=no,location=no");
   phowin.focus();
}

/*******************************
 * HS_ViewEventPhoto
 * 
 *
 */	

function HS_ViewEventPhoto (evn_id){
   url = MainURL+"index.php?page=events&section=view_photo&evn_id="+evn_id;
   phowin = window.open(url, "PHOTOALBUM", "width=382,height=460,scrollbars=no,menubar=no,resizable=no,location=no");
   phowin.focus();
}

/*******************************
 * HS_TickAll
 * 
 *
 */	

function HS_TickAll(SetName,FormHandler){
	FormElements = FormHandler.elements;
	TickTracker = FormHandler.tick_tracker.checked;		
	for(i=0;i<FormElements.length;i++){
		FElement = FormHandler.elements[i];
		if( (FElement.type == "checkbox") && (FElement.name == SetName) ){
			if(TickTracker)
				FElement.checked = true;
			else
				FElement.checked = false;
		}//if
	}//for
}//HS_TickAll
	

/*******************************
 * HS_SetRecordSize
 * 
 *
 */	

function HS_SetRecordSize( size ) {
  if(size > 0){
   document.forms["record_audio"].stream_size.value = size;
   document.forms["record_video"].stream_size.value = size;
   document.forms["record_audio"].submit.disabled = false;
   document.forms["record_video"].submit.disabled = false;
  }
  else{
     document.forms["record_audio"].submit.disabled = true;
     document.forms["record_video"].submit.disabled = true;
  }
}

/*******************************
 * HS_ChangeCommentOption
 * 
 *
 */
 
function HS_ChangeCommentOption( op )
{
    HS_HideCommentOptions();
    HS_UnhideCommentOption( op );
    document.forms["record_"+op].type.value = op;
}
 
/*******************************
 * HS_UnhideCommentOption
 * 
 *
 */
 
function HS_UnhideCommentOption( id )
{
    var el = document.getElementById( id );
    el.style.display = "block";
}
 
/*******************************
 * HS_HideCommentOptions
 * 
 *
 */
 
function HS_HideCommentOptions()
{
    var el = document.getElementById("text");
    el.style.display = "none";
 
    var el = document.getElementById("audio");
    el.style.display = "none";
 
    var el = document.getElementById("video");
    el.style.display = "none";
}


/*******************************
 * HS_VChatRequest
 * 
 *
 */
 
function HS_VChatRequest( type, param )
{
	var oXHR = zXmlHttp.createRequest();
	oXHR.open("post", MainURL+"modules/vchat.php", true);
	oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oXHR.onreadystatechange = function() {
		if (oXHR.readyState == 4) {
			HS_ShowVChatWindow( oXHR.responseText );
		}
	}
	
	var post = null;
	
	switch(type){
		case 'invite':
			post = "action=invite&per_id="+param;
			break;
		case 'cancel':
			HS_CloseVChatWindow();
			post = "action=cancel&session_id="+param;
			break;
		case 'accept':
			HS_CloseVChatWindow();
			post = "action=accept&session_id="+param;
			break;
		case 'decline':
			HS_CloseVChatWindow();
			post = "action=decline&session_id="+param;
			break;
		case 'ignore':
			HS_CloseVChatWindow();
			post = "action=ignore&session_id="+param;
			break;
		case 'invited':
			post = "action=invited&session_id="+param;
			break;
		case 'unavailable':
			post = "action=unavailable&session_id="+param;
			break;
		case 'open_invited':
			post = "action=open_invited&session_id="+param;
			break;
		case 'open_invitee':
			post = "action=open_invitee&session_id="+param;
			break;
		case 'declined':
			post = "action=declined&session_id="+param;
			break;
		case 'close':
			HS_CloseVChatWindow();
			break;
	}
	
	oXHR.send( post );
}

/*******************************
 * HS_HandleVChatSignal
 * 
 *
 */
 
function HS_HandleVChatSignal( code )
{
	var details = code.split(".");
	HS_VChatRequest( details[0], details[1] );
}

/*******************************
 * HS_AlignVChatWindow
 * 
 *
 */
 
function HS_AlignVChatWindow()
{
	var ns = (document.layers)?1:0;
	var Position = new Array;
	if(ns){
		Position['Left'] = window.innerWidth + window.pageXOffset - 5;
		Position['Top']  = window.innerHeight + window.pageYOffset - 5;
	}//if
	else{
		Position['Left'] = document.body.clientWidth + document.body.scrollLeft - 5;
		Position['Top']  = document.body.clientHeight + document.body.scrollTop - 5;
	}//else
	var VChatWindow = document.getElementById("vchat_window");
	VChatWindow.style.top = (Position['Top']/2) - (VChatWindow.offsetHeight/2);
	VChatWindow.style.left = (Position['Left']/2) - (VChatWindow.offsetWidth/2);
	if(tempTimeout)
		setTimeout( "HS_AlignVChatWindow()", 500 );
}

/*******************************
 * HS_ShowVChatWindow
 * 
 *
 */
 
function HS_ShowVChatWindow( content )
{
	if(content){
		var element = document.getElementById( "vchat_window" );
		element.innerHTML = content;
		tempTimeout = 1;
		HS_AlignVChatWindow();
		element.style.visibility = "visible";
	}
}

/*******************************
 * HS_CloseVChatWindow
 * 
 *
 */
 
function HS_CloseVChatWindow()
{
	tempTimeout = 0;
	var element = document.getElementById( "vchat_window" );
	element.innerHTML = "";
	element.style.visibility = "hidden";
}

/*******************************
 * HS_LaunchVChat
 * 
 *
 */
 
function HS_LaunchVChat( session_id )
{
	HS_CloseVChatWindow();
	url = MainURL+"modules/vchat.php?action=launch&session_id="+session_id;
	var newwin = window.open(url, "vchat", "width=550,height=330,scrollbars=no,menubar=no,resizable=no,location=no");
	newwin.focus();
}



/*******************************
 * HS_LaunchIM
 * 
 *
 */
 
function HS_LaunchIM(){
	url = MainURL+"modules/instant_messenger.php?action=launch";   
	imwin = window.open(url, "HSIM_CONSOLE", "width=250,height=350,scrollbars=no,menubar=no,resizable=no,location=no");
	imwin.focus();
}//HS_LaunchIM

/*******************************
 * HS_LaunchChat
 * 
 *
 */
 
function HS_LaunchChat(per_id){
	url = MainURL+"modules/instant_messenger.php?action=chat&per_id="+per_id;
	var newwin = window.open(url, per_id, "width=500,height=350,scrollbars=no,menubar=no,resizable=no,location=no");
	newwin.focus();
}//HS_LaunchChat

/*******************************
 * HS_BuildBlind
 * 
 *
 */
 
function HS_BuildBlind(){		
	BlindIDCount++;
	var BlindID = "BLIND_"+BlindIDCount;
	var BlindTemplate = document.getElementById("BLIND").innerHTML;
	var Temp = new Array;
	Temp = BlindTemplate.split("BLIND");
	BlindTemplate = Temp.join(BlindID);
	var BlindContent = "<div class='blind' id='"+BlindID+"'>"+BlindTemplate+"</div>";
	var BlindsHandler = document.getElementById("blinds_panel");
	if(BlindsHandler.offsetHeight >= 117){
		BlindsHandler.style.top = parseInt(BlindsHandler.style.top) - 117;
	}//if
	else{
		BlindsHandler.style.top = parseInt(BlindsHandler.style.top) - 117 + BlindsHandler.offsetHeight;
	}//else
	BlindsHandler.innerHTML+= BlindContent;
	return BlindID;
}//HS_BuildBlind

/*******************************
 * HS_BuildNotification
 * 
 *
 */
 
function HS_BuildNotification(NotiType,NotiMessage){
	BlindID = HS_BuildBlind();
	switch(NotiType){
		case 'im':
			var Link = "<a href=\"javascript:HS_LaunchIM();\">"+NotiMessage+"</a>";
			break;
		case 'calendar':
			var Link = NotiMessage;
			break;
		case 'mailbox':
			var Link = "<a href=\"/index.php?page=mailbox_"+inforolesprimary+"&section=inbox\" target=\"_blank\">"+NotiMessage+"</a>";
			break;
		case 'view':
			var Link = "<a href=\"/index.php?page=views_"+inforolesprimary+"\" target=\"_blank\">"+NotiMessage+"</a>";
			break;
	}//switch
	var MessageHandler = document.getElementById("notification_message_"+BlindID);
	MessageHandler.innerHTML = Link;
	HS_FadeBlind(BlindID,"in");
	NotiTimer[BlindID] = setTimeout("HS_FadeBlind('"+BlindID+"','out')",10000);
}//HS_BuildNotification

/*******************************
 * HS_FadeBlind
 * 
 *
 */
 
function HS_FadeBlind(BlindID,Direction){		
	var Timer = 0;
	var Speed = 50;		
	if(Direction == "in"){
		HS_ChangeAlign('blinds_panel',3);
		for(var i=10;i<=100;i=i+10){
			setTimeout("HS_ChangeOpacity(" + i + ",'" + BlindID + "')",(Timer * Speed)); 
        	Timer++;
		}//for
	}//if
	else if(Direction == "out"){			
		for(var i=90;i>=0;i=i-10){
			setTimeout("HS_ChangeOpacity(" + i + ",'" + BlindID + "')",(Timer * Speed)); 				
        	Timer++;
		}//for
		setTimeout("HS_ChangeAlign('blinds_panel',1)",Timer * Speed);
		setTimeout("HS_RemoveBlind('"+BlindID+"')",Timer * Speed);
	}//else if
}//HS_FadeBlind

/*******************************
 * HS_ChangeOpacity
 * 
 *
 */
 
function HS_ChangeOpacity(OpacityValue,BlindID){		
	var BlindObjStyle = document.getElementById(BlindID).style;
	BlindObjStyle.opacity = (OpacityValue / 100); 
	BlindObjStyle.MozOpacity = (OpacityValue / 100); 
	BlindObjStyle.KhtmlOpacity = (OpacityValue / 100); 
	BlindObjStyle.filter = "alpha(opacity=" + OpacityValue + ")"; 
}//HS_ChangeOpacity

/*******************************
 * HS_PosBlinds
 * 
 *
 */
 
function HS_PosBlinds(){
	var ns = (document.layers)?1:0;
	var Position = new Array;		
	if(ns){
		Position['Left'] = window.innerWidth + window.pageXOffset - 5;
		Position['Top']  = window.innerHeight + window.pageYOffset - 5;
	}//if
	else{
		Position['Left'] = document.body.clientWidth + document.body.scrollLeft - 5;
		Position['Top']  = document.body.clientHeight + document.body.scrollTop - 5;
	}//else
	var BlindsPanel = document.getElementById("blinds_panel");
	BlindsPanel.style.top = Position['Top'] - BlindsPanel.offsetHeight;
	BlindsPanel.style.left = Position['Left'] - 180;
	setTimeout("HS_PosBlinds()",500);
}//HS_PosBlinds

/*******************************
 * HS_ChangeAlign
 * 
 *
 */
 
function HS_ChangeAlign(BlindID,Pos){	
	var BlindObjStyle = document.getElementById(BlindID).style;
	BlindObjStyle.zIndex = Pos;
}//HS_ChangeAlign

/*******************************
 * HS_RemoveBlind
 * 
 *
 */
 
function HS_RemoveBlind(BlindID){
	var BlindObj = document.getElementById(BlindID);
	BlindObj.innerHTML = "";
}//HS_RemoveBlind

/*******************************
 * HS_CloseNotification
 * 
 *
 */
 
function HS_CloseNotification(BlindID){
	clearTimeout(NotiTimer[BlindID]);
	HS_FadeBlind(BlindID,'out');
}//HS_CloseNotification




