var arrNumeric=new Array('');
var arrEmpty = new Array('');
var list=new Array('');
var arrTextbox=new Array('');
var invalidEmail;

function submitForm()
{
	var j=0;
	var str;
    str="";
	
//	alert("typeof str: " + typeof(str));
//	alert("array" + arrTextbox);

	if (arrTextbox != "")
	{
//		alert("not empty");
		arrTextbox=new Array('');
	
	}
//	alert("textbox array is empty now" +arrTextbox);

//collect all textbox from form
	for(i=0; i<document.frm1.elements.length; i++)
		{
		if(document.frm1.elements[i].name=='email' && document.frm1.elements[i].value != "")
			{
					echeck(document.frm1.elements[i].value);	
			}
		 if(document.frm1.elements[i].type=="text")
			{
					 arrTextbox[j]=document.frm1.elements[i];
					 j=j+1;
			}
		}

	//check for null values
	if (arrEmpty != "")
	{
		//alert("not empty");
		arrEmpty=new Array('');
	
	}
	//alert("Require field is empty now" + arrEmpty);


for(i=0; i<arrTextbox.length; i++)
	 {
		  if(arrTextbox[i].value=="")
		  {	
			arrEmpty[i]="- " + arrTextbox[i].id + " is required field \n";	
		  }
	 }

	//alert("array of textbox and empty" + arrTextbox + arrEmpty);

if (list != "")
	{
	//	alert("not empty");
		list=new Array('');
	
	}

	//alert("Lsit numeric is empty now" + list);
	 j=0;
	  for(i=0; i<document.frm1.elements.length; i++)
		{
		 if(document.frm1.elements[i].name=='budgetTo'|| document.frm1.elements[i].name=='budgetFrom' || document.frm1.elements[i].name=='timelineFrom' || document.frm1.elements[i].name=='timelineTo')
		 {
					list[j]=document.frm1.elements[i];
					//alert("Insert item in list" + list[j]);
					j=j+1;
		 }
		}

	//alert("count list: " + list.length);
	//check all numeric fields
if (arrNumeric != "")
	{
		//alert("not empty");
		arrNumeric=new Array('');
	
	}

	//alert("Lsit numeric is empty now" + list);

	  for(k=0;k<list.length; k++)
		{
           // alert("list value" + list[k].value);
			if(list[k].value != "")
			{	
				 isNumber(list[k].value,list[k].id,k,arrNumeric);
			}

		}

//start printing in div 
if(arrEmpty.length>0)
{

		 for(k=0;k<arrEmpty.length;k++)
			{
				if(typeof(arrEmpty[k]) != 'undefined')
				{
				if(k == 0 || typeof(str) == "undefined" || str	== "")
					{
					 str = arrEmpty[k];
					}
				else
					{
					str += arrEmpty[k];
					}
				}
			}
}
if(arrNumeric.length>0)
{

		 for(k=0;k<arrNumeric.length;k++)
			{
				if(typeof(arrNumeric[k]) != 'undefined')
				{
				if(k == 0 && typeof(str) == "undefined" || str	== "")
					{
					 str = arrNumeric[k];
					}
				else
					{
					str += arrNumeric[k];
					}
				}
			}
}

if(typeof(invalidEmail) != 'undefined')
{
if(typeof(str) == 'undefined' || str == "")

	{	str = invalidEmail; }
else
	{	str += invalidEmail; }

}

if(arrNumeric.length>0)
{
if(typeof(arrNumeric[k]) != 'undefined')
	{
	 for(p=0;p<arrNumeric.length;p++)
		{
		 if(p=0 && typeof(str) == 'string' || str == "")
			{
			 str = arrNumeric[p];
			}
		 else
			{
			str += arrNumeric[p];
			}
		}
	}
}

//alert("type of before checking: " + typeof(str));

if(str == "")
	{return true;}
else{
//		divId.innerHTML = str;
	   var error = "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	   error = error + str;
	   alert(error);

		return false;
}
}
//format 


//Function to check email

function echeck(emailStr) {

		var at="@";
		var dot=".";
		var lat=emailStr.indexOf(at);
		var lstr=emailStr.length;
		var ldot=emailStr.indexOf(dot);
		var isEmail=true;
		invalidEmail="";
				//alert("make empty" + invalidEmail);

		if (emailStr.indexOf(at)==-1 || emailStr.indexOf(at)==0 || emailStr.indexOf(at)==lstr){
			invalidEmail="- Invalid E-mail ID \n";
		  isEmail=false;
		}

		if (emailStr.indexOf(dot)==-1 || emailStr.indexOf(dot)==0 || emailStr.indexOf(dot)==lstr){
		    invalidEmail="- Invalid E-mail ID \n";
		    		  isEmail=false;
		}

		 if (emailStr.indexOf(at,(lat+1))!=-1){
			invalidEmail="- Invalid E-mail ID \n";		   
					  isEmail=false;
		 }

		 if (emailStr.substring(lat-1,lat)==dot || emailStr.substring(lat+1,lat+2)==dot){
		    invalidEmail="- Invalid E-mail ID \n";
					  isEmail=false;
		 }

		 if (emailStr.indexOf(dot,(lat+2))==-1){
		    invalidEmail="- Invalid E-mail ID \n";
					  isEmail=false;
		   
		 }
		
		 if (emailStr.indexOf(" ")!=-1){
			invalidEmail="- Invalid E-mail ID \n";
					  isEmail=false;
		 }

		if(invalidEmail=="")
				 return isEmail;					
		else
   				 return isEmail;

		//alert("email" + invalidEmail);
	}
//Function to check numbers
function isNumber(num,name,j,arrNumeric)
{
	//alert("number to be checke: " + num);
	var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;
 
    for (i = 0; i < num.length && IsNumber == true; i++) 
      { 
       Char = num.charAt(i); 
       if (ValidChars.indexOf(Char) == -1) 
		  {
		   IsNumber = false;
		   arrNumeric[j]="- " + name + " : is numeric field \n\n";
         }
      }

   return IsNumber;
}


function HideDiv(divId) {
if(divId.length < 1) { return; }
document.getElementById(divId).style.display = "none";
}

function ShowDiv(divId) {
if(divId.length < 1) { return; }
document.getElementById(divId).style.display = "block";
}

function show_option()
{
	var selVal;
//	selVal=document.getElementById('projectDomain').value;
indexVal=document.getElementById('projectDomain').selectedIndex;
switch(indexVal)
	{
	case 0:
		ShowDiv('internetDiv');
		HideDiv('windowDiv');
		break;
	case 1:
		HideDiv('internetDiv');
		ShowDiv('windowDiv');
		break;
	}

}

function show_result()
{
	var str="<p>Your mail is send to the sales department</p>"
	var divId=document.getElementById('mailMessage');
	divId.innerHTML=str;
}
function return_select()
{

var Table = document.getElementById('childTable');

//Get reference to table body.
var TableBody = Table.firstChild;

//Create the new elements
var NewRow = document.createElement("tr");

var ActionsCell = document.createElement("td");
ActionsCell.style.width = 117;
ActionsCell.setAttribute("height","30");
ActionsCell.setAttribute("align","left");

//ActionsCell.height = '30';
var newText = document.createTextNode("Attach a file: ");
ActionsCell.appendChild(newText);

var ActionsCelld = document.createElement("td");
ActionsCelld.setAttribute("height","30");

var newText1 = document.createElement("span");
newText1.setAttribute("class","innerTableElements");

var pathCell=document.createElement("td");
var filePathName=document.createElement("input");
pathCell.style.width = 448;
filePathName.type="file";
filePathName.size="58";
filePathName.className="field";
filePathName.name="attachFile[]";

var ActionsCell4 = document.createElement("td");
var img=document.createElement('IMG');
img.setAttribute('src', 'delete.gif');
img.onclick = function(){
            removeME(NewRow);
        }

ActionsCell.appendChild(newText);
ActionsCelld.appendChild(newText1);
pathCell.appendChild(filePathName);
pathCell.appendChild(img);

//Add elements to row.
NewRow.appendChild(ActionsCell);
NewRow.appendChild(ActionsCelld);
NewRow.appendChild(pathCell);
//NewRow.appendChild(ActionsCell4);

//Add row to table

TableBody.appendChild(NewRow);

}
function removeME(tr)
{
tr.parentNode.removeChild(tr);
}

function showAnother(id)
{
	var content = '<table id="uploadT" width="681"><tr><td width="115" height="30">Attach a file : </td><td align="left"><input name="attachFile[]" type="file" class="field" size="58"></td></tr></table>';

	//alert(content);
	alert(document.getElementById(id).innerHTML);
	document.getElementById(id).innerHTML += content;
	document.getElementById(id).style.display = 'block';
}

function dynamiccontentNS6(elementid, content)
{
	if(document.all)
	{
		el = document.getElementById(elementid);
		el.innerHTML += content;
	}
	else if(document.getElementById)
	{
		rng = document.createRange();
		el = document.getElementById(elementid);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(content);
		el.appendChild(htmlFrag);
	}
}

function addMoreFile()
{
	var obj = document.getElementById("frm1");
	obj.totalDiv.value = parseInt(obj.totalDiv.value) + 1;
	var newVal = obj.totalDiv.value;
	var content = '<div id="id_'+newVal+'"><br/><label>Attach a file:</label><input name="attachFile[]" type="file" size="30" />&nbsp;&nbsp;<a href="javascript: removeMoreFile('+newVal+');">Remove</a></div>';
	
	document.getElementById("moreFile").style.display = "block";
	dynamiccontentNS6("moreFile", content);
}

function removeMoreFile(id)
{
	document.getElementById('id_'+id).style.display = 'none';
	document.getElementById('id_'+id).innerHTML = '';
}

function doSubmit(obj)
{
	var msg = "", error = "false", regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$/;
	var error = "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	
	if(obj.budgetFrom.value=='')
	{
	   msg += "Please enter budget from.\n";
	}
	else if(isNaN(obj.budgetFrom.value))
	{
		msg += "Budget From should be numeric.\n";
	}
	if(obj.budgetTo.value=='')
	{
	   msg += "Please enter budget to.\n";
	}
	else if(isNaN(obj.budgetTo.value))
	{
		msg += "Budget To should be numeric.\n";
	}
	else if((obj.budgetFrom.value - 0)>(obj.budgetTo.value - 0))
	{
		msg += "Budget From should be less than Budget To.\n";
	}

	if(obj.currency.value == '')
	{
		msg += "Please select currency.\n";
	}

	if(obj.timelineFrom.value=='')
	{
	   msg += "Please enter timeline from.\n";
	}
	else if(isNaN(obj.timelineFrom.value))
	{
	   msg += "Timeline From should be numeric.\n";
	}
	if(obj.timelineTo.value=='')
	{
		   msg += "Please enter timeline to.\n";
	}
	else if(isNaN(obj.timelineTo.value))
	{
	   msg += "Timeline To should be numeric.\n";
	}
	else if((obj.timelineFrom.value - 0) > (obj.timelineTo.value - 0))
	{
		msg += "Timeline From should be less than Timeline To.\n";
	}

	if(obj.name.value=='')
	{
		   msg += "Please enter your name.\n";
	}
	if(obj.companyName.value=='')
	{
		   msg += "Please enter company name.\n";
	}
	if(obj.designation.value=='')
	{
		   msg += "Please enter designation.\n";
	}
	if(obj.email.value=='')
	{
		   msg += "Please enter email.\n";
	}
	else if(!regEmail.test(obj.email.value))
	{
		   msg += "Email is not valid.\n";
	}
	if(obj.contact.value=='')
	{
		   msg += "Please enter contact number.\n";
	}       
	if(obj.security_code.value=='')
	{
		   msg += "Please enter verification code.\n";
	}
	if(msg != "")
	{
		error += msg;
		alert(error);
		return false;
	}
	else
	{
		return true;
	}
}

/******************************************
Date created : 25 Sep 2007
Date last modified : 25 Sep 2007
Author :  Sandeep Kumar
Last modified by :  Sandeep Kumar
Comments : JavaScript Function To validate newsletter_subscription from.
******************************************/
function validateNewsletterSubscriptionForm(obj)
{
	var error = "", masterStr = "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	var regEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if(obj.name.value == "")
		error += "Please enter Name.\n";
	
	p=obj.email.value.indexOf('@');
	s=obj.email.value.indexOf('.');
	
	if(obj.email.value == '')
	{
	 error+='Please enter E-mail Address.\n';
	}
	else if (p<1 || p==(obj.email.value.length-1))
	{
		
		error+='Please enter valid E-mail Address.\n';

	}
	else if(!regEmail.test(obj.email.value))
	{
		error+='Please enter valid E-mail Address.\n';
	}
	
   
	/*if(obj.checkbox.checked == false && obj.checkbox1.checked == false && obj.checkbox2.checked == false && obj.checkbox5.checked == false &&obj.checkbox22.checked == false && obj.checkbox23.checked == false)
	{
		error += 'Please choose your option for News latter subscriptions.\n';
	}*/
		
	/*if(obj.comment.value == "")
	{
		error += "Please enter requirement/comments/notes.\n";
	}*/
	
	if(obj.frmSecurityCode.value == "")
	{
		error += "Please enter verification code.\n";
	}
	if(error == "")
	{
		return true;
	}
	else
	{
		error = masterStr+error;
		alert(error);
		return false;
	}
}




