﻿var AfterDeletBaseID = null;
var AppName = "DMS"






function FarsiForSearchKeyPress()
{
 var key = window.event.keyCode;
   if (key == 13 || key == 27 || key == 8)
      return;
   if (key < 0x0020 || key >= 0x00FF){
      alert("لطفا صفحه کلید خود را در حالت لاتین قرار دهید.");
      window.event.keyCode ="";
      return;
   }
   if (langFarsi) {
      var el = event.srcElement;
      var objRegExp = new RegExp("[A-Za-z\x27\x2C\x3B\x5B\x5C\x5D\x7C]");
      var validate_key = objRegExp.test(String.fromCharCode(key));
      if ((validate_key || (key==92)) && (key != 0x200C) && (el.value.lastIndexOf(String.fromCharCode(1740)) == el.value.length - 1) && el.value.length > 0) {
         el.value = el.value.slice(0, -1);
         el.value += String.fromCharCode(1610);
      }
      if (key == 0x0020 && window.event.shiftKey)
         window.event.keyCode = 0x200C;
      else
         window.event.keyCode = farsikey[key - 0x0020];
         if(key == 34)
         window.event.keyCode = 0x0022;
   }
   return true;

}






function DeleteItem(FileName, MasterCode, DelList)
{
	AskResult = confirm("حذف شود ؟")

	if(AskResult){
		window.onbeforeunload = '';
		window.location.href=FileName + '?DelList=' + DelList + '&Code=' + MasterCode
	}
}
function PrintJournal()
{
	window.print()
}
function DeleteFromEditForm(BaseID, DelCode)
{
    AskDel = confirm("آیا از حذف این رکورد مطمئن هستید ؟")
    if(AskDel)
    {
        DelUrl = '../jsGetBrowse.aspx?BaseID=' + BaseID + "&DelCode=" + DelCode 
        AfterDeletBaseID = BaseID
        startRequest(DelUrl, ShowDeleteComplete, 'GET', null, null);
    }

}
function ShowDeleteComplete()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(result=="DELETED")
	            {
	                alert('رکورد با موفقیت حذف شد')
	                if(AfterDeletBaseID != null)
	                    window.location.href = '../Main/Default.aspx?BaseID='+ AfterDeletBaseID
	                else
	                    window.location.href = '../Portal';
	            }
	            else if(result.indexOf("FK_")>0)
	                alert('این رکورد دارای اطلاعات مرتبط میباشد و قابل حذف نیست')
	            document.body.style.cursor='auto';
            }
       }
   }
}

function IsOnlyNumber()
{

var returnValue = false;
var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
if ( ((keyCode >= 48) && (keyCode <= 57)) ||
(keyCode == 8) || 
(keyCode == 9) || 
(keyCode == 46) || 
(keyCode == 45) || 
(keyCode == 13) ) 
returnValue = true;

if ( window.event.returnValue )
window.event.returnValue = returnValue;
return returnValue;
}
function IsOnlyNumberAndSlash()
{
var returnValue = false;
var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
if ( ((keyCode >= 47) && (keyCode <= 57)) ||
(keyCode == 8) || 
(keyCode == 9) || 
(keyCode == 13) ) 
returnValue = true;

if ( window.event.returnValue )
window.event.returnValue = returnValue;

return returnValue;
}


function ConfirmUnload()
{
    event.returnValue = "تغییرات نادیده گرفته شود؟";
}
function GetInfo(InputObj, BaseID)
{
	Code = InputObj.value
	document.body.style.cursor='wait';
	
	// Create an instance of the XML HTTP Request object
	var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
		
	// Prepare the XMLHTTP object for a HTTP POST to our validation ASP page
	var sURL = "../Seminars/GetInfo.asp?Code=" + Code + '&BaseID=' + BaseID
	oXMLHTTP.open( "POST", sURL, false );
	
	// Execute the request
	oXMLHTTP.send();
	
	rsl = oXMLHTTP.responseText
	InputObj.parentNode.parentNode.cells(2).childNodes(0).value = rsl
	if(rsl == 'رکورد مورد نظر یافت نشد')
		InputObj.parentNode.parentNode.cells(1).childNodes(0).value = ''
	document.body.style.cursor='auto';
	
}
function ImgOver(ImgObj)
{
	ImgObj.style.borderWidth = 1
	ImgObj.style.borderColor = 'black'
}
function ImgOut(ImgObj)
{
	ImgObj.style.borderWidth = 0
}

function DoPrint()
{
	window.print()
}
function AskDelete(Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		form1.DelValue.value = Code;
		form1.action = "index.asp"
		form1.submit()
	}
}

function AskDeleteDetail(FromAction, MasterCode, Code)
{
	AskResult = confirm("رکورد حذف شود؟")
	if(AskResult){
		window.onbeforeunload = '';
		form1.DelList.value = Code;
		form1.Code.value = MasterCode ;
		form1.action = FromAction
		form1.submit()
	}
}

function GotoLink(FormAction)
{
	if( FormAction != "undefined")
		form1.action = FormAction
	form1.submit();
}

function GotoUrl(Url)
{
    window.location.href = Url
}

function PickDate(DateFieldName, InitVal, Section)
{
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	
	X =  window.event.clientX
	Y =  window.event.clientY + 100
	if ( InitVal.length != 8)
		InitVal = '';
	whn = 	window.open('../DatePicker.asp?FFN=' + DateFieldName + '&InitDate=' + InitVal + '&Section=' + Section,'DatePicker','width=200,height=185,menubar=no,status=no,titlebar=no,resizable=no,top=' + Y + ',left=' + X );
}

function UploadPic(FileName)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=580,height=150,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowTree(FileName, BaseID, FFN, InitCode)
{
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FFN=' + FFN + '&InitGroup=' + InitCode,'PersonTree','width=580,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ShowFile(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile3(FileName, FieldName, Code)
{
		whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width=620,height=450,menubar=yes,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowFile2(PathName)
{
	whList = window.open(PathName,'','width=620,height=450,menubar=no,status=no,titlebar=no,resizable=no,scrollbars,top=200,left=150');
}

function ShowSizedFile(FileName, FieldName, Code,w, h)
{
	whList = window.open(FileName + '?' + FieldName + '=' +  Code,'','width='+ w + ',height=' + h + ',menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function OpenList(BaseID, ImgObj)
{
    var LookupObj = new XMLBrowse()

	if( getObj('LookupResults'))
	{
        getObj('LookupResults').style.display='none';
	}
    ShowMode = 'List';
    FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0];
    FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0];
    LookupObj.ViewEdit = 'Edit'
    LookupObj.CreateBrowse(BaseID, ShowMode);
    //BrowseObj = new XMLBrowse(BaseID, ShowMode);

//	whList = window.open('../List.aspx?BaseID=' + BaseID + '&FFC=' + FormFieldCode + '&FFN=' + FormFieldName ,'','scrollbars=yes, width=650,height=450,menubar=no,status=no,titlebar=no,resizable=yes,top=200,left=150');
}

function OpenListMaster(BaseID, ImgObj, MasterCode)
{
    if(MasterCode == '')
    {
        alert('لطفا ابتدا شرکت بیمه را انتخاب کنید')
        return false;
    }
        FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0].name;
        FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0].name;

		whList = window.open('../List.aspx?MasterCode=' + MasterCode + '&BaseID=' + BaseID + '&FFC=' + FormFieldCode + '&FFN=' + FormFieldName ,'','scrollbars=yes, width=650,height=450,menubar=no,status=no,titlebar=no,resizable=yes,top=200,left=150');
}

function OpenTree(BaseID, ImgObj)
{
        FormFieldCode = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[1].childNodes[0].name;
        FormFieldName = ImgObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0].name;

		whList = window.open('../GetTree.aspx?GetVal=1&BaseID=' + BaseID + '&FFC=' + FormFieldCode + '&FFN=' + FormFieldName ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function OpenTree2(BaseID, Width, Height,GroupCode)
{
		whList = window.open('../GetTree.aspx?MultiSelect=1&BaseID=' + BaseID + '&GroupCode=' + GroupCode ,'','width=' + Width + ',height=' + Height + ',menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function List2(BaseID, FormFieldName,Section, FN, FV)
{
		whList = window.open('../Admin/List.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section + '&FN=' + FN + '&FV=' + FV,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function ListMulti(BaseID, FormFieldName,Section)
{
		whList = window.open('../Admin/ListMulti.asp?BaseID=' + BaseID + '&FFN=' + FormFieldName + '&Section=' + Section ,'','width=450,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}


function ShowList(FileName, BaseID, FilterCols, FilterVals)
{
	if(FilterCols == undefined)
		FilterCols = ""
	if(FilterVals == undefined)
		FilterVals = ""
		whList = window.open(FileName + '?BaseID=' + BaseID + '&FN=' + FilterCols + '&FV=' + FilterVals,'','width=500,height=450,menubar=no,status=no,titlebar=no,resizable=no,top=200,left=150');
}

function GetLeftCenter(WinHeight, WinHeight)
{

	if (screen.width == 1024)
	{
		RTop = (768 - WinHeight) / 2
		Result = "top=" + RTop + ",left=213"
	}
	else
	{
		RTop = (600 - WinHeight) / 2
		Result = "top=" + RTop + ",left=20"
	}
		return Result
}



function ShowBrowse(BaseID, MasterID, Section)
{
	if(MasterID == '')
		alert('ابتدا ذخیره کنید')
	else
			//window.location.href = '../Browse.aspx?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section;
			whList = window.open('../BrowsePopup.aspx?BaseID=' + BaseID + '&MasterCode=' + MasterID + '&Section=' + Section,'','width=790,height=420,menubar=no,status=no,titlebar=no,scrollbars,resizable=no,top=200,left=150');
}


function DoMask(MaskFormat, str,textbox,loc,delim)
{
//	try{
	
	DoNothing = 0

	CurrentPos = textbox.value.length;
	var locs = loc.split(',');	

	KeyCode = event.keyCode
	if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
		if ((KeyCode > 47 && KeyCode < 58) || (KeyCode > 95 && KeyCode < 106)) {
			MaxL = MaskFormat.length + locs.length 
			if (textbox.value.length >= MaxL) {
					event.returnValue = false
					return false;
			}
			if (KeyCode > 95) KeyCode -= (95-47);
		} else if (KeyCode != 8 && KeyCode != 46 ) {
			event.returnValue = false
			return false;
		}
	}

	CurrentChar = String.fromCharCode(KeyCode)

	for (var i = 0; i <= locs.length; i++){
		for (var k = 0; k <= str.length; k++){
		 if (k == locs[i]){
		  if (str.substring(k, k+1) != delim){
		    str = str.substring(0,k) + delim + str.substring(k,str.length)
			textbox.value = str
		  }
		 }
		}
	 }

	if(CurrentPos < MaskFormat.length + locs.length)
	{
		if(MaskFormat.charAt(CurrentPos) == 'N')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == '/')
		{
			if( CurrentChar == '/')
			{
				DoNothing = 0
			}
			else
			{
				DoNothing = 1
			}
		}
		else if(MaskFormat.charAt(CurrentPos) == 'L')
		{
			if( !isNaN(CurrentChar))
			{
				DoNothing = 1
			}
			else
			{
				DoNothing = 0
			}
		}

	}	
	else
		DoNothing = 1
	

	if(DoNothing == 1)
		event.keyCode = 0
	return true;
//	}
//	catch(e)
//	{
//	}
}


function OpenDate(DivObj)
{

    //InitVal = TDObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0].name;
    InitVal = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].value;
    FFN = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].name;
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	X =  window.event.clientX 
	Y =  window.event.clientY
	if ( InitVal.length != 8)
		InitVal = '';


    DatePan.style.left = X - 32 + document.body.scrollLeft;
    DatePan.style.top = Y + 2 + document.body.scrollTop + document.documentElement.scrollTop;
//    alert(document.body.offsetHeight)
    DatePan.style.display = "block"
    Init(1)
//    window.resizeTo(X + DatePan.offsetWidth,Y + DatePan.offsetHeight+70)
//    document.body.scrollIntoView(true)
//    
//    alert(document.body.offsetHeight)
}


var http_request = null;
var DelObj = null;
function startRequest(url, Func, Method, Param, UpdateObj) { 
    DelObj = UpdateObj;
    if (window.XMLHttpRequest) { 
       http_request = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject) { 
       http_request = new ActiveXObject('Microsoft.XMLHTTP'); 
    } 
    url = url + '&rnd=' + Math.random();
//    alert(url)
    http_request.onreadystatechange = Func;
    http_request.open(Method, url, true); 
    if( Method == 'GET')
       http_request.send(null); 
    else
       http_request.send(Param); 
} 

function DelComplete()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(result == "Success")
	                DelObj.style.display = 'none';
	            else
	                alert(result);
	            document.body.style.cursor='auto';
            }
       }
   }
}


function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0');
 WinPrint.document.write("<link href=\"../styles/main.css\" rel=\"stylesheet\" type=\"text/css\">" +  prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();

//alert(WinPrint.document.getElementById("ctl00_cphMain_tblList").offsetHeight)
WinPrint.resizeTo(document.getElementById("ctl00_cphMain_tblList").offsetWidth + 30,document.getElementById("ctl00_cphMain_tblList").offsetHeight + 180 );
 WinPrint.print();
 WinPrint.close();
}

function OpenWin(Link, Width, Height,IsFullScreen)
{
//	X =  window.event.clientX
//	Y =  window.event.clientY + 100
//alert(screen.width)
    if (!IsFullScreen)
    {
        leftVal =(screen.width - Width) / 2;
        topVal = (screen.height - Height) / 2;
        window.open(Link,'','width=' + Width + ',height=' + Height + ',menubar=no,status=no,titlebar=no,scrollbars=yes,resizable=yes,top=' + topVal + ',left=' + leftVal );
    }
    else
    {
        window.open(Link,'','addressbar=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,screenX=0,screenY=0,top=0,left=0,maximize=1' + ', height='+screen.height+', width='+screen.width );
    
        
    }
}


function OpenWinWithMenuBar(Link, Width, Height)
{
//	X =  window.event.clientX
//	Y =  window.event.clientY + 100
//alert(screen.width)
leftVal = (screen.width - Width) / 2;
topVal = (screen.height - Height) / 2;

	window.open(Link,'','width=' + Width + ',height=' + Height + ',menubar=yes,status=no,titlebar=no,scrollbars=yes,resizable=yes,top=' + topVal + ',left=' + leftVal );
}  


function ResizeWin()
{
    MainEditObj = document.getElementById('dvMainEdit');
    var w=MainEditObj.offsetWidth;
    var h=MainEditObj.offsetHeight;
    alert(h)
    if ((w!=null) && (h!=null))
    {
    window.resizeTo(w,h);
//    var winX = (screen.width - w) / 2;
//    var winY = (screen.height - h) / 2;
//    window.moveTo(winX,winY);
    }

}

function OnClicking(sender, eventArgs)
{ 
	if (eventArgs.get_item().get_value() != "") 
	{
	    switch(eventArgs.get_item().get_value())
	    {
	    
	        case "Resources":
	            window.location.href = '../AccessLevel/ResourceTree.aspx';
	            break;
	        case "IGroups":
	            window.location.href = '../Tree/EditTree.aspx?BaseID=IGroups';
	            break;
	        case "Persons":
	            window.location.href = '../Persons';
	            break;
	        case "Countries":
	            window.location.href = '../Countries';
	            break;
	        case "Parties":
	            window.location.href = '../Parties';
	            break;
	        case "News":
	            window.location.href = '../News';
	            break;
	        case "Centers":
	            window.location.href = '../Centers';
	            break;
	        case "Medias":
	            window.location.href = '../Medias';
	            break;
	        case "Articles":
	            window.location.href = '../Articles';
	            break;
	        case "Thesises":
	            window.location.href = '../Thesises';
	            break;
	        case "MovementDictionaries":
	            window.location.href = '../MovementDictionaries';
	            break;
	        case "Documents":
	            window.location.href = '../Documents';
	            break;
	        case "MovementCalendars":
	            window.location.href = '../MovementCalendars';
	            break;
	        case "Seminars":
	            window.location.href = '../Seminars';
	            break;
	        case "Lectures":
	            window.location.href = '../Lectures';
	            break;
	        case "Interviews":
	            window.location.href = '../Interviews';
	            break;
	        case "Minorities":
	            window.location.href = '../Minorities';
	            break;	            
	        case "Press":
	            window.location.href = '../Press';
	            break;	            
	        case "Albums":
	            window.location.href = '../Albums';
	            break;	            

//	        case "GarbageWords":
//	            window.location.href = '../GarbageWords/EditGarbageWords.aspx';
//	            break;	            

	            
	        default :
	        {
	            if (eventArgs.get_item().get_childListElement() == null && eventArgs.get_item().get_value() != undefined)
	               	                window.location.href = '../Main/Default.aspx?BaseID=' + eventArgs.get_item().get_value()
        	    //BrowseObj1.CreateBrowse(eventArgs.Item.Value)
	        }
	    } 
	    return false;
	}
} 

function ShowHideTop()
{
    TopObj = document.getElementById('TopHeader')
    if(TopObj.style.display != 'none')
    {
        TopObj.style.display = 'none'
        document.getElementById('TDMainTD').className = ''
        document.getElementById('TDMain').className = 'cTblMainTD2'
    }
    else
    {
        TopObj.style.display = 'block'
        document.getElementById('TDMainTD').className = 'cTblMainTD'
        document.getElementById('TDMain').className = 'cTblMainEdit'
    }            
    
}

function CorrectText(str)
{
    return str.replace('ي', 'ی').replace('ي', 'ی').replace('ى', 'ی').replace('ك', 'ک')
            .replace('٠', '۰').replace('١', '۱').replace('٢', '۲').replace('٣', '۳').replace('٤', '۴')
            .replace('٥', '۵').replace('٦', '۶').replace('٧', '۷').replace('٨', '۸').replace('٩', '۹')
}
function ConvertNumbersToEnglish(str)
{
    return str.replace('۰','0').replace('۱','1').replace('۲','2').replace('۳','3').replace('۴','4')
            .replace('۵','5').replace('۶','6').replace('۷','7').replace('۸','8').replace('۹','9');

}
var lblUpdateObj = null;
function ShowLabel(FeildName, Code)
{
    lblUpdateObj = event.srcElement;
    startRequest('ShowLabel.aspx?FullFieldName=' + Fieldname + '&DetailCode=' + Code, PutLabelString, 'GET', null, lblUpdateObj);
}
function PutLabelString()
{
    if(http_request != null)
    {
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
	            result = http_request.responseText
	            if(lblUpdateObj != null)
	                lblUpdateObj.innerHTML = result;
	            document.body.style.cursor='auto';
            }
       }
   }
}

function PrintStr()
{
    CallPreviewPrint('PrintArea');
}

function PrintPage(btnObj)
{
    window.print();
}

function CallPreviewPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','PrintPage','letf=0,top=0,width=950,height=800,toolbar=0,scrollbars=1,status=0,resizeable=true');
 
 StrBody = "<body style=\"background-color:white\" dir=rtl>";
 StrBody += "<link id=\"ctl00_Link1\" href=\"../styles/main.css\" rel=\"stylesheet\" type=\"text/css\" />";
 StrBody += "<script src=\"../js/main.js\" type=\"text/javascript\"></script>";
 StrBody += "<div id=\"PrintArea\">" + prtContent.innerHTML + "</div><br /><a href=\"#\" class=\"cPrint2\" onclick=\"CallPrint('PrintArea')\"><img src=\"../images/spacer.gif\" alt=\"Print\" class=\"cPrint2\" /></a></body>"
 WinPrint.document.write(StrBody);
 WinPrint.document.close();
 WinPrint.focus();

}


function CallPrint(strid)
{
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=1,status=0');
 WinPrint.document.write("<body dir=rtl>" + prtContent.innerHTML + "</body>");
 WinPrint.document.close();
 WinPrint.focus();

//alert(WinPrint.document.getElementById("grdPrint").offsetHeight)
//WinPrint.resizeTo(document.getElementById("grdPrint").offsetWidth + 30,document.getElementById("grdPrint").offsetHeight + 180 );
WinPrint.print();
WinPrint.close();
}

function ToggleSelection(ChkObj)
{
    tblObj = ChkObj.parentNode.parentNode.childNodes[1]
    for(i=0; i < tblObj.rows.length; i++)
    {
        for(j=0; j < tblObj.rows[i].cells.length; j++)
        {
             CurCheckBox = tblObj.rows[i].cells[j].childNodes[0]   
             if(ChkObj.checked)
                CurCheckBox.checked = true;
             else
                CurCheckBox.checked = false;
                     
        }
    }

}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}
function ChangeStar(objLI)
{
    objUL = objLI.parentNode;

    Index = 0;
    for(i =0; i < objUL.childNodes.length; i++)
    {
        objUL.childNodes[i].className = "StarFull";
        Index++;
        if(objLI == objUL.childNodes[i])
            break;
    }
    for(i =Index; i < objUL.childNodes.length; i++)
    {
        objUL.childNodes[i].className = "StarHalf";

    }

}

function RestoreStars (objStars)
{
    objOnStars = objStars.childNodes[0].childNodes[0];
    objOffStars = objStars.childNodes[1].childNodes[0];
    
    for(i = 0; i < objOnStars.childNodes.length; i++)
    {
        objOnStars.childNodes[i].className = "StarFull";
    }
    for(i = 0; i < objOffStars.childNodes.length; i++)
    {
        objOffStars.childNodes[i].className = "StarHalf";
    }    
}


function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	//popUpDiv.style.top = popUpDiv_height + 'px';
	popUpDiv.style.top = '200px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

/////////////////////////////////////////////////////////////////////////////////////////////


// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});

/*
$(document).ready(function() {
    //jQuery.easing.def = 'easeOutBounce';
    var method1 = 'easeOutCirc';
    var method2 = 'easeOutBounce';
	$("#StatBoxHeader").click(function(e){
		e.preventDefault();
		this.blur();
		//$('#BoxStat').animate({height:200}, {duration: 1000, easing: method1});
		if ($("#BoxStat").is(":hidden")) {
		    $("#BoxStat").show("slow");
		} else {
		    $("#BoxStat").slideUp();
		}
    });
});
*/
function SlideBoxes(objBoxHeader) {
    objBoxContent = objBoxHeader.parentNode.parentNode.childNodes[1];
    if ($(objBoxContent).is(":hidden")) {
        $(objBoxContent).slideDown();
    } else {
        $(objBoxContent).slideUp();
    }
}


