var contextPath="/cmint";
var myhccontPath="/myhc-cont";
//This function is to set the auto complete off for the first form
function autocompleteOff(element) {
	self.focus(); //Bring window to foreground if necessary.
	var form = $(element); // grab the form element.
	if(form)
	{
		form.setAttribute("autocomplete","off"); // Turn off Autocomplete for the form, if the browser supports it.
  }
}
//This function is to restrict the character for a given field
function restrictCharacters(object, maxLength)
{
	//Checking whether the element exists on the page
	if($(object))
	{
		//Getting the current value
		var str=$(object).value;
		//Checking the current length with the max length
		if(str.length>maxLength)
		{
			//Trimming the string if text has increased the limit
			$(object).value=str.substring(0,maxLength);
		}
	}
	else return;
}
//Show message for the element
function showMessage(element, message)
{
	//Checking whether div exists or not
	if($(element))
	{
		//Showing the element
		showElement(element);		
		//Assigning the message for the given element
		$(element).innerHTML="<p>"+message+"</p>";
	}
}
//Check the value for the given element
function checkValue(element, value)
{
	//Checking whether div exists or not
	if($(element))
	{
		if(trim($(element).value)==value)
			return true;
	}
	return false;
}
//Sets the value for the given element
function setValue(element, value)
{
	if($(element))
		$(element).value=value;
}
//Sets the index for the given element ... this for the list box and drop downs
function setIndex(element, index)
{
	if($(element))
		$(element).selectedIndex=index;
}
//Hides the element specified
function hideElement(element)
{
	if(document.getElementById(element))
		document.getElementById(element).style.display='none';
}
//Shows the element specified
function showElement(element)
{
	if($(element))
		$(element).style.display='block';		
}
//To show or hide based on the current status
function toggleDisplay(element)
{
  if($(element))
  {
    if($(element).style.display=='none')
    {
      showElement(element);
    }
    else
    {
      hideElement(element);
    }
  }
}
//Common function to add a new item to the drop down or list box
function addElement(element, name, value)
{
	if($(element))
	{
		$(element).options[$(element).options.length]=new Option(name,value);
	}
}
//Common function to check whether the institution, venue, or course exists based on the title
function checkExists(action, countryId, institutionName, institutionId, adminFlag)
{
	var url=contextPath+"/ajaxActions?action="+action+"&countryId="+countryId+"&institutionName="+institutionName+"&institutionId="+institutionId+"&adminFlag="+adminFlag;
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ checkFinish(ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
//String trim function
function trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
//Function to disable the save and cancel buttons
function disableButtons(type,button,place)
{
	if(!submitFlag)
	{
		if(button==1)
		{
			submitFlag=true;
			return true;
		}
		if(type=='I')
		{
      if($("countryId").value=="211" && ($("insfield9")!= null && trim($("insfield9").value)==""))
      {        
        $("insfield9").value="No information available";
      }
			if(trim($("institutionName").value)!="" && institutionName!=trim($("institutionName").value.toUpperCase()))
			{				
        checkInstitutionExists();
				showMessage(place+"msg","<p>Please wait while we are checking the provider already exists in our records.</p>");
				return false;
			} 
      if($("countryId").value=="211"){
       storeDateValues();
      }
      submitFlag=true;
			return true;
		}
		else if(type=='O')
		{
			if(validate())
			{
        submitFlag=true;        
				return true;
			}
			else
			{
				return false;
			}
		}
		else if(type=='V')
		{
			if(validateVenue())
			{
			submitFlag=true;
				return true;
			}
			else
			{
				return false;
			}
		}
		else if(type=='S')
		{
      storeStartDateMonth();
      submitFlag=true;
			return true;
		}
    else if(type=='P')
		{
      $("frmSave").value="YES";
      if(validate())
			{
        if($("awardingbodyId"))
        {
          if($("awardingbodyId").value!="" && $("awardingbodyId").value=="Please enter")
          {          
           $("awardingbodyId").value="";
          }
        }        
        submitFlag=true;
				return true;
			}
			else
			{
				return false;
			}
		}
		return false;
	}
	else
	{
		showMessage(place+"msg","<p>The form has already been submitted. Please wait until it gets submitted.</p>");
		return false;	
	}
}
//Function to get the drop down label for the given index
function getDropDownLabel(element)
{
	if($(element))
	{
		var obj=$(element);
    if(obj[obj.selectedIndex]!=null && obj[obj.selectedIndex]!='undefined'){
		return obj[obj.selectedIndex].firstChild.nodeValue;
    }else{
    return "";
    }
	}
}
//Function to set the default value for the passed object
function setDefaultValue(inputObj)
{
if(inputObj!=null){
	if(inputObj.type == "text")
	{
		inputObj.value="";
	}
	else if((inputObj.type).substr(0, 6) == "select")
	{
		inputObj.selectedIndex=0;
	}
 } 
}
//Common function to show the image while ajax is in progress to fetch the content
function displayAjaxProgressImage(sourceElement, element,pageType)
{
	element=document.getElementById(element);
	sourceElement=document.getElementById(sourceElement);
	if(element)
	{
    var newTop = null;
    element.style.display="block";
		element.style.position="absolute";
    if(sourceElement.id=='venueName' || pageType=='V')
    {
      element.style.zIndex = "1002";
      }else{
      element.style.zIndex = "1000";
      }
		var newLeft=getLeftPosition(sourceElement);
    newTop=getTopPosition(sourceElement);
    element.innerHTML="<div class=\"mhelpbtm\"><p align=\"center\"/><img src=\""+myhccontPath+"/img/drip-circle.gif\" alt=\"\" title=\"\" /><br /><span>Please wait while we load the help information</span></p></div>";
		element.style.left=newLeft-45+"px";
		element.style.top=newTop-element.offsetHeight-20+"px";
		element.scrollTop=0;
	}
}
//Common function to get the help text against the attribute 
function getHelpText(countryId, pageType, attributeId, typeId, sourceElement, element)
{
	var url=contextPath+"/ajaxActions?action=helpText&attributeId="+attributeId+"&typeId="+typeId+"&pageType="+pageType+"&countryId="+countryId;
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ displayHelpPopup(null, sourceElement, element, ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
	displayAjaxProgressImage(sourceElement, element,pageType);
}
//Common function to get the help text against the static fields
function getStaticFieldsHelpText(attributeId, attributeName, sourceElement, element)
{

  var url=contextPath+"/ajaxActions?action=staticFieldsHelpText&id="+attributeId;
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ displayHelpPopup(attributeName, sourceElement, element, ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
	displayAjaxProgressImage(sourceElement, element);
}
//Function do display the help popup
function displayHelpPopup(attributeName, sourceElement, element, ajax)
{
  var countryId="";
  if(document.getElementById("countryId")){
    countryId = document.getElementById("countryId").value;
  }
  element=document.getElementById(element);
	sourceElement=document.getElementById(sourceElement);
	var elementName=element.id;
	if(element)
	{
		var helpText;
		if(attributeName)
		{
			helpText=ajax.response;
		}
		else
		{
			var names=ajax.response.split("~`_~`");
			attributeName=names[0];
			helpText=names[1];
		}
    if(countryId!=null && countryId=="210"){
      element.innerHTML="<div class=\"mhelpbtm\"><a class=\"clse\" onclick=\"javascript:hideElement('"+elementName+"')\"></a><p><strong>Help: "+attributeName+"</strong></p><div class=\"hauto\"><p>"+helpText+"</p></div></div>";
    }else{
   
      element.innerHTML="<div class=\"mhelpbtm\"><a class=\"clse\" onclick=\"javascript:hideElement('"+elementName+"')\"></a><p><strong>Help: "+attributeName+"</strong></p><div class=\"hauto\"><p>"+helpText+"</p></div></div>";
    }
    var newLeft=getLeftPosition(sourceElement);
    newTop=getTopPosition(sourceElement);
		element.style.left=newLeft-45+"px";
		element.style.top=newTop-element.offsetHeight-20+"px";
		element.scrollTop=0;
	}
}
//Function to get the xml node value
function getNodeValue(ajax, element)
{
 var message = ajax.responseXML.getElementsByTagName(element)[0].firstChild.nodeValue;
 return message;
}
//Common function to update the course and venue status
function updateStatus(what, id, status, styleId,fromStatus)
{

  var url;
	if(what=="C")
	{
		url=contextPath+"/ajaxActions?action=courseStatus&courseId="+id+"&status="+status;
	}
	else if(what=="S")
	{
		url=contextPath+"/ajaxActions?action=scholarshipStatus&scholarshipId="+id+"&status="+status;
	}
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onLoading=function(){ $((status=="L"?"live":(status=="A"?"arc":"del"))+styleId).innerHTML='Processing'; };
	ajax.onCompletion = function(){ modifyStatus(what, id, status, styleId, ajax,fromStatus); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
//Function to modify the display data after changing the status
function modifyStatus(what, id, status, styleId, ajax,fromStatus)
{
  if(trim(ajax.response)=="SUCCESS")
	{
		var text=(what=="C")?"course":"scholarship";
		if(status=="L")
		{
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'A','"+styleId+"','"+fromStatus+"')\" title=\"Archive this "+text+"\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'D','"+styleId+"','"+fromStatus+"')\" title=\"Delete this "+text+"\" />Delete";
		}
		else if(status=="A")
		{
    if($("deleteStatusLink"))
		{
			$("deleteStatusLink").style.display='block';
		}
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'L','"+styleId+"','"+fromStatus+"')\" title=\"Make this "+text+" live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is archived\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'D','"+styleId+"','"+fromStatus+"')\" title=\"Delete this "+text+"\" />Delete";
		}
		else if(status=="D")
		{
       if($("deleteStatusLink"))
		{
			$("deleteStatusLink").style.display='block';
		}
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'L','"+styleId+"','"+fromStatus+"')\" title=\"Make this "+text+" live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'A','"+styleId+"','"+fromStatus+"')\" title=\"Archive this "+text+"\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is deleted\" />Delete";
		}
	}else{
    alert(ajax.response);
    var text=(what=="C")?"course":"scholarship";
		if(fromStatus=="LIVE")
		{
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'A','"+styleId+"','"+fromStatus+"')\" title=\"Archive this "+text+"\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'D','"+styleId+"','"+fromStatus+"')\" title=\"Delete this "+text+"\" />Delete";
		}
		else if(fromStatus=="ARCHIVED")
		{
    if($("deleteStatusLink"))
		{
			$("deleteStatusLink").style.display='block';
		}
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'L','"+styleId+"','"+fromStatus+"')\" title=\"Make this "+text+" live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is archived\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'D','"+styleId+"','"+fromStatus+"')\" title=\"Delete this "+text+"\" />Delete";
		}
		else if(fromStatus=="DELETED")
		{
       if($("deleteStatusLink"))
		{
			$("deleteStatusLink").style.display='block';
		}
			if($("live"+styleId))
				$("live"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'L','"+styleId+"','"+fromStatus+"')\" title=\"Make this "+text+" live\" />Live";
			if($("arc"+styleId))
				$("arc"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" onclick=\"updateStatus('"+what+"',"+id+",'A','"+styleId+"','"+fromStatus+"')\" title=\"Archive this "+text+"\" />Archive";
			if($("del"+styleId))
				$("del"+styleId).innerHTML="<input type=\"radio\" name=\"statuscheck"+styleId+"\" checked=\"checked\" title=\"Current status is deleted\" />Delete";
		}
  }
}
function getTopPosition(inputObj)
{	
	var returnValue = inputObj.offsetTop;
	while((inputObj = inputObj.offsetParent) != null){
		returnValue += inputObj.offsetTop;
	}
	return returnValue;
}
function getLeftPosition(inputObj)
{
	var returnValue = inputObj.offsetLeft;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	return returnValue;
}
//Common function to validate the email
function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
	 return true;
}
function $(id){
  return document.getElementById(id);
}
function startsWith(str, starts)
{
  if(str=="" || starts==""){return false;}
  return starts==(str.substring(0,starts.length));
}
function endsWith(str, ends)
{
  if(str=="" || ends==""){return false;}
  return ends==(str.substring(ends.length-1));
}
function courseListURL(se, element, ugurl, pgurl, feurl,eflurl,type,vurl,showURL)
{
  $(element).style.display="block";
  $(element).style.position="absolute";
  var newLeft=getLeftPosition($(se));
  var newTop=getTopPosition($(se))+$(se).offsetHeight;
  $(element).style.left=newLeft+"px";
  $(element).style.top=newTop+"px";
  var urlString = "<ul class=\"common\">";  
  if(type=="view"){
   if(showURL=="efl-fe"){
   urlString = urlString +"<li><a href='"+feurl+"'>View all adult/vocational courses</a></li><li><a href='"+eflurl+"'>View all EFL courses</a></li>";
   }else if(showURL=="efl"){
   urlString = urlString +"<li><a href='"+vurl+"'>View all your courses</a></li><li><a href='"+ugurl+"'>View all undergraduate courses</a></li><li><a href='"+pgurl+"'>View all postgraduate courses</a></li><li><a href='"+feurl+"'>View all adult/vocational courses</a></li><li><a href='"+eflurl+"'>View all EFL courses</a></li>";
   }else if(showURL=="fe"){   
   urlString = urlString +"<li><a href='"+feurl+"'>View all adult/vocational courses</a></li>";
   }else{
   urlString = urlString +"<li><a href='"+vurl+"'>View all your courses</a></li><li><a href='"+ugurl+"'>View all undergraduate courses</a></li><li><a href='"+pgurl+"'>View all postgraduate courses</a></li><li><a href='"+feurl+"'>View all adult/vocational courses</a></li>";
   } 
  }else if(type=="add"){ 
   if(showURL=="efl-fe"){
   urlString = urlString +"<li><a href='"+feurl+"'>Add an adult/vocational course</a></li><li><a href='"+eflurl+"'>Add an EFL course</a></li>";
   }else if(showURL=="efl"){
   urlString = urlString +"<li><a href='"+ugurl+"'>Add an undergraduate course</a></li><li><a href='"+pgurl+"'>Add a postgraduate course</a></li><li><a href='"+feurl+"'>Add an adult/vocational course</a></li><li><a href='"+eflurl+"'>Add an EFL course</a></li>";
   }else if(showURL=="fe"){
   urlString = urlString +"<li><a href='"+feurl+"'>Add an adult/vocational course</a></li>";
   }else{
   urlString = urlString +"<li><a href='"+ugurl+"'>Add an undergraduate course</a></li><li><a href='"+pgurl+"'>Add a postgraduate course</a></li><li><a href='"+feurl+"'>Add an adult/vocational course</a></li>";
   }
  }
  else if(ugurl=="tickerTape")
  {
    urlString = urlString +"<li>URL to Enter e.g</li><li>http://www.google.com OR www.google.com</li>";
  }  
   urlString = urlString +"</ul><p class=\"sright\"><a href=\"javascript:hideElement('"+element+"')\">Close</a></p>";  
  if(type=="view"){
  $(element).innerHTML=urlString; 
  }
  if(type=="add"){
  $(element).innerHTML=urlString;
  }
  if(ugurl=="tickerTape"){
  $(element).innerHTML=urlString;
  }
  $(element).scrollTop=0;
}
function nonUKCourseListURL(se, element,eflurl,othurl,type)
{
  $(element).style.display="block";
  $(element).style.position="absolute";
  var newLeft=getLeftPosition($(se));
  var newTop=getTopPosition($(se))+$(se).offsetHeight;
  $(element).style.left=newLeft+"px";
  $(element).style.top=newTop+"px";
  if(type=="view")
  $(element).innerHTML="<ul class=\"common\"><li><a href='"+eflurl+"'>View all EFL courses</a></li><li><a href='"+othurl+"'>View all other courses</a></li></ul><p class=\"sright\"><a href=\"javascript:hideElement('"+element+"')\">Close</a></p>";
  if(type=="add")
  $(element).innerHTML="<ul class=\"common\"><li><a href='"+eflurl+"'>Add an EFL course</a></li><li><a href='"+othurl+"'>Add other courses</a></li></ul><p class=\"sright\"><a href=\"javascript:hideElement('"+element+"')\">Close</a></p>";
  $(element).scrollTop=0;
}
function replaceAll(OldString,FindString,ReplaceString) {
var SearchIndex = 0;
var NewString = ""; 
while (OldString != null && OldString.indexOf(FindString,SearchIndex) != -1) {
NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
NewString += ReplaceString;
SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length); 
}
if(OldString != null)
NewString += OldString.substring(SearchIndex,OldString.length);
return NewString;}
function convertDates(dateValue)
{
  var tempDate = "";
  var tempMonth = "";
  var tempYear = "";
  var cnvtTempMonth = "";
  tempDate = dateValue.substr(0,2);
  tempMonth = dateValue.substr(3,3);
  var arrayMonth = {"Jan":"01","Feb":"02","Mar":"03","Apr":"04","May":"05","Jun":"06","Jul":"07","Aug":"08","Sep":"09","Oct":"10","Nov":"11","Dec":"12"}; 
  cnvtTempMonth = arrayMonth[tempMonth];
  tempYear = dateValue.substr(7,4);
  return tempDate+"/"+cnvtTempMonth+"/"+"20"+tempYear;
}
function calShowSelectDt(dateSelcted,buttonid,texboxid,countryid,hypFormat,mulipleDateSelect)
{
  var clist = texboxid+"clist";
  var dateSelcted = convertDates(dateSelcted);
  $(clist).style.display="block";
  var temp_buttonid= "temp_"+buttonid;
  $(clist).innerHTML="<div class='mhelpbtms'> <a class='clse' href=\"javascript:hideElement('"+clist+"')\"></a><ul class=\"common\" id=\"ulid\"><li><a href=\"javascript:intiCalender('"+temp_buttonid+"','"+texboxid+"','"+countryid+"','"+hypFormat+"','"+mulipleDateSelect+"','"+dateSelcted+"')\" id='"+temp_buttonid+"'>Edit</a></li><li><a href=\"javascript:deleteDate('"+dateSelcted+"','"+countryid+"','"+texboxid+"')\">Delete</a></li></ul></div>";    
 $(clist).style.display="block";
 $(clist).style.position="absolute";

 var newLeft=getLeftPosition($(texboxid));
 var newTop=getTopPosition($(texboxid))-$(clist).offsetHeight-20;
 $(clist).style.left=newLeft+"px"; 
 $(clist).style.top=newTop+"px";
  var selDate = dateSelcted.split("/"); 
  dateSelcted = selDate[2] + "/" + selDate[1] + "/" + selDate[0];
  //intiCalender(temp_buttonid,texboxid,210,true,true);
  intiCalender(temp_buttonid,texboxid,countryid,hypFormat,mulipleDateSelect,dateSelcted);     // set the button id and textid
}
function deleteDate(dateSelcted,countryid,texboxid)
{
  var clist = texboxid+"clist";
  var children = document.getElementById(texboxid).getElementsByTagName('a'); 
  var newDate = "";
  for(i=0;i<children.length;i++)
  {
    newDate = convertDates(children[i].innerHTML);
    if(newDate==dateSelcted)
    {         
       p2 = children[i];
       p2.parentNode.removeChild(p2);       
    }
  }                                             
  var children = document.getElementById(texboxid).getElementsByTagName('a');                  
  var tempStore=""; 
  var dataStore="";   
  for(i=0;i<children.length;i++)
  {
    if(i==0)
    {
      tempStore = children[i].innerHTML;
    }
    else
    {
      tempStore = tempStore + "," + children[i].innerHTML;
    } 
  } 
  tempStore  = tempStore.replace(",,",", ");    
  if(tempStore!="")
  {       
    var tempStoreSplit  = tempStore.split(",");
    for(i=0;i<tempStoreSplit.length;i++)
    {
      //var dtEvents  = 'onclick="'+ "calShowSelectDt('" + tempStoreSplit[i] + "'," + "'imgtrigger','oppStDate','" + countryid + "','true','true');" + '"';       
      var dtEvents  = "javascript:calShowSelectDt('" + tempStoreSplit[i] + "'," + "'imgtrigger','"+texboxid+"','" + countryid + "','true','true')";       
      
      if(i==0)
      {               
        //dataStore = '<a href="#" ' + dtEvents + ">" + tempStoreSplit[i] + "</a>";        
        dataStore = "<a href="+dtEvents+">" + tempStoreSplit[i] + "</a>";        
      }
      else
      {
        //dataStore = dataStore + ", " + '<a href="#" ' + dtEvents + ">" + tempStoreSplit[i] + "</a>";
        dataStore = dataStore + ", " + "<a href="+dtEvents+">" + tempStoreSplit[i] + "</a>";
      }
    }    
  }  
  $(clist).style.display="none";     
  $(texboxid).innerHTML  = dataStore;    
}
//Month select box....
function oppStartMonth(page)
{   
  if(page=="coursePage")
  {
   $("cclist").style.display="block";      
   $('cclist').style.position="absolute";
   var newLeft=getLeftPosition($('oppStMonthTrig'));
   var newTop=getTopPosition($('oppStMonthTrig'))+$('oppStMonthTrig').offsetHeight;
   $('cclist').style.left=newLeft+"px"; 
   $('cclist').style.top=newTop+"px";  
  }
 else if((page=="findRep")){
  $("cclist").style.display="block";      
   $('cclist').style.position="absolute";
   var newLeft=getLeftPosition($('oppStMonthTrig'));
   var newTop=getTopPosition($('oppStMonthTrig'))+$('oppStMonthTrig').offsetHeight;
   $('cclist').style.left=newLeft+"px"; 
   $('cclist').style.top=newTop+"px";  
 } else if((page=="findRep2")){
  $("cclist2").style.display="block";      
   $('cclist2').style.position="absolute";
   var newLeft=getLeftPosition($('oppStMonthTrig2'));
   var newTop=getTopPosition($('oppStMonthTrig2'))+$('oppStMonthTrig2').offsetHeight;
   $('cclist2').style.left=newLeft+"px"; 
   $('cclist2').style.top=newTop+"px";  
 }else
  {
    $("cclist").style.display="block";   
    var topValue= 0,leftValue= 0;
    leftValue += $("newoppform").offsetLeft + $("oppStMonthTrig").offsetLeft - 10;
    topValue  += $("newoppform").offsetTop + 120;             
  
    $("cclist").style.left=leftValue+"px";
    $("cclist").style.top=topValue+"px";     
  }
}
//month appent to box
function addOppMonth(page)
{ 
  var dispMonth="";  
  var eventMonth  = "";
  var dispMonthVal="";
  var chk="chk";
  
  if(page=="findRep2"){    
  chk="chk2";
    }
  if(page=="coursePage")
  {
  eventMonth  = "javascript:oppStartMonth('coursePage')";
  } else
  {
  eventMonth  = "javascript:oppStartMonth()";
  }   
  for(var i=0;i<15;i++)
  {
    if($(chk+i).checked)
    {      
      if(i==0)
      {    
        dispMonth = "<a href="+eventMonth+">" + $(chk+i).value + "</a>";  
        dispMonthVal=$(chk+i).value;
      }
      else
      {
       if(trim(dispMonth)==""){
          dispMonth = "<a href="+eventMonth+">" + $(chk+i).value + "</a>";
         }else{
          dispMonth = dispMonth + ", " + "<a href="+eventMonth+">" + $(chk+i).value + "</a>";     
         }
        if(trim(dispMonthVal)==""){
          dispMonthVal=$(chk+i).value;
         }else{
          dispMonthVal =dispMonthVal +", "+$(chk+i).value;
        }      
      }          
    }
    if(page=="findRep"){    
    $("field0").value=dispMonthVal;    
    } else if(page=="findRep2"){    
    $("rfield0").value=dispMonthVal;    
    }else{    
    $("oppStMonth").innerHTML = dispMonth;    
    }
  }
}

function deleteAnchor()
{  
  //location.href = "#opphd";
  location.href = "#bottommsg";  
}

function storeStartDateMonth(dateObject,monthObject)
{  
  if($("oppStDate"))
  {
    var children = document.getElementById('oppStDate').getElementsByTagName('a');                  
    var tempStore = "";       
    for(i=0;i<children.length;i++)
    {
      if(i==0)
      {
        tempStore = children[i].innerHTML;
      }
      else
      {
        tempStore = tempStore + ", " + children[i].innerHTML;
      } 
    }    
    tempStore  = tempStore.replace(", , ",", ");    
    //$('insfield7').value = tempStore;    
    $(dateObject).value = tempStore; 
  }  
  if($("schAppDeadDate"))
  {    
    var children = document.getElementById('schAppDeadDate').getElementsByTagName('a');                  
    var tempStore = "";       
    for(i=0;i<children.length;i++)
    {
      if(i==0)
      {
        tempStore = children[i].innerHTML;
      }
      else
      {
        tempStore = tempStore + ", " + children[i].innerHTML;
      } 
    }    
    tempStore  = tempStore.replace(", , ",", ");       
    $('schAppDeadId').value = tempStore;        
  }
  if($("schStDate"))
  {
    var children = $('schStDate').getElementsByTagName('a');
    var tempStore = "";
    for(i=0;i<children.length;i++)
    {
      if(i==0)
      {
        tempStore = children[i].innerHTML;
      }
      else
      {
        tempStore = tempStore + ", " + children[i].innerHTML;
      }
    }
    tempStore = tempStore.replace(", , ",", ");
    $("schStDateVal").value = tempStore;
  }
   if(!$("schMonthId")){
   if($("oppStMonth"))
   {    
     //var oppMonth = $("oppStMonth").innerHTML;     
     var childrenMonth = document.getElementById('oppStMonth').getElementsByTagName('a');                  
     var tempStoreMonth = "";      
     for(i=0;i<childrenMonth.length;i++)
     {
      if(i==0)
      {
        tempStoreMonth = childrenMonth[i].innerHTML;
      }
      else
      {
        tempStoreMonth = tempStoreMonth + ", " + childrenMonth[i].innerHTML;
      } 
     }      
     //$("insfield8").value = tempStoreMonth;          
     $(monthObject).value = tempStoreMonth; 
   }}   
   if($("schMonthId"))
  {    
    var childrenMonth = document.getElementById('oppStMonth').getElementsByTagName('a');                  
     var tempStoreMonth = "";      
     for(i=0;i<childrenMonth.length;i++)
     {
      if(i==0)
      {
        tempStoreMonth = childrenMonth[i].innerHTML;
      }
      else
      {
        tempStoreMonth = tempStoreMonth + ", " + childrenMonth[i].innerHTML;
      } 
     }      
     //$("insfield8").value = tempStoreMonth;          
     $("schMonthId").value = tempStoreMonth;      
  }
}
function scholarMonthDate()
{  
  if($("countryId").value=="114" || $("countryId").value=="9" || $("countryId").value=="168"  || $("countryId").value=="211" || $("countryId").value=="210" ||  $("countryId").value=="134")
  {
 
    if($("applideadline"))
    {
      if($("applideadline").checked==true)
      {      
        $("hideDate").style.display = "block";
        $("hideMonth").style.display = "block";
      }else{     
        $("hideDate").style.display = "none";
        $("hideMonth").style.display = "none";
        $("schAppDeadDate").innerHTML = "";
        $("oppStMonth").innerHTML = "";      
        $("schAppDeadId").value="";
        $("schMonthId").value="";
      }
    }
   } 
}
function scrollTop(element)
{
  element = $(element);
  sc = $('tscroll');
	isc = $('itscroll');
	isc.style.width = element.scrollWidth+'px';
	sc.onscroll= function() {
		element.scrollLeft= sc.scrollLeft;
	};
	element.onscroll= function() {
		sc.scrollLeft= element.scrollLeft;
	};
}
function isURL(url)
{
  var RegExp = /^http(s{0,1}):\/\/[a-zA-Z0-9_/\-\.]+\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\&\?\=\-\.\~\%\+\#\,\;\:\!\@\$\^\(\)]*$/
  if(url.indexOf("?")!=-1)
  {
    url = url.substring(0, url.indexOf("?"));
  }
  if(RegExp.test(url)){
    return true;
  }else{
    return false;
  }
}
// this is to postion the calendar
pageCalCounts =0;
