
// Find object position
function getRealPos(ele, dir)
{
	if(dir=="x") 
		pos = ele.offsetLeft;
 	else
		pos = ele.offsetTop;
	tempEle = ele.offsetParent;
	while (tempEle != null)
	{
		pos += (dir=="x") ? tempEle.offsetLeft : tempEle.offsetTop;
		tempEle = tempEle.offsetParent;
	}
	return pos;
}

function getElementSize(elem) {
    return [elem.offsetWidth, elem.offsetHeight];
}
//is ie6 or other
function getIEVersionNumber() {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf('MSIE ');
    if (browser == 'Microsoft Internet Explorer') {
        if (MSIEOffset == -1) {
            return version
        } else {
            return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(';', MSIEOffset)));
        }
    }
    else return 11;
}
var g_PopupIFrame;
function HideAllSelect(hza) {//listboxlar div'in üstünde gözüküyordu
    var vers = getIEVersionNumber();
    if (vers <= 6 && vers > 0) {
        if (hza.style.visibility == 'visible') {
            hza.style.zIndex = hza.style.zIndex + 1;
            var iFrame = document.createElement('IFRAME');
            iFrame.setAttribute('src', '');
            iFrame.style.position = 'absolute';
            iFrame.style.left = hza.offsetLeft + 'px';
            iFrame.style.top = hza.offsetTop + 'px';
            iFrame.style.width = hza.offsetWidth + 'px';
            iFrame.style.height = hza.offsetHeight + 'px';
            document.body.appendChild(iFrame);
            g_PopupIFrame = iFrame;
        }
        else {
            document.body.removeChild(g_PopupIFrame);
            g_PopupIFrame = null;
        }
    }
}
//for classic ajax character problem
function textForReq(sText) {
    if (navigator.appName != 'Netscape')
        return escape(sText);
    else
        return encodeURIComponent(sText);
}
//getelement 
function getElement(ElemID)
{
	if(document.all)
		return document.all(ElemID);
	else
		return document.getElementById(ElemID);

}
//email validation
function ValidateEmail(sEmail) {
    var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

    return reg.test(sEmail);
}

function addItem(number) {
    documentInOtherFrame = window.parent.frames[1].document;
    box = documentInOtherFrame.getElementById("selectHoldingBox");

    opt = documentInOtherFrame.createElement("option");
    opt.text = getTitle(files[number]);
    opt.value = currentPath + files[number];
    box.options[box.options.length] = opt;
}

function MoveImage() {
}
// Create tooltip
var toolTip = null;
var toolTipPoint = null;
var toolTipParent = null;
var toolIFrame = null;
function onCountryChange(ddlCountry,lblCountry)
{
	var country = getElement(ddlCountry);
	var lbl = getElement(lblCountry);
	var hdn = getElement("hdncountryCodeID" + country.options[country.selectedIndex].value);
	if(hdn)
		lbl.innerText = "+" + hdn.value; 	
	else
		lbl.innerText = "";
}

function DisableDatePicker(sobjname,strChkBox)
{
	var dobj = getElement(sobjname + "_day")
	var mobj = getElement(sobjname + "_month")
	var yobj = getElement(sobjname + "_year")
	if(dobj)
	{
		var chkBox = getElement(strChkBox);
		dobj.disabled = !chkBox.checked;
		mobj.disabled = !chkBox.checked;
		yobj.disabled = !chkBox.checked;
	}
}
		
function daysinmonth(lnMonth,lnYear) 
{
	var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn
	lmn = lnMonth - 1
	dt1 = new Date(lnYear, lmn, 1)
	cmn1 = dt1.getMonth()
	dtt = dt1.getTime() + 2332800000
	lflag = true
	dycnt = 28
	while (lflag) {
	dtt = dtt + 86400000
	dt1.setTime(dtt)
	cmn2 = dt1.getMonth()
	
	if (cmn1!=cmn2) {
		lflag = false }
	else {dycnt = dycnt + 1}}
	if (dycnt > 31) {dycnt = 31}
		return dycnt
}
function setdays(DayName,MonthName,YearName)
{
	var dobj = getElement(DayName)
	var mobj = getElement(MonthName)
	var yobj = getElement(YearName)
	if(!dobj)
		return;
	var monthdays = daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)
	var selectdays = dobj.length
	var curdy = dobj.options[dobj.selectedIndex].value
	
	
	if (curdy.length==1) 
		{curdy = "0"+curdy}    
	var curmn = mobj.options[mobj.selectedIndex].value
	if (curmn.length==1) {curmn = "0"+curmn}
	var curyr = yobj.options[yobj.selectedIndex].value
	if (selectdays > monthdays) {
		for (var dlp=selectdays; dlp > monthdays; dlp--) {
			dobj.options[dlp-1] = null 
		}
	}
	else if (monthdays > selectdays) {
		for (var dlp=selectdays; dlp < monthdays; dlp++) 
		{
			dobj.options[dlp] = new Option(dlp+1,dlp+1) 
		}
	}
	if (curdy > monthdays) {
		dobj.options[monthdays-1].selected = true
		curdy = monthdays 
	}
	var curdate = curdy + " / " + curmn + " / " + curyr
}

function blurTip()
{
	try{
		IEMajor =getIEVersionNumber(); 		
		if(IEMajor>5) 
		{
			// If tooltip exists
			if (toolTip != null)
			{
				document.body.removeChild(toolTip);
				toolTip = null;
				toolTipParent = null;
			}
			if(toolIFrame!=null)
			{
			 document.body.removeChild(toolIFrame);
			 toolIFrame=null;
			}
		}
	}
	catch(o)
	{
	}
}

function focusTip(obj,msg)
{
try{
 	IEMajor = getIEVersionNumber(); 
	if(IEMajor>5) 
	{
		// Remove any existing tooltip
		blurTip();		
		if (toolTip == null) // If tooltip is null
		{
			// Get window dimensions
			if (typeof window.innerWidth!="undefined")
			{
				winSize = {
					x : window.innerWidth,
					y : window.innerHeight
				};
			}
			else if (typeof document.documentElement.offsetWidth!="undefined")
			{
				winSize = {
					x : document.documentElement.offsetWidth,
					y : document.documentElement.offsetHeight
				};
			}
			else 
			{
				winSize = {
					x : document.body.offsetWidth,
					y : document.body.offsetHeight
				};
			}			
			toolTip = document.createElement('DIV');
			var subMsg = msg.split("@");			
			var sInnerText="";
			for(i=0;i < subMsg.length;i++)
			{
				var sInMsg=eval(subMsg[i]);
				if(sInMsg.indexOf ('@')!=-1)
				{
					var subMsg2 = sInMsg.split("@");			
					for(j=0;j < subMsg2.length;j++)
					{
						if(subMsg2[j]!=null && subMsg2[j]!="undefined")
						{
							if(sInnerText=="")
								sInnerText='<li>'+ subMsg2[j]+'</li>';
							else
								sInnerText=sInnerText+"<li>"+subMsg2[j]+'</li>';									 			
						}
					}
				}
				else if(sInMsg!=null && sInMsg!="undefined")
				{
					if(sInnerText=="")
						sInnerText='<li>'+ eval(subMsg[i])+'</li>';
					else
						sInnerText=sInnerText+"<li>"+eval(subMsg[i])+'</li>';									 			
				}
			}
			toolTip.size = i+14;
			if(sInnerText.length>0)
				sInnerText='<img src="/UserFiles/images/icons/unlem.gif" align="right"><ul class="infoul">'+sInnerText+'</ul>';
			toolTip.innerHTML=sInnerText;				

			if (toolTipParent == null)
			{
				toolTipParent = {
					x : getRealPos(obj, 'x'),
					y : getRealPos(obj, 'y') + 2
				};
			}

			toolTipParent.y = toolTipParent.y-14;
			toolTipParent.x += obj.offsetWidth+10;

			moveTip();
			
			toolTip.style.position='absolute';
			toolTip.setAttribute('class', '');
			toolTip.className = 'InfoMsg';
			// Add to document
			toolTipPoint = document.createElement('DIV');
			toolTipPoint.setAttribute('class', '');
			toolTipPoint.className = 'InfoMsg-pointer';			
			toolTip.appendChild(toolTipPoint);
			document.body.appendChild(toolTip);

			adjustWidth(obj);
			
			toolTip.style.left = toolTipParent.x + 'px';
			toolTip.style.top = toolTipParent.y + 'px';
			 if(IEMajor<=6)
			{
				var iFrame = document.createElement('IFRAME');
				iFrame.setAttribute('src', '');
				iFrame.style.position='absolute';
				iFrame.style.left =toolTip.offsetLeft + 'px';
				iFrame.style.top =toolTip.offsetTop + 'px';
				iFrame.style.width =toolTip.offsetWidth + 'px';
				iFrame.style.height =toolTip.offsetHeight + 'px';									
				document.body.appendChild(iFrame);
				toolIFrame=iFrame;
				toolTip.style.zIndex=toolTip.style.zIndex+1;				
			 }
			 else
			{
				if(toolIFrame!=null)	
					document.body.removeChild(toolIFrame);
				 toolIFrame=null;
			}						
			
		}
		}
	}
	catch(o)
	{
	}
}
function adjustWidth(obj)
{
// Restrict width
	try{
		//debugger;
		if (toolTip.offsetWidth > 300) toolTip.style.width = '300px';
		var xDif=0;
		var yDif=0;
		// Get tooltip extent
		extent = {
			x : toolTip.offsetWidth,
			y : toolTip.offsetHeight
		};

//		if ((toolTipParent.x + extent.x) >= winSize.x)
//		{
			//shift tooltip left
			xDif = toolTipParent.x;
			toolTipParent.x -= extent.x;
			xDif -= toolTipParent.x;
			toolTip.style.left = toolTipParent.x + 'px';
//		}
		
		// Get scroll height
		if (typeof window.pageYOffset!="undefined")
		{
			scrollHeight = window.pageYOffset;
		}
		else if (typeof document.documentElement.scrollTop!="undefined")
		{
			scrollHeight = document.documentElement.scrollTop;
		}
		else 
		{
			scrollHeight = document.body.scrollTop;
		}
		// If tooltip exceeds window height
		
//		if ((toolTipParent.y + extent.y) >= (winSize.y + scrollHeight))
//		{
			//shift tooltip up
			yDif = toolTipParent.y;
			toolTipParent.y -= (extent.y+obj.offsetHeight-28);
			yDif -=toolTipParent.y;
			toolTip.style.top = toolTipParent.y + 'px';
			//herzaman üstte çıkması için
			
//		}
		if(xDif>0 && yDif == 0)
		{
			
			toolTipParent.y = toolTipParent.y + obj.offsetHeight+27;
			toolTip.style.top = toolTipParent.y + 'px';
			
			toolTipPoint.setAttribute('class', '');
			toolTipPoint.className = 'InfoMsg-pointerUP';			
			toolTipPoint.style.left =  toolTip.offsetWidth-32 + 'px';
			SetToolTipBorderStyle('Top,Left');		
		}
		else if(xDif>0 && yDif > 0)
		{
			toolTipParent.y = toolTipParent.y -54;
			toolTip.style.top = toolTipParent.y + 'px';
			
			toolTipPoint.setAttribute('class', '');
			toolTipPoint.className = 'InfoMsg-pointerDown';	
			toolTipPoint.style.left =  toolTip.offsetWidth-74 + 'px';
			SetToolTipBorderStyle('Bottom,Right');
		}
		else if(xDif==0 && yDif>0)
		{
			toolTipParent.x -= 1;
			toolTip.style.left = toolTipParent.x + 'px';			
			toolTipParent.y += 22;			
			toolTip.style.top = toolTipParent.y + 'px';
			toolTipPoint.style.top = extent.y-toolTipPoint.offsetHeight-4;
			SetToolTipBorderStyle('Left,Bottom');			
		}
		else if(xDif==0 && yDif==0)
		{
			SetToolTipBorderStyle('Left,Bottom');
		}
	}
	catch(o)
	{
	}
}
function SetToolTipBorderStyle(directions)
{
	return;
	var directn = directions.split(",");			
	for(i=0;i < directn.length;i++)
	{
		eval('toolTip.style.border'+directn[i]+'Width=2;');
		eval('toolTip.style.border'+directn[i]+'Style="solid";');
		eval('toolTip.style.border'+directn[i]+'Color="#A7A7A7";');									 			
	}
	
}
// function SetToolTipBorderStyle(directions)
// {
	// var directn = directions.split(",");			
	// for(i=0;i < directn.length;i++)
	// {
		// eval('toolTip.style.border'+directn[i]+'Width=2;');
		// eval('toolTip.style.border'+directn[i]+'Style="solid";');
		// eval('toolTip.style.border'+directn[i]+'Color="#92adc7";');									 			
	// }
	
// }
function moveTip()
{
			// Get focused object coordinates
/* if(toolTip!=null)
{	
	toolTip.style.left = event.clientX + 'px';
	toolTip.style.top = event.clientY + 'px';
} */

}
function select_deselectAll (chkVal, idVal) 
{
    var frm = document.forms[0]; for (i = 0; i < frm.length; i++) { if (idVal.indexOf('chkSelectAll') != -1) { if (chkVal == true) { frm.elements[i].checked = true; } else { frm.elements[i].checked = false; } } else if (idVal.indexOf('chkSelect') != -1) { if (frm.elements[i].checked == false) { frm.elements[1].checked = false; } } } 
}

function getCookie(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 setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

/* text wrap Start*/
function wordbreaktext(clsName,tgName) {
    var tag = document.getElementsByTagName(tgName);
    for (var i = 0; i < tag.length; i++) {
        if (tag.item(i).className == clsName) {
            var text = tag.item(i).innerHTML;
            tag.item(i).innerHTML = wrapnewln(text);
        }
    }
}

function wrapnewln(sText) {
    var sRet = "";
    var str = sText.split(/\r\n/g);    
    for (i = 0; i < str.length; i++) {
        var sTem = str[i];
        if (sTem.length > 10) {
            sRet = sRet + (sRet.length>0?"<br/>":"")+ wraptextspace(sTem);
        }
        else if (sTem.length > 0) {
            sRet = sRet + (sRet.length>0?"<br/>":"") + sTem;
        }
    }
    return sRet;
}
function wraptextspace(sText) {
    var sRet = "";
    var str = sText.split(/\s/g);
    for (j = 0; j < str.length; j++) {
        var sTemj = str[j];
        if (sTemj.length > 10) {
            sRet = sRet + (sRet.length > 0 ? " " : "") + wbr(sTemj, 10);
        }
        else if (sTemj.length>0) {
            sRet = sRet + " " + sTemj;
        }
    }
    return sRet;
}
function wbr(str, num) {
    return str.replace(RegExp("(\\D{" + num + "})(\\D)", "g"), function(all, text, char) {
        return text + "<wbr/>" + char;
    });
}
/*text wrap end*/
function trim(sValue) { return sValue.replace(/^\s{1,}/ig, '').replace(/\s{1,}$/ig, ''); }

var sleepDV = null;
function SleepIMG(lstJob, bSH) {
    
    if (sleepDV == null && bSH==true) {
        sleepDV = document.createElement('DIV');
        sleepDV.id = 'idSleppIMGDiv';
        sleepDV.innerHTML = "<table><tr><td><img src='/UserFiles/images/icons/loading.gif'></td><td><small>yükleniyor...</small></td></tr></table>";
        document.body.appendChild(sleepDV);
    }
    if (bSH == true) {
        var pos = [getRealPos(lstJob, 'x'), getRealPos(lstJob, 'y')];
        sleepDV.className = 'ShowSLPDiv';
        if (document.layers) {
            sleepDV.left = pos[0] + 5;
            sleepDV.top = pos[1] - 5;
        }
        else {
            sleepDV.style.left = pos[0] + 20;
            sleepDV.style.top = pos[1] - 10;
        }
    }
    else {
        if (sleepDV) {
            sleepDV.setAttribute("style", "display:none");
            sleepDV.style.display = 'none';            
            sleepDV.innerHTML = '';
            document.body.removeChild(sleepDV);
        }
        sleepDV = null;
    }
}