// JavaScript Document
function ShowContent()
{
	var content = '';
	var Opid = document.getElementById('packageType').value;
	/*//new Effect.BlindUp('output'); Effect.BlindDown('output', {duration:.3});
	new Effect.BlindUp('output'); 
	window.setTimeout('Effect.BlindDown(\'output\', {duration:.5})',2000);
	//document.getElementById('output').style.visibility = "hidden";*/
	
	switch(Opid)
	{
		case 'FlashSSLGenie':
			
			 content = '<table width="55%" style="margin-left:17px"><tr><td><strong>Select Duration:</strong></td>\
			 			<td width="58%" align="left"><select name="duration" id="duration" size="1">\
  							<option value="1" selected>1 year</option>\
 							<option value="2">2 year</option>\
  							<option value="3">3 year</option>\
  						</select></td></tr></table>';
			document.getElementById('additional').style.visibility = "visible";
		break;
		
		case 'PremiumSSLGenie':
		case 'PremiumSGCSSLGenie':
			content = '<table width="100%" style="margin-left:17px"><tr><td width="23%"><strong>Select Duration</strong></td>\
			 			<td width="15%" align="left"><select name="duration" id="duration" size="1">\
  							<option value="1" selected>1 year</option>\
 							<option value="2">2 year</option>\
  							<option value="3">3 year</option>\
  							<option value="4">4 year</option>\
							<option value="5">5 year</option>\
  							<option value="6">6 year</option>\
  							<option value="7">7 year</option>\
							<option value="8">8 year</option>\
  							<option value="9">9 year</option>\
  							<option value="10">10 year</option>\
						</select></td><td width="30%" align="center"><strong>Enter Warranty</strong></td><td><strong>$</strong>\
						<input type="text" id="warranty" name="warranty" size="6" maxlength="6" value="100000"></td></tr></table>';
			document.getElementById('additional').style.visibility = "visible";
		break;
		
		case 'CodeSigning':
		case 'EmailSigning':
			 content = '<table width="100%" style="margin-left:17px"><tr><td width="22%"><strong>Select Duration</strong></td>\
			 			<td width="15%" align="left"><select name="duration" id="duration" size="1">\
  							<option value="1" selected>1 year</option>\
 							<option value="2">2 year</option>\
  							<option value="3">3 year</option>\
  							<option value="4">4 year</option>\
						</select></td><td width="30%" align="center"><strong>Enter Warranty</strong></td><td><strong>$</strong>\
						<input type="text" id="warranty" name="warranty" size="6" maxlength="6" value="100000"></td></tr></table>';
			document.getElementById('additional').style.visibility = "hidden";
		break;
	}
	document.getElementById('features').innerHTML = content;
	//document.getElementById('output').style.visibility = "visible";
	//new Effect.BlindDown('output'); Effect.Appear('output', {duration:.3});
}

function ShowPackDetails()
{
	var content = '';
	var Opid = document.getElementById('packageType').value;
	document.getElementById('boxa').style.display = "none";	
	document.getElementById('boxb').style.display = "none";	
	document.getElementById('boxc').style.display = "none";	
	document.getElementById('boxd').style.display = "none";	
	
	switch(Opid)
	{
		case 'FlashSSLGenie':
			document.getElementById('boxa').style.display = "block";	
		break;
		
		case 'PremiumSSLGenie':
			document.getElementById('boxb').style.display = "block";	
		break;
		
		case 'PremiumSGCSSLGenie':
			document.getElementById('boxc').style.display = "block";	
		break;
		
		case 'CodeSigning':
		case 'EmailSigning':
			 document.getElementById('boxd').style.display = "block";	
		break;
		
		default:
			document.getElementById('boxa').style.display = "block";	
		break;
	}
}
function ValidateUserDetail()
{
	var cname = document.getElementById('commonName').value;
	var on = document.getElementById('orgName').value;
	var oun = document.getElementById('orgUnitName').value;
	var pbox = document.getElementById('poBox').value;
	var phone = document.getElementById('confirmPhone').value;
	var str1 = document.getElementById('street1').value;
	var loc = document.getElementById('locality').value;
	var state = document.getElementById('state').value;
	var pcode = document.getElementById('pCode').value;
	var cntry = document.getElementById('country').value;
	var dn = document.getElementById('dunsNumber').value;
	var cn = document.getElementById('companyNumber').value;
	var vemail = document.getElementById('validEmail').value;
	var pwd = document.getElementById('upasswd').value;
	var rpwd = document.getElementById('rpasswd').value;
	var error = '';
	if(cname!=""&&str1!=""&&phone!=""&&loc!=""&&state!=""&&pcode!=""&&cntry!=""&&vemail!=""&&pwd!=""&&rpwd!="")
	{
		var strippedPhone = phone.replace(/[\(\)\.\-\ ]/g, '');
	
		if(pwd.length < 6)
		{
			error = "Password cannot be less than 6 characters";
		}
		else if(pwd != rpwd)
		{
			error = "Password Mismatch";
		}
		else if(isNaN(strippedPhone))
		{
			 error = "The phone number contains illegal characters";
		}
		else
		{
			BeforeAtRate = vemail.substring(0,vemail.indexOf("@"));
			AfterAtRate = vemail.substring(vemail.indexOf("@")+1,vemail.length);	
			middle = AfterAtRate.substring(0, AfterAtRate.indexOf("."));
			last = AfterAtRate.substring(AfterAtRate.indexOf(".") + 1,AfterAtRate.length);
			
			if ((vemail.indexOf(" ") >= 0) || (vemail.indexOf("@") == -1) || (vemail.indexOf(".") == -1))
			{
				error = "Incorrect Validation Email";
	      		document.getElementById('validEmail').focus();
			}
			if (BeforeAtRate.length == 0 || middle.length == 0 || last.length == 0)
			{
				error = "Incorrect Validation Email";
				document.getElementById('validEmail').focus();
			}
		}
		
	}
	else
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById('errormsg').innerHTML = "Compulsory Field(s) is/are empty";
		return false;
	}
	if(error != '')
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById('errormsg').innerHTML = error;
		return false;
	}
}

function ValidatePackDetail()
{
	var strippedWarranty = document.getElementById('warranty').value.replace(/[\s\.]/g, '$');
	if(document.getElementById('warranty').value == '')
	{
		document.getElementById('errormsg').innerHTML = "Please enter warranty";
		return false;
	}
	else if(isNaN(strippedWarranty))
	{
		document.getElementById('errormsg').innerHTML = "Warranty Contains Invalid Characters";
		return false;
	}
	else if(document.getElementById('warranty').value < 1000 || document.getElementById('warranty').value > 250000)
	{
		document.getElementById('errormsg').innerHTML = "Warranty should be Between $1000 to $250000";
		return false;
	}
	else
		return true;
}

function validatePassword()
{
	var strOpasswd = document.changep.opasswd.value;
	var strNpasswd = document.changep.npasswd.value;
	var strRNpasswd = document.changep.rnpasswd.value;
	
	if (strOpasswd == "")
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById("errormsg").innerHTML = "Please Enter Old Password";
		document.changep.opasswd.focus();
		return false;
	}
	
	 if (strNpasswd == "")
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById("errormsg").innerHTML = "Please Enter New Password";
		document.changep.opasswd.focus();
		return false;
	}
	
	if(strOpasswd.length < 6)
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById("errormsg").innerHTML = "Old Password Characters less than 6";
		document.changep.opasswd.focus();
	 	return false;
	} 
		
	if(strNpasswd.length < 6)
	{
		document.getElementById('errordiv').style.display = "block";
		document.getElementById("errormsg").innerHTML = "New Password cannot be less than 6 Characters";
		document.changep.opasswd.focus();
 		return false;
	} 
	
	if(strNpasswd != strRNpasswd)
	{
	 	document.getElementById('errordiv').style.display = "block";
		document.getElementById("errormsg").innerHTML = "Password Mismatch";
	 	strNpasswd = strRNpasswd = "";
	 	document.changep.npasswd.focus();
	 	return false;
	}
}

function CalculateAmount(packCost, warrantyCost, sealCost, wildcardCost, sgcCost)
{
	var duration = document.getElementById('duration').value;
	
	var amountbox = document.getElementById('amount');
	//var durationRateDiv = document.getElementById('durationRate');
	var durationCostDiv = document.getElementById('durationCost');
	
	durationcost = duration*packCost;
	

	//durationCostDiv.innerHTML = "$"+ roundNumber(durationcost,2);
	var amount = roundNumber(durationcost,2); 
	//alert(amount);
	amountbox.innerHTML =amount+"&#1585;&#1610;&#1575;&#1604;";
	
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

