/*For adding - in the phone numbers */
var mandatoryLen = 12;
var SSNmandatoryLen = 11;
var allowableChars  = new Array([4,45],[8,45],[13,120],[13,88]);
                function isNum(event,dotreq) {
                    var keyCod = (navigator.appName.indexOf("Microsoft")!=-1 )? event.keyCode:event.which ;
                    var valid = "0123456789";
                    obj = (navigator.appName.indexOf("Microsoft")!=-1 ) ? window.event.srcElement:event ? event.target : null  ;
                    if ( dotreq && obj.value.indexOf(".") == -1  ) valid = valid + '.' ;
                    var temp = String.fromCharCode(keyCod);
                    if (valid.indexOf(temp) == "-1" && keyCod!=0 && keyCod!=8)    {
                       keyCod = 0 ;
                       return false ;
                    }
                    return true;
                }
                function isValidChar(Elemnt,event)
                {

                	for(var i=0;i<allowableChars.length;i++){

					   if((Elemnt.value.length+1 == allowableChars[i][0]) && (event.keyCode == allowableChars[i][1]));
					   {
					   	 return true;
					   }
                	}
                	return false;
                }
                function formatPhoneAndFax(event,elementId,forSsn) {
						var Country;
						Country = document.getElementById('ddlCountry');
						
						if(Country.value == "USA" || Country.value == "Canada")
						{
							var secondDelimter = 7;
							if(forSsn)
								secondDelimter = 6;
							Elemnt = document.getElementById(elementId);
							if(isNum(event)) {
								if(Elemnt.value.length > 0 && (Elemnt.value.length== 3 || Elemnt.value.length== secondDelimter))
									Elemnt.value = Elemnt.value + "-";
								else if(Elemnt.value.length == (secondDelimter+5))
												Elemnt.value = Elemnt.value + "x";
							}
							else  {
								if (!isValidChar(Elemnt,event))
                            		return false;
                            		//Not an Number
							}
							return true;
						}
						else
						{
							var key;
							key = event.keyCode;
							
							if(key < 48 || key > 57)
							{
								event.returnValue = false;
							}
							else
							{
								event.returnValue = true;
							}							
						}                        
                    } //End of formatPhone
                    
                    function formatPhoneAndFaxWithoutExtn(event,elementId,forSsn) {
						var Country;
						Country = document.getElementById('ddlCountry');
						
						if(Country.value == "USA" || Country.value == "Canada")
						{
							var secondDelimter = 7;
							if(forSsn)
								secondDelimter = 6;
							Elemnt = document.getElementById(elementId);
							if(isNum(event)) {
								if(Elemnt.value.length > 0 && (Elemnt.value.length== 3 || Elemnt.value.length== secondDelimter))
									Elemnt.value = Elemnt.value + "-";
								//else if(Elemnt.value.length == (secondDelimter+5))
									//Elemnt.value = Elemnt.value + "x";
							}
							else  {
								if (isValidChar(Elemnt,event))
                            		return false;
                            		//Not an Number
							}
							return true;
						}
						else
						{
							var key;
							key = event.keyCode;
							
							if(key < 48 || key > 57)
							{
								event.returnValue = false;
							}
							else
							{
								event.returnValue = true;
							}							
						}                        
                    } //End of formatPhone
                    
                    function isValidPhoneAndFax(elementId,maxLength,msg,forSsn) {
						var Country;
						Country = document.getElementById('ddlCountry');
						
						if(Country.value == "USA" || Country.value == "Canada")
						{						
							var secondDelimter = 7;
							if(forSsn)
								secondDelimter = 6;
							Elemnt = document.getElementById(elementId);
							if(Elemnt.value.length ==0 )
								return true;
							if((Elemnt.value.length < mandatoryLen) || (Elemnt.value.length > maxLength) ) {
									alert(msg);
									event.value="";
									Elemnt.focus();
							}
							else
							if(Elemnt.value.length == mandatoryLen+1){// checking for Extension, which is optional
                        		Elemnt.value = Elemnt.value.substring(0,Elemnt.value.length-1)
							}
							else if(Elemnt.value.length>0  && ( Elemnt.value.lastIndexOf('-') != secondDelimter || Elemnt.value.indexOf('-') != 3)) {
								alert(msg);
								Elemnt.focus();
							}
						}
						else
						{
							return true;
						}
                    } //End of validLength
           function formatSSN(event,elementId,forSsn) {
                        var secondDelimter = 7;
                        if(forSsn)
                            secondDelimter = 6;
                        if(isNum(event)) {
                            Elemnt = document.getElementById(elementId);
                            if(Elemnt.value.length > 0 && (Elemnt.value.length== 3 || Elemnt.value.length== secondDelimter))
                                Elemnt.value = Elemnt.value + "-";
                        }
                        else  {
                            return false; //Not an Number
                        }
                        return true;
                    } //End of formatPhone
					
					  function isValidSSN(elementId,maxLength,msg,forSsn) {

							var secondDelimter = 7;
							if(forSsn)
								secondDelimter = 6;
							Elemnt = document.getElementById(elementId);
							if(Elemnt.value.length == 0 )
							return true;
							if((Elemnt.value.length < SSNmandatoryLen) || (Elemnt.value.length > maxLength) ) {
									alert(msg);
									Elemnt.focus();
							}
						}
						function CountryListOnChange(Obj){
							Elemnt = document.getElementById('txtPhone');
							Elemnt.value="";
							if(Obj != 'Contact')
							{
								ShowCurrencies();
							}
						}
						function ShowCurrencies(){
							var ddlCountryValue = document.getElementById('ddlCountry').value;
							var dvCurrencies= document.getElementById('dvCurrencies');
							var splittedCurrenciesValue = ddlCountryValue.split("|")[1];
							dvCurrencies.innerHTML = splittedCurrenciesValue;
							}
						function CountryListOnChangeClient(){
							Elemnt = document.getElementById('txtWorkPhone');
							Elemnt1 = document.getElementById('txtCPPhone');
							//Country = document.getElementById('ddlCountry');
							Elemnt.value="";
							Elemnt1.value="";
							
							//if(Country.value != "USA" || Country.value != "Canada")
						}
						function Validate(){
							
							Elemnt = document.getElementById('ddlHear');
							TxtBox = document.getElementById('txtOthers');
							
							if (!validRequired(document.frmContact.txtFName,"First Name"))
							return false;
							
								else if (!validRequired(document.frmContact.txtCompany,"Company"))
								return false;
						
								else  if (!validRequired(document.frmContact.txtJobTitle,"Job Title"))
								return false;
								
								else if (!validEmail(document.frmContact.txtEmail,"EMail ID", "yes"))
								return false;
								
								else  if (!validRequired(document.frmContact.ddlHear,"How do you hear about Arman"))
								return false;
																				
								else if( Elemnt.options[Elemnt.selectedIndex].text == 'Others' )
										{
											if( TxtBox.value == "" || TxtBox.value.length < 0 )
											{
												alert("Please enter a value for Others");
												return false;
											}
										}
								else if (!validRequired(document.frmContact.txtComments,"Comments"))
								return false;
							
								else
								{
									//document.frmContact.submit();
									return true;
								}
						}
						
						//Download Demo form Validation
						function ValidateDownload(){
							
							//Elemnt = document.getElementById('ddlHear');
							//TxtBox = document.getElementById('txtOthers');
							
							if (!validRequired(document.frmDownload.txtFName,"Name"))
							return false;
							
								else if (!validRequired(document.frmDownload.txtOrganization,"Organization"))
								return false;
						
								else  if (!validRequired(document.frmDownload.txtPhone,"Phone No"))
								return false;
								
								else if (!validEmail(document.frmDownload.txtEmail,"EMail ID", "yes"))
								return false;
								
								else if (!validRequired(document.frmDownload.txtUsers,"No of User"))
								return false;
								
								else if (!validCheckbox(document.frmDownload.radAgree))
								return false;
								else
								{
									//document.frmContact.submit();
									return true;
								}
						}
						//Download Demo form Validation Ends
						
						//Download Demo form Validation
						function ValidateOrder(){
							
							//Elemnt = document.getElementById('ddlHear');
							//TxtBox = document.getElementById('txtOthers');
							
							if (!validRequired(document.frmOrderNow.txtFName,"Name"))
							return false;
							
								else if (!validRequired(document.frmOrderNow.txtOrganization,"Organization"))
								return false;
						
								else  if (!validRequired(document.frmOrderNow.txtPhone,"Phone No"))
								return false;
								
								else if (!validEmail(document.frmOrderNow.txtEmail,"EMail ID", "yes"))
								return false;
								
								else
								{
									//document.frmContact.submit();
									return true;
								}
						}
						//Download Demo form Validation Ends
						
						function QuoteValidate(){
							Elemnt = document.getElementById('ddlHear');
							TxtBox = document.getElementById('txtOthers');
							
							ServiceElemnt = document.getElementById('ddlService');
							ServiceTxtBox = document.getElementById('txtServiceOthers');
							
							if (!validRequired(document.frmRequestQuote.txtFName,"Name"))
							return false;
							
								else  if (!validRequired(document.frmRequestQuote.txtProject,"Project Name"))
								return false;
								
								else if (!validRequired(document.frmRequestQuote.txtCompany,"Company"))
								return false;
						
								else if (!validEmail(document.frmRequestQuote.txtEmail,"EMail ID", "yes"))
								return false;
								
								else if (!validSelection(document.frmRequestQuote.ddlCountry,"Country"))
								return false;
								
								else if (!validSelection(document.frmRequestQuote.ddlService,"Service Required"))
								return false;
								
								else if( ServiceElemnt.options[ServiceElemnt.selectedIndex].text == 'Others' )
										{
											if( ServiceTxtBox.value == "" || ServiceTxtBox.value.length < 0 )
											{
												alert("Please enter a value for Others");
												return false;
											}
										}
										
								else if (!validRequired(document.frmRequestQuote.txtCompletionDate,"Anticipated Date"))
								return false;
								
								else if (!validRequired(document.frmRequestQuote.txtBudget,"Your Budget"))
								return false;
								
								else  if (!validRequired(document.frmRequestQuote.ddlHear,"How do you hear about Arman"))
								return false;
																				
								else if( Elemnt.options[Elemnt.selectedIndex].text == 'Others' )
										{
											if( TxtBox.value == "" || TxtBox.value.length < 0 )
											{	
												alert("Please enter a value for Others");
												return false;
											}
										}
								else if (!validRequired(document.frmRequestQuote.txtComments,"Project Description"))
								return false;
							
								else
								{									
									return true;
								}
						}
						
						
						function fnSalesChk(){
								Elemnt = document.getElementById('chkSalesPerson');
								Elemnt.value = ( Elemnt.checked ) ? 1 : 0 ;
								}
						// Fucntion for Client Validate
						function fnClientValidate(){
								var Password = document.getElementById('txtPassword');
								var RPassword = document.getElementById('txtRePassword');
								
								if (!validRequired(document.frmClientManagement.txtCompanyName,"Company Name"))
								return false;
							
									else if (!validRequired(document.frmClientManagement.txtContactPerson,"Client Name"))
									return false;
							
									else if (!validEmail(document.frmClientManagement.txtCPPhoneEmail,"Personal Email ID", "yes"))
									return false;
									
									else  if (!validRequired(document.frmClientManagement.txtCPPhone,"Personal Phone #","yes"))
									return false;
																					
									else if (!validRequired(document.frmClientManagement.txtUserName,"Username"))
									return false;
									
									else if ((Password.value) != (RPassword.value))
										alert("Your passwords doesn't match !");
									else if ((Password.value == "") || (RPassword.value == ""))		
										alert("Your passwords cannot be empty !");
									
								else
								{
									return true;
								}
						}
						
						
						
