
function runExcelReport(reportNo,useInterimAndFinal,useFinalOnly,useInvalid,usePending,monthFrom,yearFrom,monthTo,yearTo)
{
  xmlReport=GetXmlHttpObject()
  if (xmlReport==null) { alert ("Your browser does not support AJAX!"); return;}
  //startProcessing('Process_Text');
  //StartProcessing('Process_Text',procNo,fileType);
  var url="build_report.php?reportNo="+reportNo+"&useInterimAndFinal="+useInterimAndFinal+"&useFinalOnly="+useFinalOnly+"&useInvalid="+useInvalid+"&usePending="+usePending+"&monthFrom="+monthFrom+"&yearFrom="+yearFrom+"&monthTo="+monthTo+"&yearTo="+yearTo;
  //alert(url);
  xmlReport.onreadystatechange=function() 
  {
    if (xmlReport.readyState==4)
    {
      var vRandomDate = new Date(); windowname = vRandomDate.getTime();
      var returnMessage = xmlReport.responseText;
      //alert(returnMessage);
      if (returnMessage.search(/Report Cancelled by User!/i)==-1 && returnMessage.search(/Error/i)==-1)
      {
        url2='get_report.php';
        //alert(url2);
        window.open(url2, windowname, 'top=300,left=400,height=150,width=150,location=no,resizable=no,scrollbars=no,status=no');
      }
      else if (returnMessage.search(/Report Cancelled by User!/i)==-1)
        alert(returnMessage.replace("Error",""));
      //StopProcessing();
    }
  }
  xmlReport.open("GET",url,true);
  xmlReport.send(null);

  return true;
}

/*
function StartProcessing(c_Element,procNo,fileType)
{
  i_Count=0;
  var pageObj = document.getElementById(c_Element);
  document.getElementById('pageHolder').disabled=true;
  document.getElementById('popup').style.display='block';
  //Time_Interval = setInterval('if (i_Count == 10){document.getElementById("' + c_Element + '").innerText = "Processing Report"; i_Count = 0; chkProcess("'+procNo+'","'+fileType+'");} else {document.getElementById("' + c_Element + '").innerText = document.getElementById("' + c_Element + '").innerText + "."; i_Count++; }',100);
  Time_Interval = setInterval('if (i_Count == 10){document.getElementById("' + c_Element + '").innerText = "Processing Report"; i_Count = 0; } else {document.getElementById("' + c_Element + '").innerText = document.getElementById("' + c_Element + '").innerText + "."; i_Count++; }',100);
}
*/

function StopProcessing()
{
  document.getElementById('popup').style.display='none';
  document.getElementById('pageHolder').disabled=false;
  Time_Interval = clearInterval(Time_Interval);   
  document.getElementById('Process_Text').innerText = "Processing Report";
}

function stateChanged()
{
  if (xmlHttp.readyState==4)
  {
    //alert(xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", ""));
    document.getElementById('spanResultsArea').innerHTML=xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", "");
  }
}

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 radioSet(checked,otherHalf)
{
  //alert("in");
  otherHalf.checked=(checked==false);
}

function searchAds(monthFrom,yearFrom,monthTo,yearTo,progToCall)
{
  //alert("In");
  //alert(yearFrom+","+monthFrom+","+yearTo+","+monthTo);
  if (progToCall === undefined)
    progToCall = 'clt_archive.php?';
  
  //alert(progToCall);
  var refreshTo = progToCall;
  refreshTo = refreshTo + 'monthFrom='+monthFrom+"&";
  refreshTo = refreshTo + 'yearFrom='+yearFrom+"&";
  refreshTo = refreshTo + 'monthTo='+monthTo+"&";
  refreshTo = refreshTo + 'yearTo='+yearTo;
  window.location = refreshTo;
}

function checkYears(YearToValue,YearFromValue,YearFromElement)
{
	if(YearFromValue > YearToValue)
	{
    var ElementToModify = document.getElementById(YearFromElement);
    ElementToModify.value = YearToValue;
	}
}

function selectAll(thisSelect)
{
  //alert('1');
  //alert('Val1'+thisSelect.value);
  for(var i=0, len=thisSelect.options.length; i<len; i++)
  {
    thisSelect.options[ i ].selected = true;
    //alert(i);
  }
  //alert('Val2'+thisSelect.value);
  return true;
}

function removeFromSelect(thisSelect)
{
  thisSelect.remove(thisSelect.options.selectedIndex);
}

function findInOrAddToSelect(fieldValue,selectName,fieldName)
{
  //alert(fieldValue+","+selectName+","+fieldName);
  selectHandle=document.getElementById(selectName);
  logNotFound=true;
  for (j=0; j<selectHandle.length; j++) 
  { if (selectHandle.options[j].value==fieldValue)
    {
      logNotFound=false;
      selectHandle.options[j].selected=true;
    }
  }
  if(logNotFound==true)
  {  //Value not found in the select's existing list so we have to add new entry into it
    AddRemoveLastInSelect(fieldName,fieldValue,true,selectName);
  }
}

function AddRemoveLastInSelect(NewName,NewValue,AddEntry,SelectName,OptionIndex)
{
  //alert(NewName);
  var SelectToModify = document.getElementById(SelectName);
  //alert("In AddRemove - SelectName "+SelectToModify.name);
  var NewOptionToBeAdded = document.createElement('option');
  NewOptionToBeAdded.text = NewName;
  NewOptionToBeAdded.value = NewValue;
  if (AddEntry==true)
  {
 		try
	  {
	    SelectToModify.add(NewOptionToBeAdded); // IE only
      SelectToModify.selectedIndex = NewOptionToBeAdded.index;
	  }
	  catch(ex)
		{
	    SelectToModify.add(NewOptionToBeAdded, null); // standards compliant; doesn't work in IE
      SelectToModify.selectedIndex = NewOptionToBeAdded.index;
	  }
  }
  else if (SelectToModify.length > 0)
  {
    if (OptionIndex != '')
      SelectToModify.remove(SelectToModify.length - 1);
    else
      SelectToModify.remove(OptionIndex);
  }
}

function dispCodeText(codeNo)
{
  //alert("codeNo:"+codeNo);
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
  var url="get_code.php?code_id="+codeNo;
  //alert(url);
  xmlHttp.onreadystatechange=function() 
  { if (xmlHttp.readyState==4) 
    { 
      responseText=xmlHttp.responseText;
      //alert(responseText);
      if(responseText.search(/Error/i)!=-1)
        alert(responseText);
      else
      {
        //alert(responseText);
        resultsDiv = document.getElementById('resultsArea');
        resultsDiv.innerHTML = "";
        resultsDiv.innerHTML = responseText;
      }
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function printSub(subId)
{
  //alert("Print this Submission? "+subId);
  window.location='print_sub.php';
}

function refreshDate(date)
{
  //alert('admin_home.php?date='+date);
  window.location='admin_home.php?date='+date;
}

function refreshSubs(clientNo,sortBy,urgencyNo)
{
  //alert(clientNo+","+adverNo+","+brandNo+","+sortBy+","+urgencyNo);
  var refreshTo = 'admin_home.php?';
  if(clientNo != 0)
    refreshTo = refreshTo + 'client_id='+clientNo+"&";
  //if(adverNo != 0)
  //  refreshTo = refreshTo + 'adver_id='+adverNo+"&";
  //if(brandNo != 0)
  //  refreshTo = refreshTo + 'brand_id='+brandNo+"&";
  if(sortBy != 0)
    refreshTo = refreshTo + 'sort_by='+sortBy+"&";
  if(urgencyNo != 0 && urgencyNo != undefined)
    refreshTo = refreshTo + 'urgency_id='+urgencyNo;
  window.location = refreshTo;
}

/*function refreshSubs(clientNo,adverNo,brandNo,sortBy,urgencyNo)
{
  //alert(clientNo+","+adverNo+","+brandNo+","+sortBy+","+urgencyNo);
  var refreshTo = 'admin_home.php?';
  if(clientNo != 0)
    refreshTo = refreshTo + 'client_id='+clientNo+"&";
  if(adverNo != 0)
    refreshTo = refreshTo + 'adver_id='+adverNo+"&";
  if(brandNo != 0)
    refreshTo = refreshTo + 'brand_id='+brandNo+"&";
  if(sortBy != 0)
    refreshTo = refreshTo + 'sort_by='+sortBy+"&";
  if(urgencyNo != 0 && urgencyNo != undefined)
    refreshTo = refreshTo + 'urgency_id='+urgencyNo;
  window.location = refreshTo;
}
*/

function startProcessing(c_Element)
{
  i_Count = 0;
  //for(var i=0;i<document.forms['sub_form'].elements.length;i++)
  //{
  // 	document.forms['sub_form'].elements[i].disabled=true;
  //}
  document.getElementById('btnSave').disabled=true;
  document.getElementById('popup').style.display='block';
  resultsDiv = document.getElementById('Process_Text');
  Time_Interval = setInterval('if (i_Count == 10){resultsDiv.innerHTML = "Uploading Submission - please wait"; i_Count = 0; } else {resultsDiv.innerHTML = resultsDiv.innerHTML + "."; i_Count++; }',100);
  return true;
}

function StopProcessing()
{
  document.getElementById('popup').style.display='none';
  document.getElementById('pageHolder').disabled=false;
  Time_Interval = clearInterval(Time_Interval);   
  document.getElementById('Process_Text').innerText = "Processing Report";
}

function refreshAd(adverNo,brandNo)
{
  if(adverNo != 0)
    window.location='disp_ad.php?adver_id='+adverNo;
  else if(brandNo != 0)
    window.location='disp_ad.php?brand_id='+brandNo;
}

function chkDeleteUser(userNo,userName)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this User "+userName+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_user.php?user_id="+userNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText;
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='admin_users.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function chkDeleteNews(newsNo,newsName)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this News Item "+newsName+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_news.php?news_id="+newsNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText;
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='disp_news_list.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function chkDeleteCamp(campaignNo,campaignName)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this Campaign "+campaignName+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_camp.php?camp_id="+campaignNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText;
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='disp_camps.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function chkDeleteBrand(brandNo,brandName)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this brand "+brandName+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_brand.php?brand_id="+brandNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText;
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='disp_brands.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function chkDeleteAdver(adverNo,adverName)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this Advertiser "+adverName+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_adver.php?adver_id="+adverNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText;
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='disp_advers.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function editClient(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_clients.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    { 
      document.getElementById('#Name').disabled=false;
      document.getElementById('#Contact').disabled=false;
      document.getElementById('#Phone').disabled=false;
      document.getElementById('client_active_yes').disabled=false;
      document.getElementById('client_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editCode(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_code_list.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    {
      document.getElementById('Sort Order').disabled=false;
      document.getElementById('#Ref').disabled=false;
      document.getElementById('#Code Body').disabled=false;
      document.getElementById('code_active_yes').disabled=false;
      document.getElementById('code_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editCategory(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_categories.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    {
      document.getElementById('Sort Order').disabled=false;
      document.getElementById('#Category Name').disabled=false;
      document.getElementById('category_active_yes').disabled=false;
      document.getElementById('category_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editNews(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_news_list.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    {
      document.getElementById('#Title').disabled=false;
      document.getElementById('#News Body').disabled=false;
      document.getElementById('news_live_yes').disabled=false;
      document.getElementById('news_live_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editCamp(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_camps.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    { 
      document.getElementById('#Name').disabled=false;
      document.getElementById('Contact').disabled=false;
      document.getElementById('campaign_active_yes').disabled=false;
      document.getElementById('campaign_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editAdver(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_advers.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      /*document.getElementById('#Name').disabled=true;
      document.getElementById('Contact').disabled=true;
      document.getElementById('ad_active_yes').disabled=true;
      document.getElementById('ad_active_no').disabled=true;
      document.getElementById('btnSave').disabled=true;
      btnEdit.value="Edit";*/
      window.location.reload();
    }
    else
    { 
      document.getElementById('#Name').disabled=false;
      //document.getElementById('Contact').disabled=false;
      document.getElementById('adver_active_yes').disabled=false;
      document.getElementById('adver_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function editBrand(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "disp_brands.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      window.location.reload();
    }
    else
    { 
      document.getElementById('#Name').disabled=false;
      //document.getElementById('Contact').disabled=false;
      document.getElementById('#Category').disabled=false;
      document.getElementById('brand_active_yes').disabled=false;
      document.getElementById('brand_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function chkDelete(subNo,subTitle,adNo)
{
  //alert(subNo+","+subTitle+","+adNo);
  var okToDelete = confirm("Are you sure that you want to DELETE this Submission "+subTitle+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_sub.php?sub_id="+subNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", "");
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert("Error: "+responseText);
        else
        {
          alert(responseText);
          window.location='disp_ad_subs.php?ad_id='+adNo;
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function chkDeleteAd(adNo,adTitle)
{
  //alert(adNo+","+adTitle);
  var okToDelete = confirm("Are you sure that you want to DELETE this Ad "+adTitle+" ?");
  if (okToDelete==true)
  {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
    var url="del_ad.php?ad_id="+adNo;
    //alert(url);
    xmlHttp.onreadystatechange=function() 
    { if (xmlHttp.readyState==4) 
      { 
        responseText=xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", "");
        //alert(responseText);
        if(responseText.search(/Error/i)!=-1)
          alert(responseText);
        else
        {
          alert(responseText);
          window.location='client_home.php';
        }
      }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
  else
    return false;
}

function savePrice()
{
  logEditing=document.getElementById('logEditingPrice').value;
  priceNo=document.getElementById('ItemPriceNo').value;
  stockNo=document.getElementById('StockListNo').value;
  clientNo=document.getElementById('selectedNo').value;
  priceValue=document.getElementById('ClientsSalePrice').value;
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return;}
  var url="savePrice.p?editing="+logEditing+"&pNo="+priceNo+"&pValue="+priceValue+"&pStockNo="+stockNo+"&pClientNo="+clientNo;
  //alert(url);
  xmlHttp.onreadystatechange=function() 
  { if (xmlHttp.readyState==4) 
    { 
      responseText=xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", "");
      //alert(responseText);
      if(responseText.search(/Error/i)!=-1)
        alert("Error: "+responseText);
      else
      {
        //returnArray=responseText.split("||");
        //displayPrice(returnArray[1],null);
        cancelPrice();
        
      }
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function enableFields(fieldList, clicked)
{
  fieldList = fieldList.split(",");
  for(i=0;i<fieldList.length;i++)
  {
    formObj = document.getElementsByName(fieldList[i]);
    if(clicked)
    {
      for(j=0;j<formObj.length;j++)
      {
        formObj[j].disabled = false;
        formObj[j].readOnly = false;
      }
    }
    else
    {
      for(j=0;j<formObj.length;j++)
      {
        formObj[j].disabled = true;
      }
    }
  }
  document.getElementById('btnEdit').disabled=true; 
  document.getElementById('btnCancel').disabled=false; 
  document.getElementById('btnSave').disabled=false;
  document.getElementById('btnDelete').disabled=true;
}

function rewriteLabel(selectHandle,selectIndex)
{
  var newHeader ="<h3 style='margin:0px 0px 10px 20px;'>You can upload up to 10 files for this Medium '";
  newHeader = newHeader+ selectHandle[selectIndex].text;
  newHeader = newHeader+"' using the fields below...</h3>";
  //alert(newHeader);
  document.getElementById('files_header').innerHTML=newHeader;
}

function editAd(btnEdit,logNew)
{
  if(logNew)
  {
    window.location = "client_home.php";
  }
  else
  {
    if(btnEdit.value=="Cancel")
    {
      document.getElementById('#Title').disabled=true;
      document.getElementById('#Contact').disabled=true;
      document.getElementById('ad_active_yes').disabled=true;
      document.getElementById('ad_active_no').disabled=true;
      document.getElementById('btnSave').disabled=true;
      btnEdit.value="Edit";
    }
    else
    { 
      document.getElementById('#Title').disabled=false;
      document.getElementById('#Contact').disabled=false;
      document.getElementById('ad_active_yes').disabled=false;
      document.getElementById('ad_active_no').disabled=false;
      document.getElementById('btnSave').disabled=false;
      btnEdit.value="Cancel";
    }
  }
}

function is_odd( $int )
{
  return( $int & 1 );
}

function changeRowColour(tableRow,highlight,highlightColour,returnColour)
{
  //alert("'"+highlightColour+"','"+returnColour+"'");
  if (highlight==1)
  {
    if (highlightColour != '')
      tableRow.bgColor=highlightColour;
    else
      tableRow.bgColor='#E0EEEE';
      //tableRow.bgColor='lightsteelblue';
  }
  else
  {
    if (returnColour != '')
      tableRow.bgColor=returnColour;
    else
      tableRow.bgColor='#f5f2ec';
  }
  //alert(tableRow.bgColor);
}

function changeLabel(labelId,labelValue)
{
  label=document.getElementById(labelId);
  label.innerHTML='<p>'+labelValue+'</p>';
  document.getElementById('#Agency Name').focus();
}

function setURL(userNo,websiteNo,rootDir,designNo,amountValue,promoCode)
{
  //newURL="http://ntserver/ourbigday/create_success.php?";
  //newURL="http://www.ourbigday.ie/payment_success.php?";
  newURL="http://"+rootDir+"pay_success.php?";
  newURL=newURL+"user_id="+userNo+"&";
  newURL=newURL+"website_id="+websiteNo+"&";
  //newURL=newURL+"design_id="+designNo+"&";
  newURL=newURL+"package_id="+Math.round(amountValue/150)+"&";
  newURL=newURL+"payment_id="+amountValue;
  document.getElementById('return').value=newURL;
  document.getElementById('amount').value=amountValue;
  //document.getElementById('amount').value=5;
  //alert(newURL);
  //window.location = newURL;
  if(promoCode!="")
  {
    //alert(promoCode);
    //if(promoCode=="")
    //{
    //  alert("You've entered a valid Promo Code, you will now be redirected.");
    //  window.location = newURL;
    //  return false;
    //}
    //else
    //{
      alert("You've entered an invalid Promo Code, please try again or leave blank to proceed.");
      return false;
    //}
  }
  //alert(newURL);
  //return false;
  return true;
}

function selectPackage(loggedIn,packageNo,packagePrice)
{
  //alert(loggedIn+"-"+packageNo);
  if(loggedIn==false)
  {
    alert("You must be logged in before selecting a Package!");
    window.location = "login.php";
    return false;
  }
  if(packageNo=="3")
    window.location = "contact_us.php?package_no="+packageNo;
  else if(packageNo!="0")
    window.location = "create_site.php?package_no="+packageNo+"&package_price="+packagePrice;
}

function selectDesign(loggedIn,designNo)
{
  //alert(loggedIn+"-"+designNo);
  if(loggedIn==false)
  {
    alert("You must be logged in before selecting a Design!");
    window.location = "login.php"
    return false;
  }
  if(designNo!="0")
    window.location = "create_site.php?design_no="+designNo;
}

function checkSelections(loggedIn,websiteNo,designNo,packageNo)
{
  //alert(loggedIn+"-"+websiteNo+"-"+designNo+"-"+packageNo);
  if(loggedIn!="1")
  {
    alert("You must be logged in before proceeding to payment!");
    window.location = "login.php"
    return false;
  }
  if(designNo=="0")
  {
    alert("You must select a design before proceeding to payment!");
    return false;
  }
  if(websiteNo=="")
  {
    alert("You must view your sample site before proceeding to payment!");
    //window.location = "login.php"
    return false;
  }
  if(packageNo=="0")
  {
    alert("You must select a package before proceeding to payment!");
    return false;
  }
  return true;
  //return false;
}

function displayDate(dateToShow)
{
  //Take the time elemment off the end of the datetime string
  dateArray=dateToShow.substring(0,10);
  //Split into array deimited by the "-" character
  dateArray=dateArray.split("-");
  document.getElementById('wedding_year').value=dateArray[0];
  document.getElementById('wedding_month').value= parseInt(dateArray[1]);
  document.getElementById('wedding_day').value=parseInt(dateArray[2]);
}

function validateEmail(email_string,email_field) 
{
  if(email_field=='')
    email_field='email_address';
	var at="@";
	var dot=".";
	var lat=email_string.indexOf(at);
	var lstr=email_string.length;
	var ldot=email_string.indexOf(dot);
	var afterDot = email_string.substring((ldot+1),email_string.length);
  var lAfterDot = afterDot.length;
	if (
       (email_string.indexOf(at)==-1)||
       (email_string.indexOf(at)==-1 || email_string.indexOf(at)==0 || email_string.indexOf(at)==lstr)||
       (email_string.indexOf(dot)==-1 || email_string.indexOf(dot)==0 || email_string.indexOf(dot)==lstr)||
       (email_string.indexOf(at,(lat+1))!=-1)||
       (email_string.substring(lat-1,lat)==dot || email_string.substring(lat+1,lat+2)==dot)||
       (email_string.indexOf(dot,(lat+2))==-1)||
       (email_string.indexOf(" ")!=-1)||
       (lAfterDot<2)
     )
    {
	    alert("Invalid E-mail address!");
	    return false;
      document.getElementsByName(email_field)[0].focus();
	  }
  return true					
}

function validateFields(emailField)
{
  if(
      validateEmail(document.getElementsByName(emailField)[0].value) && 
      validatePasswords()
    )
    return true;
  else
    return false;
}

function validateDate(dayValue,monthValue,yearValue,alertMessage)
{
  dateString = yearValue+"-"+monthValue+"-"+dayValue;
  dayValue   = parseInt(dayValue);
  monthValue = parseInt(monthValue);
  yearValue  = parseInt(yearValue);
  
  todaysDate = new Date(); 
  todaysDate.setHours(0,0,0,0);
  
  var givenDate = new Date(yearValue,monthValue-1,dayValue);
	if((dayValue == givenDate.getDate()) && (monthValue-1 == givenDate.getMonth()) && (yearValue == givenDate.getFullYear()))
	{
	  if (givenDate<=todaysDate) 
    { 
  	  alert("Date selected must be in the future!");
      return false; 
    }    
    document.getElementsByName('wedding_date')[0].value=dateString;
    return true;
  }
	else
	{
	  alert(alertMessage);
	  return false;
	}
}

function chkDuplicates()
{     
  for(var i=1;i<2;i++)
  {       	    	
    fieldName = "file"+i;
    fieldHandle = document.getElementsByName(fieldName)[0];
    if(fieldHandle.value!="")
    {
      for(var j=i+1;j<11;j++)
      {       	 
        fieldNames = "file"+j;
        //alert(fieldHandle.value+":"+document.getElementsByName(fieldNames)[0].value);   	
        if(fieldHandle.value == document.getElementsByName(fieldNames)[0].value)
        {
          alert("Duplicate Filenames..."+fieldHandle.value+"...please Reselect!");
          document.getElementsByName(fieldNames)[0].focus();
          return false;
        }
      }
    }
  }
  return true;
}

function checkApprovalMatches(thisForm)
{
  approvalSought = document.getElementById('approval_sought').value;
  approvalGiven  = document.getElementById('approval_status').value;
  if(approvalSought=="Final Approval" && approvalGiven=="Interim Approval")
    return confirm("This Submission seeks Final Approval but you are awarding it Interim Approval are you sure you wish to proceed?");
  else if(approvalSought=="Interim Approval" && approvalGiven=="Final Approval")
    return confirm("This Submission seeks Interim Approval but you are awarding it Final Approval are you sure you wish to proceed?");
  else
    return true;    
}

function checkRequiredFields(thisForm)
{            
  var thisMessage="";
  var fieldList="";
  for(var i=0;i<thisForm.elements.length;i++)
  {       	    	
    var field = thisForm.elements[i];
    var firstField;
    //alert(field.type+"-"+field.id);
    //if(field.type!="submit"/*&&field.type!="select"*/)
    //  fieldList=fieldList+field.name+",";
    if(field.type=="checkbox")
      if(field.checked) field.value=1; else field.value=0;
    field.style.backgroundColor = "white";
    if (field.id.search(/##/)!=-1 && field.checked==false) 
    { //If its got a ## in its name then its a required field and a checkbox
      thisMessage=thisMessage+"You must accept the '"+field.id.replace("##","")+"' before proceeding!\n";
      field.style.backgroundColor = "pink";
      if(firstField==null) firstField=field;
    }
    else if (field.id.search(/##/)==-1 && field.id.search(/#/)!=-1 && field.value=="" /*&& i<100*/) 
    { //If its got a # in its name then its a required field
      thisMessage=thisMessage+"'"+field.id.replace("#","")+"' is a required field and must not be left blank!\n";
      field.style.backgroundColor = "pink";
      if(firstField==null) firstField=field;
    }
  } 
  if(thisMessage!="")
  {
    alert(thisMessage);
    firstField.focus();
    return false;
  }
  //Build a field list for use in Update Prog
  //thisForm.fieldList.value=fieldList.substring(0,fieldList.length-1);
  //alert(thisForm.fieldList.value);
  return true; 
}

function validatePasswords()
{
  newPass1=document.getElementsByName('password')[0];
  newPass2=document.getElementsByName('password2')[0];
  if(newPass1.value!=newPass2.value)
  {
    alert("You must enter the same password twice!");
    newPass1.value='';
    newPass1.style.backgroundColor = "pink";
    newPass2.value='';
    newPass2.style.backgroundColor = "pink";
    newPass1.focus();
    return false;
  }
  return true;
}

function getThisYear()
{
  var d = new Date();
  var thisYear = "";
  try
  {
    thisYear = d.getUTCFullYear();
  }
  catch(err)
  {
    alert(err.description );
  }
  if(thisYear == "")
    thisYear == "2008";
  return thisYear;
}

function blankField(field,value,field2,value2)
{
	if (field.value == value)
    field.value = "";
  if (field2.value == "")
      field2.value = value2;
}

function stateChanged()
{
  if (xmlHttp.readyState==4)
  {
    //alert(xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", ""));
    document.getElementById('spanResultsArea').innerHTML=xmlHttp.responseText.replace("<!-- Generated by Webspeed: http://www.webspeed.com/, http://www.possenet.org/ -->", "");
  }
}

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;
}

