var bToggle = false;

function copySelectedOptions(from,to)
{
	to.options.length = 0;
	var j = 0;
	for(i=0;i<from.options.length;i++)
	{
		if(from.options[i].selected == true)	
		{	
			var temp = from.options[i].value.split("~");
			to.options[j] = new Option(temp[1],temp[0]);
			j++;
		}
	}
}
function copySelectedToTextBox(from,to)
{
	for(i=0;i<from.options.length;i++)
	{
		if(from.options[i].selected == true)	
		{	
			var temp = from.options[i].value.split("~");
			to.value = temp[1];
		}
	}
}

function replaceSubstring(inputString, fromString, toString) 
{
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") 
   {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) 
   { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) 
      {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } 
   else 
   { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") 
      {
         for (var i=0; i < midStrings.length; i++) 
         {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) 
            {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) 
      {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) 
      {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
function LTrim(sString)
{
	var temp = sString;
	while(temp.substring(0,1) == ' ')
	{
		temp = temp.substring(1, temp.len);
	}
	return temp;
}
function toggle(sName, bDisplay)
{
	if(bDisplay)
	{
		document.getElementById(sName).style.display = '';
	}
	else
	{
		document.getElementById(sName).style.display = 'none';
	}
}
function isNum(n)
{
	var valid = "0123456789";
	//var ok = "yes";
	var temp;
	for (var i = 0; i < n.length; i++) 
	{
		temp = "" + n.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") return false;
	}
	return true;
}
function isISSN(sISSN)
{
	if(sISSN.length != 9)return false;
	if(sISSN.charAt(4) != "-")return false;
	var temp=sISSN.split("-");
	if(!isNum(temp[0]))return false;
	if(!isNum(temp[1]))return false;
	return true;
}
function isEmail1(str)
{
	var filter=/^.+@.+\..{2,3}$/

	if (filter.test(str))
	{
		return true;
	}
	else 
	{
		return false;
	}
}
function isEmail2(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	{
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false;
	}
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}
	return true;			
}
function isDate(sString)
{
	//check for dd/mm/yyyy
	var d1=sString.split("/");
	var _dd=parseFloat(d1[1]);
	var _mm=parseFloat(d1[0]);
	var _yy=parseFloat(d1[2]);
	if(d1.length != 3 || d1[0] == "" || d1[1] == "" || d1[2] == "" || !isNum(d1[0]) || !isNum(d1[1]) || !isNum(d1[2]) || _dd > 31 || _mm > 12 || _yy < 1900 || _dd <= 0 || _mm <= 0 || _yy > 9999)
	{
		return false;
	}
	return true;
}
function fIsEmpty(sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if (oElement.value == "")
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}
function fIsNotNum(sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (!isNum(oElement.value))
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}
function fIsNotEmail(sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (!isEmail2(oElement.value))
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}
function fIsNotInRange(iRange1, iRange2, sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (!isNum(oElement.value))
	{
		return sMessage;
	}
	var iCheck = parseInt(oElement.value);
	if (iCheck < iRange1 || iCheck > iRange2)
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}
function fIsNotNumOrChar(sChar, sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (isNum(oElement.value) || (oElement.value == sChar))
	{
		return "";
	}
	else
	{
		return sMessage;
	}
}
function fIsChooseActorOk(sName1, sName2, sName3, sName4, sName5, sName6, sName7, sName8, sName9, sName10, sMessage)
{
	var oElement1 = window.document.getElementById(sName1);
	var oElement2 = window.document.getElementById(sName2);
	var oElement3 = window.document.getElementById(sName3);
	var oElement4 = window.document.getElementById(sName4);
	var oElement5 = window.document.getElementById(sName5);
	var oElement6 = window.document.getElementById(sName6);
	var oElement7 = window.document.getElementById(sName7);
	var oElement8 = window.document.getElementById(sName8);
	var oElement9 = window.document.getElementById(sName9);
	var oElement10 = window.document.getElementById(sName10);
	var a = "";
	for(i = 1;i<=10;i++)
	{
		for(j=i+1;j<=10;j++)
		{
			eval("if(oElement" + i + ".value != ''){if (oElement" + i + ".value == oElement" + j + ".value){ a = '" + sMessage + "';}}");
		}
	}
	return a;
}
function fIsChooseActorOk1(sName1, sName2, sMessage)
{
	var oElement1 = window.document.getElementById(sName1);
	var oElement2 = window.document.getElementById(sName2);
	var a = "";
	for(i = 1;i<=2;i++)
	{
		for(j=i+1;j<=2;j++)
		{
			eval("if(oElement" + i + ".value != ''){if (oElement" + i + ".value == oElement" + j + ".value){ a = '" + sMessage + "';}}");
		}
	}
	return a;
}
function isInString(sString, sInString) 
{
  if (sString == "") return true;
  for (i=0; i<sString.length; i++) 
  {
    if (sInString.indexOf(sString.charAt(i),0) == -1) return false;
  }
  return true;
}
function fIsValidString(sString, sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (isInString(oElement.value, sString))
	{
		return "";
	}
	else
	{
		return sMessage;
	}
}
function fIsISSN(sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (isISSN(oElement.value))
	{
		return "";
	}
	else
	{
		return sMessage;
	}
}
function fIsDate(sName, sMessage)
{
	var oElement = window.document.getElementById(sName);
	if(oElement.value == "") return "";
	if (isDate(oElement.value))
	{
		return "";
	}
	else
	{
		return sMessage;
	}
}
function fToggle(bChecked)
{
	bToggle = bChecked;
	toggle("hiderow0000",bChecked);
	toggle("hiderow2006",bChecked);
	toggle("hiderow2007",bChecked);
	toggle("hiderow2008",bChecked);
	toggle("hiderow2009",bChecked);
	toggle("hiderow2010",bChecked);
	toggle("hiderow2011",bChecked);
	toggle("hiderow2012",bChecked);
	toggle("hiderow2013",bChecked);
	toggle("hiderow2014",bChecked);
	toggle("hiderow2015",bChecked);
	toggle("hiderow2016",bChecked);
	toggle("hiderow2017",bChecked);
	toggle("hiderow2018",bChecked);
	toggle("hiderow2019",bChecked);
	toggle("hiderow2020",bChecked);
}
function fShowCategory(sList, sDesc)
{
	var oList = window.document.getElementById(sList);
	var oDesc = window.document.getElementById(sDesc);
	var sText = oList.options[oList.selectedIndex].text;
	oDesc.value = sText
}
function fShowCategory1(sList, sDesc1, sDesc2)
{
	var oList = window.document.getElementById(sList);
	var oDesc1 = window.document.getElementById(sDesc1);
	var oDesc2 = window.document.getElementById(sDesc2);
	var sText = oList.options[oList.selectedIndex].value;
	var temp = sText.split("/")
	oDesc2.value = temp[1];
	oDesc1.value = temp[2];
	//oDesc1.value = sText
}
function fSelectValue(sList, sValue, sMessage)
{
	var oList = window.document.getElementById(sList);
	if(oList.options[oList.selectedIndex].value == sValue)
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}

function fSelectValueIsEqual(sList1, sList2, sMessage)
{
	var oList1 = window.document.getElementById(sList1);
	var oList2 = window.document.getElementById(sList2);
	if(oList1.selectedIndex == 0)return ""; 
	if(oList2.selectedIndex == oList1.selectedIndex)
	{
		return sMessage;
	}
	else
	{
		return "";
	}
}
//This function use for get select value from list box to list box
function fInsert(el,ins) { 
    if (el.setSelectionRange){ 
        el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length); 
    } 
    else if (document.selection && document.selection.createRange) { 
        el.focus(); 
        var range = document.selection.createRange(); 
        range.text = ins + range.text; 
    } 
} 
function fGetValueFromListBox(sListFrom, sListTo)
{
	var oListFrom = window.document.getElementById(sListFrom);
	var oListTo = window.document.getElementById(sListTo);
	copySelectedOptions(oListFrom, oListTo);
}
function fGetValueFromListBoxToTextbox(sListFrom, sListTo)
{
	var oListFrom = window.document.getElementById(sListFrom);
	var oListTo = window.document.getElementById(sListTo);
	copySelectedToTextBox(oListFrom, oListTo);
}
function fInsertVariable(sVariable, sSubject, sBody, sWhichText)
{
	var oVariable = window.document.getElementById(sVariable);
	var oWhichText = window.document.getElementById(sWhichText);
	var oText;
	if (oWhichText.value == "1")
	{
		oText = window.document.getElementById(sSubject);
	}
	else
	{
		oText = window.document.getElementById(sBody);
	}
	fInsert(oText, oVariable.options[oVariable.selectedIndex].text);
}

function addOption(selectObject,optionText,optionValue) 
{
	if (selectObject != null)
	{
		var optionObject = new Option(optionText,optionValue);
		var optionRank = selectObject.options.length;
		selectObject.options[optionRank]=optionObject;
    }
}
function deleteOption(selectObject,optionRank) 
{
	if(selectObject.options.length != 0) 
    { 
		selectObject.options[optionRank] = null; 
	}
}
function fMoveToOtherListbox(sFrom, sTo)
{
	var oFrom = window.document.getElementById(sFrom);
	var oTo = window.document.getElementById(sTo);
	addOption(oTo,oFrom.options[oFrom.selectedIndex].text,oFrom.options[oFrom.selectedIndex].value);
	deleteOption(oFrom,oFrom.selectedIndex);
}
function SingleSelect(regex,current)
{
    re = new RegExp(regex);
      for(i = 0; i < document.forms[0].elements.length; i++) 
       { elm = document.forms[0].elements[i];
          if (elm.type == 'checkbox') 
           { if (re.test(elm.name)) 
             { elm.checked = false; }
           }
        }
     current.checked = true;
}
function GoBack() 
{
  history.back(1);
}
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
function showHide()
{ 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        return;
    } 
    var url="/ck1.aspx";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState==4)
        {
            if(xmlHttp.responseText != "")
            {
                document.getElementById("tableWarning").style.display = xmlHttp.responseText;
            }
            else
            {
                document.getElementById("tableWarning").style.display = 'none';
            }
        }
        else
        {
        }
    }
    
    xmlHttp.send(null);
    setTimeout("showHide()",5000);
}
function fInsertValuesFromListbox(oSource, oDes)
{
	var oVariable = window.document.getElementById(oSource);
	if(oVariable != null)
	{
		var oVariable1 = window.document.getElementById(oDes);
		if(oVariable1 != null)
		{
			var myRadEditor = GetRadEditor(oDes);
			var sText = oVariable.options[oVariable.selectedIndex].text;
			myRadEditor.SetFocus();
			myRadEditor.GetSelectionHtml();
			myRadEditor.PasteHtml(sText);
		}
	}
}