
//*****************************************************************************************
//***  Project        	: Capiyot	| Netcraft	    				            		***
//***  Code File        : Logic and DHTML Functions for Java Scripts			  		***				 		    ***
//***  Author           : Roee Dayan											 	    ***
//***  Created Date     : 12/1/2005 												    ***
//***  LastUpdater      : Roee Dayan											  		***
//***  Change Date      : 12/1/2005 											 		***
//*****************************************************************************************



var DaysArray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
var agt=navigator.userAgent.toLowerCase();
var isIE = (agt.indexOf("msie") != -1);

function DayChange(obj)
{
	var objTD = obj.parentElement;
	var objInputs = objTD.all.tags('input');
	var objHidden = objInputs.item(0);

	objHidden.value = obj.value;
}

function openLogUotWindow()
{
	if(self.VBArray)
	{
		//alert("1");
		var e = self.event, s = self.screen;
		//alert(s.width - e.clientX);
		//alert(e.clientY);
		if(s.width - e.clientX < 18 && e.clientY > -100 && e.clientY < -80/*&& typeof(e) == "function"*/)
		{
			//alert("2");
			var WinSettings="height=200,width=350,status=no,center=yes,toolbar=no,menubar=no,location=no";
			//window.open("frmLogOutUser.aspx", null, WinSettings);
		}
	}
}

function isNumeric(parm) 
{
  var numb = '0123456789';
  if (parm == "") return false;
  for (i=0; i<parm.length; i++) 
	if (numb.indexOf(parm.charAt(i),0) == -1) return false;
  
  return true;
}

function showpicture(param)
{
	showpicture(param, false);
}

function showpicture(param, attachment)
{
	// Make sure the image is not the default images
	if (param.indexOf("man_") == -1)
	{
		var WinSettings = "status:no;center:yes;resizable:yes;dialogWidth:640px;dialogHeight:480px;dialogTop:0px; dialogLeft:0px;; help:no;edge:sunken";
		
		if (param.toLowerCase().indexOf(".jpg") != -1 || param.toLowerCase().indexOf(".jpeg") != -1)
		{
			
			// Regular enlarged image - param is URL for Picture
			if (!attachment)
			{
				var modalWin = window.showModelessDialog("frmShowPicture.aspx?imageurl=" + param, null, WinSettings);
			}
			else
			{
				var modalWin = window.open("frmShowPicture.aspx?imageurl=" + param + "&attach=1",null, "width=800,height=600,resizable=yes,scrollbars=yes");
			}
			
		}
		else
		{			
			// Odd Cast Character - param is profileID
			var modalWin = window.showModelessDialog("OddCast/showCharacter.aspx?ocurl=" + param, null, WinSettings);		
		}
	};
}

function MonthChange(obj)
{
	var objTD = obj.parentElement;
	var theCollection = objTD.all.tags('select');
	var objDaysCombo = theCollection.item(2);
	var selectedDay = objDaysCombo.value;
	var CurrentSumDays = objDaysCombo.length;
	var objMonthCombo = theCollection.item(1);
	var month = objMonthCombo.value;
	
	for (i = 0 ; i < CurrentSumDays ; i++)
		objDaysCombo.remove(0);
	
	for (i = 1 ; i < DaysArray[month-1]+1 ; i++)
	{
		var oOption = document.createElement("OPTION");
		var oText =document.createTextNode(i);
		oOption.appendChild(oText);
		oOption.setAttribute("value",i);
		objDaysCombo.appendChild(oOption);
	}
	
	objDaysCombo.value = selectedDay;
	if (objDaysCombo.value == "")
		objDaysCombo.value = DaysArray[month-1];
}

// -------------------------------------
// This function Locates a certain style 
// and scrolls to the first one found
// -------------------------------------
// Written By Joey Simhon
// Date Created: February 8th 2005 01:00
// Last Updated: February 8th 2005 01:00
// -------------------------------------
function locateStyle(styleToLookFor)
{
	//var trCol = document.all.tags("tr");
	var trCol = document.getElementsByTagName('div');
		
	for (i=0; i<trCol.length; i++)
	{
		if (trCol[i].className == styleToLookFor)
		{
			//alert("found one");
			trCol[i].scrollIntoView();
			break;
		};
	};
};

function MissCallFrom(uniqueFrom)
{
	Refresher.DoPostback(uniqueFrom, "MISSINGCALL");
}

function SendDialogToPMB(uniqueFrom, text)
{
	Refresher.DoPostback(uniqueFrom, "SAVECHATDIALOG;" + text);
}

function check_combo(objFromName, objToName, HiddenFrom, HiddenTo)
{
	var objFrom;
	var objTo;
	var objHiddenFrom;
	var objHiddenTo;
	
	eval("objFrom = document.all." + objFromName);
	eval("objTo = document.all." + objToName);
	eval("objHiddenFrom = document.all." + HiddenFrom);
	eval("objHiddenTo = document.all." + HiddenTo);
	if (parseInt(objFrom.value) > parseInt(objTo.value) && objTo.value != "-1")
	{
		var tmpValue = objFrom.value;
		objFrom.value = objTo.value;
		objTo.value = tmpValue;
	}
	objHiddenFrom.value = objFrom.value;
	objHiddenTo.value = objTo.value;
}

function blockScreen()
{
	//alert("blocker");
	document.body.insertAdjacentHTML("BeforeEnd","<div id='blocker' class='screenBlocker' ></div>");
	var theDiv = document.getElementById("blocker");
	theDiv.style.width	= document.body.scrollWidth;
	theDiv.style.height = document.body.scrollHeight;
}

function DisableMeAfterClick(ctrlName)
{
	//alert("'" + ctrlName + "'");
	var obj;
	eval("obj = document.all." + ctrlName);
	obj.disabled = true;
}

function saveLocationPart(dropName, HiddenColntrol)
{
	var objHidden;
	var objDrop;
	
	eval("objHidden = document.all." + HiddenColntrol);
	eval("objDrop	= document.all." + dropName);
	//alert(objDrop.value);
	objHidden.value = objDrop.value;
}
			


function AddMultiReqLocationToDB(locationName, remove)
{
	clsAjaxMethods.AddRequiredLocation(locationName, remove);
	//alert(locationName);
	//alert(remove);
}

function clickManager(theObj)
{
	clickManager(theObj, false, null);
}

function clickManager(theObj, Eevent)
{
	clickManager(theObj, false, Eevent);
}
			
function clickManager(theObj, saveToDB, Eevent)
{
	var Condition = false
	var SourceElement
	var TagName
	
	if (isIE)
	{
		TagName = event.srcElement.tagName
		SourceElement = event.srcElement
		
		if (TagName == 'INPUT' || TagName == 'LABEL')
			Condition = true;
	}
	else
	{
		TagName = Eevent.target.tagName
		SourceElement = Eevent.target
		
		if (TagName == 'INPUT' || TagName == 'LABEL')
			Condition = true;
		
	}
	
	if (Condition)
	{
		if (saveToDB && TagName == 'INPUT')
		{
			
			var collectTags
			
			if (isIE)
			{
				collectTags = event.srcElement.parentElement.all;
			}
			else
			{
				collectTags = Eevent.target.parentNode.childNodes;
			}
	
			if (SourceElement.checked)
				AddMultiReqLocationToDB(locations.get( collectTags[1].innerHTML ), 'false')
			else
				AddMultiReqLocationToDB(locations.get( collectTags[1].innerHTML ), 'true')

		}
			
		var theCollection = theObj.getElementsByTagName('INPUT');	
		//alert('Num of Inputs - ' + theCollection.length);	
		//alert('input id ' + event.srcElement.name + ' was clicked');
		//alert();
		for (i=0; i<theCollection.length; i++)
		{
			if (TagName == 'INPUT')
			{
				//INPUT tag was clicked so we compare input's ID
				if (SourceElement.id == theCollection.item(i).id)
				{
					var itemClicked = i + 1;
					//alert('Item number ' + (itemClicked) +  ' was clicked');
				}
			} else {
				//LABEL tag was clicked so we compare it's FOR attribute to the INPUT's ID
				if (SourceElement.htmlFor == theCollection.item(i).id)
				{
					var itemClicked = i + 1;
					//alert('Item number ' + (itemClicked) +  ' was clicked');
				}						
			}
		}
		
		if (itemClicked == theCollection.length)
		{

			//Last item was clicked - clear others
			//alert ('last was clicked');
			for (i=0; i<theCollection.length - 1; i++)
			{
				theCollection.item(i).checked = false;
			};
			theCollection.item(theCollection.length-1).checked = true;
			

		} else {
			//Other than last was clicked
			//alert ('other was clicked');
			theCollection.item(theCollection.length - 1).checked = false;
		}
	}
}


function myTest()
{
	alert('123');
}

// -------------------------------------------------
// This function Handles The client side profile tabs 
// on the profiles list page
// -------------------------------------------------
// Written By Joey Simhon
// Date Created: March 6th 2005 02:53
// Last Updated: March 6th 2005 02:53
// -------------------------------------
function changeProfileTabs(tabClicked, infoHeaderID, imagesHeaderID, infoLayerID, imagesLayerID, picturesStr, noPicsMessage)
{
	var infoOnImg		=	'images_pitriot/pl/profile/info_on.gif';
	var infoOffImg		=	'images_pitriot/pl/profile/info_off.gif';
	var picOnImg		=	'images_pitriot/pl/profile/pic_on.gif';
	var picOffImg		=	'images_pitriot/pl/profile/pic_off.gif';
	
	var infoHeaderObj	=	document.getElementById(infoHeaderID);
	var imagesHeaderObj =	document.getElementById(imagesHeaderID);
	var infoLayerObj	=	document.getElementById(infoLayerID);
	var imagesLayerObj	=	document.getElementById(imagesLayerID);

	if (tabClicked == 'info')	
	{
		// change tab headers
		infoHeaderObj.src		=	infoOnImg;
		imagesHeaderObj.src		=	picOffImg;
		
		// change tab display
		infoLayerObj.style.display		=	'block';
		imagesLayerObj.style.display	=	'none';		
	}
	else if (tabClicked == 'pic')	
	{
		// change tab headers
		infoHeaderObj.src		=	infoOffImg;
		imagesHeaderObj.src		=	picOnImg;			
		
		// change tab display
		infoLayerObj.style.display		=	'none';
		imagesLayerObj.style.display	=	'block';
		
		// Dynamically write the images layer
		if (picturesStr != '')
		{
			var picArr	=	picturesStr.split('~');
			var divs	=	imagesLayerObj.all.tags('div');
			
			for (i = 0; i < picArr.length; i ++)
			{
				if (picArr[i] != null)
				{
					divs[i*2].all.tags('img')[0].src = picArr[i].toString();
					//divs[i*2].all.tags('div')[0].style.cursor = 'pointer';
				} //if
				
			} //for
			
			// Hide Un-needed images
			if (picArr.length < 3)
			{
				for (i = 3; i > picArr.length ; i --)
				{
					divs[i*2-2].style.display = 'none';
				}; //for
			}; //if
			
		} else {	// Display No Images Message
			
			// Hide Image Frames
			
			var divs	=	imagesLayerObj.all.tags('div');
			for (i = 0; i < divs.length; i ++)
			{
				divs[i].style.display = 'none';
			}; //for
			divs[i-1].style.display = 'block';
			divs[i-1].innerHTML = noPicsMessage;
			
		}; // else					
	}; // else if				
}; // function

// -------------------------------------------------
// This function handles a case where source picture 
// cannot be found. It shows a jane/john doe photo
// instead.
// -------------------------------------------------
// Written By Rotem Harel
// Date Created: December 13th 2005 09:03
// Date Updated: December 13th 2005 09:03
// -------------------------------------
function setDefaultPicture(size, gender, obj)
{
	img = new Image();
	img.src = "images_pitriot/common/nopic/" + size + "_" + gender + ".gif";
	obj.src = img.src;
	/*
	// Prevent bugs. lo oved li.... img.complete is always false. WHY???
	img.onload = function() {
		if(img.complete) {
			obj.src = img.src;
		}
	}*/
	//img.src = "images_pitriot/common/nopic/" + size + "_" + gender + ".jpg";
	//obj.src = img.src;
	//obj.src = "images_pitriot/common/nopic/" + size + "_" + gender + ".jpg";
	//alert(obj.src);
}; //function