function quickLinks(strLocation)
{
	window.location = strLocation;
}


function swapImage(imageSrc,imageName)
{
	var newSwapImage = new Image();
	newSwapImage.src = imageSrc;
	eval('document.images.' + imageName + '.src = newSwapImage.src;');
}


function openPopup(strLocation)
{
	window.open(strLocation, 'Citadon', 'height=650,width=550,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no');
}

function popDemo(URL)
{
		demo = window.open(URL,'demo','toolbar=no,location=no,scrolling=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=960,height=576,copyhistory=0,screenX=0,screenY=0,top=0,left=0');
}

function popPNet(URL) {
		projectnet = window.open(URL,'projectnet','toolbar=no,location=no,scrolling=no,directories=no,status=yes,menubar=1,scrollbars=no,resizable=yes,width=600,height=400,copyhistory=0,screenX=100,screenY=10,top=140,left=212');
	}

function cwWacLogin()
	{
	var LoginWin=window.open("http://citadoncw.citadon.com/tce?ClientType=Thin","","left=" + (screen.width-372)/2 + ",top=" + (screen.height-251)/2 + ",width=372,height=251");
	}

function steWacLogin()
	{
	var LoginWin=window.open("http://citadoncw.citadon.com/tce?ClientType=ThinSTE","","left=" + (screen.width-372)/2 + ",top=" + (screen.height-251)/2 + ",width=372,height=251,scrollbars=1,toolbar=1,menubar=1,location=1");
	}

function popThis(URL) {
	if (navigator.appVersion.indexOf("Macintosh") != -1) {
contextPop = window.open(URL,'contextPop','toolbar=no,location=no,scrolling=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=350,height=170,status=0,copyhistory=0,screenX=100,screenY=10,top=250,left=300');
	} else {
contextPop = window.open(URL,'contextPop','toolbar=no,location=no,scrolling=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=350,height=170,status=0,copyhistory=0,screenX=100,screenY=10,top=250,left=300');
	}
}

function popSolutions(strLocation)
{
	window.open(strLocation, 'Citadon', 'height=600,width=750,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=no');
}

function validEmail(email) 
{
	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}


function submitIt(sales_form) 
{

	if (sales_form.salutation.value == "") {
		alert("Please enter your salutation.")
		sales_form.salutation.focus()
		return false
	}

	if (sales_form.first_name.value == "") {
		alert("Please enter your first name.")
		sales_form.first_name.focus()
		return false
	}

	if (sales_form.last_name.value == "") {
		alert("Please enter your last name.")
		sales_form.last_name.focus()
		return false
	}

	if (sales_form.title.value == "") {
		alert("Please enter your title.")
		sales_form.title.focus()
		return false
	}

	if (sales_form.company.value == "") {
		alert("Please enter your company name.")
		sales_form.company.focus()
		return false
	}

	if (sales_form.industry.value == "") {
		alert("Please select your industry.")
		sales_form.industry.focus()
		return false
	}

	if (sales_form.lead_source.value == "") {
		alert("Please select how you heard about us.")
		sales_form.lead_source.focus()
		return false
	}

	if (sales_form.description.value == "") {
		alert("Please enter your question or request.")
		sales_form.description.focus()
		return false
	}

	if (!validEmail(sales_form.email.value)) {
		alert("Please enter a valid E-MAIL address.")
		sales_form.email.focus()
		sales_form.email.select()
		return false
	}

	if (sales_form.phone.value == "") {
		alert("Please enter a number where you can be reached.")
		sales_form.phone.focus()
		return false
	}

	if (sales_form.street.value == "") {
		alert("Please enter your address.")
		sales_form.street.focus()
		return false
	}

	if (sales_form.city.value == "") {
		alert("Please enter your city.")
		sales_form.city.focus()
		return false
	}

	if (sales_form.state.value == "") {
		alert("Please enter your state.")
		sales_form.state.focus()
		return false
	}

	if (sales_form.zip.value == "") {
		alert("Please enter your ZIP code.")
		sales_form.zip.focus()
		return false
	}

	if (sales_form.country.value == "") {
		alert("Please enter your country.")
		sales_form.country.focus()
		return false
	}

	return true

}

function submitSupport(contact_support) {

	if (contact_support.name.value == "") {
		alert("Please enter your contact name.")
		contact_support.name.focus()
		return false
	}

	if (!validEmail(contact_support.email.value)) {
		alert("Please enter a valid e-mail address.")
		contact_support.email.focus()
		contact_support.email.select()
		return false
	}

	if (contact_support.company.value == "") {
		alert("Please enter your Company Name or Organization ID.")
		contact_support.company.focus()
		return false
	}

	if (contact_support["00N00000006p2lV"].value == "") {
		alert("Please select the product you are using.")
		contact_support["00N00000006p2lV"].focus()
		return false
	}

	if (contact_support.priority.value == "") {
		alert("Please tell us the priority of your problem.")
		contact_support.priority.focus()
		return false
	}

	if (contact_support.subject.value == "") {
		alert("Please enter the subject of your request.")
		contact_support.subject.focus()
		return false
	}

	if (contact_support.description.value == "") {
		alert("Please fill out the DESCRIPTION of what problem you had with Citadon CW.")
		contact_support.description.focus()
		return false
	}

	return true

}


function Registration()
{
	var LoginWin=window.open("http://www.citadon.com/resources/register.htm","","left=" + (screen.width-708)/2 + ",top=" + (screen.height-600)/2 + ",width=708,height=600,scrollbars=yes,toolbar=no,location=no,scrolling=yes,status=yes,menubar=no,resizeable=yes");
}


function isANumber(number) 
{
	  answer = 1;
	  if (!parseFloat(number)) {
    //the first digit wasn't numeric
    	answer = 0;
	  } else {
    //the first digit was numeric, so check the rest
    	for (var i=0; i<number.length; i++) {
	      if ((number.charAt(i) != "0")
    		&& (!parseFloat(number.charAt(i)))) {
	          answer = 0;
    	      break;
      		}
    	}
  }
  if (answer == 1) {
    orderPlaced = true;
  }
  return answer;
} 


function isAPhoneNumber(entry) 
{
  //don't bother validating the pattern if
  //no value was passed in
  if (entry) {
    //parse the value into small subsections
    var openParen = entry.substring(0,1);
    var areaCode = entry.substring(1,4);
    var closeParen = entry.substring(4,5);
    var exchange = entry.substring(5,8);
    var dash = entry.substring(8,9);
    var line = entry.substring(9,13);
    //now check each of the subsections
    //individually
    if ((openParen != "(")
      || (!isANumber(areaCode,
"phone number - area code"))
      || (closeParen != ")")
      || (!isANumber(exchange,
"phone number - exchange"))
      || (dash != "-")
      || (!isANumber(line,
"phone number - line")))
		{
			alert("Please enter a phone number in the following format: (123)456-7890.");
			return false
		}
  	}
	return true
}


function submitTrial(regForm) 
{
	if (regForm.first_name.value == "") {
		alert("Please enter your First Name.")
		regForm.first_name.focus()
		return false
	}
			
	if (regForm.last_name.value == "") {
		alert("Please enter your Last Name.")
		regForm.last_name.focus()
		return false
	}
			
	if (!validEmail(regForm.email.value)) {
		alert("Please enter a valid E-MAIL address.")
		regForm.email.focus()
		regForm.email.select()
		return false
	}
			
	if ( document.regForm.login_id.value.length < 6 )
    {
    	alert("\nUser Login ID must be minimum of 6 characters.\n\nPlease re-enter the Login ID.")
		regForm.login_id.focus()
		return false
	}
																			
	if ( document.regForm.login_id.value.length > 36 )
    {
    	alert("\nUser Login ID must be maximum of 36 characters.\n\nPlease re-enter the Login ID.")
		regForm.login_id.focus()
		return false
	}
			
	if ( !validate_userID(document.regForm.login_id.value))
	{
		alert("Login ID can only contain the following special characters: -  _  .\n\nPlease re-enter the Login Name")
		regForm.login_id.focus()
		return false
	}

	if (regForm.company.value == "") {
		alert("Please enter your Organization name.")
		regForm.company.focus()
		return false
	}
			
	if (regForm.phone.value.length < 10) {
		alert("Please enter your phone number with area code. (Example: 123-456-7890)")
		regForm.phone.focus()
		return false
	}

	if (regForm.address.value == "") {
		alert("Please enter your Business Address.")
		regForm.address.focus()
		return false
	}

	if (regForm.city.value == "") {
		alert("Please enter your City.")
		regForm.city.focus()
		return false
	}

	if (regForm.state.value == "") {
		alert("Please enter your State.")
		regForm.state.focus()
		return false
	}
			
	if (regForm.country.value == "") {
		alert("Please enter your Country/Region.")
		regForm.country.focus()
		return false
	}
			
	if (regForm.zip.value == "") {
		alert("Please enter your Postal/Zip code.")
		regForm.zip.focus()
		return false
	}
			
	if (regForm.lead_source.value == "") {
		alert("Please select how you heard about us.")
		regForm.lead_source.focus()
		return false
	}
			
	if (regForm.terms_of_service.checked == false) {
		alert("You must agree to the Terms of Service before continuing with the Registration.")
		regForm.terms_of_service.focus()
		return false
	}

	if (regForm.project_name.value == "") {
		alert("Please enter your Project Name.")
		regForm.project_name.focus()
		return false
	}
			
	if (regForm.email_1.value != "") {
		if (!validEmail(regForm.email_1.value)) {
			alert("Please enter a valid E-MAIL address.")
			regForm.email_1.focus()
			regForm.email_1.select()
			return false
			}
	}
			
	if (regForm.email_2.value != "") {
		if (!validEmail(regForm.email_2.value)) {
			alert("Please enter a valid E-MAIL address.")
			regForm.email_2.focus()
			regForm.email_2.select()
			return false
			}
	}

	if (regForm.email_3.value != "") {
		if (!validEmail(regForm.email_3.value)) {
			alert("Please enter a valid E-MAIL address.")
			regForm.email_3.focus()
			regForm.email_3.select()
			return false
			}
	}

	if (regForm.email_4.value != "") {
		if (!validEmail(regForm.email_4.value)) {
			alert("Please enter a valid E-MAIL address.")
			regForm.email_4.focus()
			regForm.email_4.select()
			return false
			}
	}

	return true
	
}


var Reg = "/\\[]:;|!=,+*?><#@$%^&~"


function Invalid_name(urstr)
{
	// validate user name, must be in alphanumeric value
	var i;
	var result;
	var nallowedchar = Reg;

	for (i=0; i<urstr.length; i++)
	{
		if (nallowedchar.indexOf(urstr.charAt(i)) > 0)
		{
				result = true;
		}
		else if(urstr.charAt(i) == '/')
		{
			result = true;
		}
		else if(urstr.charAt(i) == '"')
		{
			result = true;
		}
	}
	if (result == true)
	return true;
}


function isBlank(elem)
{
	if (!elem.value)
		return true;
	else
	{
		var str = elem.value;
		for (var i = 0; i < str.length; i++)
			{
				var ch = str.charAt(i)
				if ((ch != ' ') && (ch != '\n') && (ch != '\t'))
				return false;
			}
		return true;
	}
}


function validate_userID(urstr)
{
	var CharsReg = "0123456789abcdefghijklmnopqrstuvwxyz-_."
	// validate user name, must be in alphanumeric value
	var i;
	var result;
	var allowedchar = CharsReg;

	for (i=0; i<urstr.length; i++)
	{
		if (allowedchar.indexOf(urstr.charAt(i).toLowerCase()) < 0)
			return false;
		else
			result = true;
	}
	if (result == true)
		return true;
}


function  Replace_Invalid_Char(nameString)
{
	var InputName = '';
	var digits="0123456789";
	var str = nameString

	for (var i = 0; i < str.length; i++)
		{
			var ch = str.substring(i, i + 1);
			if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (digits.indexOf(ch) == -1))
				{
					if(ch =="-" || ch=="_")
						{
							InputName=InputName+ch
						}
				}
			else
			{
				InputName=InputName+ch
			}
		}
	return InputName;
}


function ProcessLoginID()
{
	var fstr
	var lstr
	var usr

	if(isBlank(document.regForm.first_name))
	{
		//alert('Please enter First Name')
		document.regForm.first_name.focus()
		alert('Please enter First Name')
		return false;
	}

	else if(isBlank(document.regForm.last_name))
	{
		//alert('Please enter Last Name')
		document.regForm.last_name.focus()
		alert('Please enter Last Name')
		return false;
	}

	else if ( Invalid_name(document.regForm.first_name.value))
	{
		alert('The First Name contains invalid character\n\n  [/\\[]:;|!=,+*?><#@$%^&~"]\n\nPlease re-enter Fist name')
		document.regForm.first_name.focus()
		document.regForm.first_name.select()
		return false;
	}

	else if ( Invalid_name(document.regForm.last_name.value))
	{
		alert('The Last Name contains invalid character\n\n  [/\\[]:;|!=,+*?><#@$%^&~"]\n\nPlease re-enter Last name')
		document.regForm.last_name.focus()
		document.regForm.last_name.select()
		return false;
	}
																			
	else
	{
		fstr = document.regForm.first_name.value
		for (var i = 0; i < 1; i++)
			{
				var fch = fstr.charAt(i)
			}
		lstr =  document.regForm.last_name.value
		usr = document.regForm.last_name.value.substring(0,24)
		document.regForm.login_id.value = fch+usr;
		document.regForm.login_id.value = document.regForm.login_id.value.toLowerCase()
		document.regForm.login_id.value = Replace_Invalid_Char(document.regForm.login_id.value.toLowerCase())
		document.regForm.login_id.value = document.regForm.login_id.value.substring(0,24)
		return true;
	}
	return false;
}
