
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(dt){
	//var dt=document.frmSample.txtDate
	if (isDate(dt)==false){
		//dt.focus()
		return false
	}
	else
{
return true;
}

   // return true
 }


	


function checkFields(f)
		{
			fname = f.firstName.value;
			lname =	f.lastName.value;
			cnumber =	f.creditCardNumber.value;
			cvnumber =	f.cvv2Number.value;
			address =	f.address1.value;
			city =	f.city.value;
			zip =	f.zip.value;			
			if(fname.length < 1)
			{				
				f.firstName.focus();				
				alert('please enter firstname');				
				return false;
			}
			if(lname.length < 1)
			{				
				f.lastName.focus();				
				alert("please enter lastname");				
				return false;
			}
			if(cnumber.length < 1)
			{				
				f.creditCardNumber.focus();				
				alert("please enter card number");				
				return false;
			}
			//check for numeric
			if(!IsNumeric(cnumber))
			{				
				f.creditCardNumber.focus();				
				alert("Invalid card number");				
				return false;
			}
			if(cvnumber.length < 1)
			{				
				f.cvv2Number.focus();				
				alert("please enter veriication number");				
				return false;
			}
			//check for numeric
			if(!IsNumeric(cvnumber))
			{				
				f.cvv2Number.focus();				
				alert("Invalid card varification number");				
				return false;
			}
			if(address.length < 1)
			{				
				f.address1.focus();				
				alert("please enter address");				
				return false;
			}
			if(city.length < 1)
			{				
				f.city.focus();				
				alert("please enter city name");				
				return false;
			}
			if(zip.length < 1)
			{				
				f.zip.focus();				
				alert("please enter zip code");				
				return false;
			}
			
		}
		function IsNumeric(sText)
		{
			var ValidChars = "0123456789.";
			var IsNumber=true;
			var Char;

 
			for (i = 0; i < sText.length && IsNumber == true; i++) 
			   { 
			   Char = sText.charAt(i); 
			   if (ValidChars.indexOf(Char) == -1) 
			      {
			      IsNumber = false;
			      }
			   }
			return IsNumber;
   
		}





		function showrfqpopup(cid,parentobj){
			obj = document.getElementById(cid);
			mainobj = document.getElementById(parentobj);
			var curleft = curtop = 0;
			if (mainobj.offsetParent) {
			curleft = mainobj.offsetLeft;
			curtop = mainobj.offsetTop;
			while (mainobj = mainobj.offsetParent) {
			curleft += mainobj.offsetLeft;
			curtop += mainobj.offsetTop;
			}
		}
	obj.style.position = "absolute";
	obj.style.display = "";
	obj.style.left = curleft - 185 + 'px';
	obj.style.top = curtop - 190 + 'px';
	}




		function showpopup(cid,mainobj)
		{
		obj = document.getElementById(cid);
		var curleft = curtop = 0;
		if (mainobj.offsetParent) {
			curleft = mainobj.offsetLeft
			curtop = mainobj.offsetTop
			while (mainobj = mainobj.offsetParent) {
				curleft += mainobj.offsetLeft
				curtop += mainobj.offsetTop
			}
		}
		
		obj.style.position = "absolute";
		obj.style.display = "";
		obj.style.left = curleft + 10 + 'px';
		obj.style.top = curtop + 10 + 'px';
		}

		function hidepopup(divid)
		{
		objid = divid;
		document.getElementById(objid).style.display = "none";
		}
		function checkAccFormFields(f,usertype)
		{
			fname = f.firstName.value;
			//if(usertype == 0){
			lname =	f.lastName.value;
			//}
			//else{
			// lname = "null"
			//}
			phone =	f.phoneNo.value;
			email =	f.email.value;
			email2 = f.email2.value;
			password = f.password.value;	
			password2 = f.password2.value;	
			companyname = f.company.value;			
			if(fname.length < 1)
			{				
				f.firstName.focus();				
				alert('please enter firstname');				
				return false;
			}
			if(lname.length < 1)
			{				
				f.lastName.focus();				
				alert("please enter lastname");				
				return false;
			}
			if(phone.length < 1)
			{				
				f.phoneNo.focus();				
				alert("please enter phone number");				
				return false;
			}			
			if(email.length < 1)
			{				
				f.email.focus();				
				alert("please enter email address/username");				
				return false;
			}					
			if(password.length < 1)
			{				
				f.password.focus();				
				alert("please enter password");				
				return false;
			}			
			if(email != email2)
			{				
				f.email2.focus();				
				alert("please re-enter email address/username, emails entered are not same.");				
				return false;
			}
			if(password2 != password)
			{				
				f.password2.focus();				
				alert("please re-enter password again, password entered are not the same.");				
				return false;
			}
			if(companyname.length < 1)
			{				
				f.company.focus();				
				alert('please enter Company');				
				return false;
			}
		}

/* JAVASCRIPT */

var testObj;

function initFade() {
	document.getElementById('adhowitworksdiv').style.display = '';
	testObj = document.getElementById('adhowitworksdiv');
	for (var i=0;i<11;i++){
		setTimeout('setOpacity('+i+')',100*i);
	}
	return false;
}

function setOpacity(value)
{
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';	
}
function checkSecurityform(f)
{
	fullname = f.fullname.value;
	companyname = f.company.value;
	emailadd = f.email.value;
	cemail = f.c_email.value;
	phone = f.phone.value;
	if(fullname.length < 1)
	{				
		f.fullname.focus();				
		alert('please enter fullname');				
		return false;
	}
	if(companyname.length < 1)
	{				
		f.company.focus();				
		alert('please enter company name');				
		return false;
	}	
	if(emailadd.length < 1)
	{				
		f.email.focus();				
		alert('please enter a valid emailID');				
		return false;
	}


	if (!echeck(emailadd))
	{
		f.email.focus();
		alert('please enter valid EmailID');				
		return false;	
	}
	if (cemail.length< 1 )
	{
		f.email.focus();
			alert('please enter the confirm EmailID');
						
		return false;	
	}
if (emailadd != cemail)
	{
		f.email.focus();alert('email entered are not same');				
		return false;	
	}
	if(phone.length < 1)
	{				
		f.phone.focus();				
		alert('please enter phone number');				
		return false;
	}
}











function checkfieldsrfq(f)
{


	pjtname = f.projectName.value;
	
	
	partname = f.partName.value;
	descpn = f.desc.value;
	eausage = f.annualusage.value;
	qty= f.qty.value;
	expexteddate= f.ret3.value;
	
	ret = f.ret.value;
	awarddate= f.ret2.value;
	deliveryloc= f.desc222.value;

	commercialterms= f.desc223.value;
	
	instructions= f.desc225.value;

	contactname=f.contactname.value;

emailid=f.emailid.value;
phone=f.phoneno.value;
productmarket=f.productmarket.value;
zipcode=f.zipcode.value;
targetprice=f.targetprice.value;

//fileup1 = f.fileup.value;
	

if(pjtname.length < 1)
	{				
		f.projectName.focus();				
		alert('please enter Project Name');				
		return false;
	}

	if(partname.length < 1)
	{				
		f.partName.focus();				
		alert('please enter Part Name/Number');				
		return false;
	}



	if(descpn.length < 1)
	{				
		f.desc.focus();				
		alert('please enter Description');				
		return false;
	}

if(contactname.length < 1)
	{				
		f.contactname.focus();				
		alert('please enter Contact Name');				
		return false;
	}
if(emailid.length < 1)
	{				
		f.emailid.focus();				
		alert('please enter Email ID');				
		return false;
	}


if (!echeck(emailid))
	{
		f.emailid.focus();
		alert('please enter a valid EmailID');				
		return false;	
	}

if(phone.length < 1)
	{				
		f.phoneno.focus();				
		alert('please enter Phone number');				
		return false;
	}

if(productmarket.length < 1)
	{				
		f.productmarket.focus();				
		alert('please select Product Market');				
		return false;
	}



	if( !capabilityregioncheck() )
	{
	alert('Please select Process');
	return false;
	}

	if(eausage.length < 1)
	{				
		f.annualusage.focus();				
		alert('please enter Estimated annual usage');				
		return false;
	}

	if(!IsNumeric(eausage))
			{				
				f.annualusage.focus();				
				alert("Invalid Estimated annual usage");				
				return false;
			}
	if(qty.length < 1)
	{				
		f.qty.focus();				
		alert('please enter Release size quantity');				
		return false;
	}
	if(!IsNumeric(qty))
			{				
				f.qty.focus();				
				alert("Invalid Release size quantity");				
				return false;
			}

	if(expexteddate.length < 1)
	{				
		f.ret3.focus();				
		alert('please enter Expected date');				
		return false;
	}

else
{
if (ValidateForm(expexteddate))
{

}
else
{
f.ret3.focus();	
return false;
}
}
	if(ret.length < 1)
	{				
		f.ret.focus();				
		alert('please enter Close Date');				
		return false;
	}

else
{
if (ValidateForm(ret))
{

}
else
{
f.ret.focus();	
return false;
}
}

	if(awarddate.length < 1)
	{				
		f.ret2.focus();				
		alert('please enter Award Date');				
		return false;
	}
else
{
if (ValidateForm(awarddate))
{

}
else
{
f.ret2.focus();	
return false;
}
}

	if(deliveryloc.length < 1)
	{				
		f.desc222.focus();				
		alert('please enter Delivery location');				
		return false;
	}


	if(zipcode.length >0)
	{	
		if(!IsNumeric(zipcode))	
		{	
		f.zipcode.focus();				
		alert('please enter valid Zip Code');				
		return false;
		}
	}


	if(targetprice.length >0)
	{	
		if(!IsNumeric(targetprice))	
		{	
		f.targetprice.focus();				
		alert('please enter valid Price');				
		return false;
		}
	}

	
	//if(fileup1.length < 1)
		//{				
				//f.fileup.focus();				
				//alert('please select the file');				
				//return false;
			//}
		
	
	
	}




function validatesuppliers(f)
{
	cname = f.companyName.value;
	contactName = f.contactName.value;
	emailadd = f.emailid.value;
	phone = f.phoneno.value;
	if(cname.length < 1)
	{				
		f.companyName.focus();				
		alert('please enter Company Name');				
		return false;
	}
	if(contactName.length < 1)
	{				
		f.contactName.focus();				
		alert('please enter Contact Name');				
		return false;
	}	
	if(emailadd.length < 1)
	{				
		f.emailid.focus();				
		alert('please enter a emailID');				
		return false;
	}


	if (!echeck(emailadd))
	{
		f.emailid.focus();
		alert('please enter a valid EmailID');				
		return false;	
	}
	
	if(phone.length < 1)
	{				
		f.phoneno.focus();				
		alert('please enter phone number');				
		return false;
	}
}
function submitRFQ()
{
document.getElementById("rfqdiv").innerHTML = "<input type='hidden' name='submitRFQaction' value='SRFQ'/>";
document.theForm.submit();
}






function checkfieldsrfqsave(fr,cid,parentobj,RFQid)
{
	f = document.getElementById(fr);

	pjtname = f.projectName;
	
	
	partname = f.partName;
	
	descpn = f.desc;
	eausage = f.annualusage;
	qty= f.qty;
	expexteddate= f.ret3;
	
	ret = f.ret;
	awarddate= f.ret2;
	deliveryloc= f.desc222;

	commercialterms= f.desc223;
	
	instructions= f.desc225;

	contactname=f.contactname;

	emailid=f.emailid;
	phone=f.phoneno;
	productmarket=f.productmarket;
	zipcode=f.zipcode;
	targetprice=f.targetprice;
	
	
	if(pjtname.value.length < 1)
	{				
		document.getElementById(fr).projectName.focus();				
		alert('please enter Project Name');				
		exit;

	}

	if(partname.value.length < 1)
	{				
		document.getElementById(fr).partName.focus();				
		alert('please enter Part Name/Number');				
		exit;
	}



	if(descpn.value.length < 1)
	{				
		document.getElementById(fr).desc.focus();				
		alert('please enter Description');				
		exit;
	}

if(contactname.value.length < 1)
	{				
		document.getElementById(fr).contactname.focus();				
		alert('please enter Contact Name');				
		exit;
	}
if(emailid.value.length < 1)
	{				
		document.getElementById(fr).emailid.focus();				
		alert('please enter Email ID');				
		exit;
	}


if (!echeck(emailid.value))
	{
		document.getElementById(fr).emailid.focus();
		alert('please enter a valid EmailID');				
		exit;
	}

if(phone.value.length < 1)
	{				
		document.getElementById(fr).phoneno.focus();				
		alert('please enter Phone number');				
		exit;
	}

if(productmarket.value.length < 1)
	{				
		document.getElementById(fr).productmarket.focus();				
		alert('please select Product Market');				
		exit;
	}



	if( !capabilityregioncheck() )
	{
	alert('Please select Process');
	exit;
	}

	if(eausage.value.length < 1)
	{				
		document.getElementById(fr).annualusage.focus();				
		alert('please enter Estimated annual usage');				
		exit;
	}

	if(!IsNumeric(eausage.value))
			{				
				document.getElementById(fr).annualusage.focus();				
				alert("Invalid Estimated annual usage");				
				exit;
			}
	if(qty.value.length < 1)
	{				
		document.getElementById(fr).qty.focus();				
		alert('please enter Release size quantity');				
		exit;
	}
	if(!IsNumeric(qty.value))
			{				
				document.getElementById(fr).qty.focus();				
				alert("Invalid Release size quantity");				
				exit;
			}

	if(expexteddate.value.length < 1)
	{				
		document.getElementById(fr).ret3.focus();				
		alert('please enter Expected date');				
		exit;
	}

else
{
if (ValidateForm(expexteddate.value))
{

}
else
{
exit;
}
}

	if(ret.value.length < 1)
	{				
		document.getElementById(fr).ret.focus();				
		alert('please enter Close Date');				
		exit;
	}

else
{
if (ValidateForm(ret.value))
{

}
else
{
exit;
}
}
	if(awarddate.value.length < 1)
	{				
		document.getElementById(fr).ret2.focus();				
		alert('please enter Award Date');				
		exit;
	}
else
{
if (ValidateForm(awarddate.value))
{

}
else
{
exit;
}
}

	if(deliveryloc.value.length < 1)
	{				
		document.getElementById(fr).desc222.focus();				
		alert('please enter Delivery location');				
		exit;
	}


	if(zipcode.value.length >0)
	{	
		if(!IsNumeric(zipcode.value))	
		{	
		document.getElementById(fr).zipcode.focus();				
		alert('please enter valid Zip Code');				
		exit;
		}
	}


	if(targetprice.value.length >0)
	{	
		if(!IsNumeric(targetprice.value))	
		{	
		document.getElementById(fr).targetprice.focus();				
		alert('please enter valid Price');				
		exit;
		}
	}

	
	//showrfqpopup(cid,parentobj);




ajaxFunction();

var sUrl = "../suppliers/GetRFQ.asp?RFQid="+RFQid
	if (xmlHttpObj != null) 
		{
			xmlHttpObj.onreadystatechange = function(){
			  if(xmlHttpObj.readyState == 4)
                 {	
                     if(xmlHttpObj.status == 200)
                     {	

if (xmlHttpObj.responseText=='submittedRFQ')
{
showrfqpopup(cid,parentobj);
}
else
{
//alert('hi');
document.getElementById("saveChangesDiv").innerHTML = "<input type='hidden' name='SaveStatus' value='YESNO'/>";
document.forgotForm.submit();


}

                       
                      }
                 }	
       }	
	   xmlHttpObj.open("GET",sUrl,true);
	   xmlHttpObj.send(null);
	}


	
	
	}




function checkemailbuyer(f)
{


	emailto = f.emailto.value;
	
	
	emailfrom = f.emailfrom.value;
	emailsubject= f.emailsubject.value;
	emailmsg= f.emailmsg.value;
			if(emailto.length < 1)
			{				
				f.emailto.focus();				
				alert('please enter To Address');				
				return false;
			}

if (!echeck(emailto))
	{
		f.emailto.focus();
		alert('please enter valid EmailID');				
		return false;	
	}

			if(emailfrom.length < 1)
			{				
				f.emailfrom.focus();				
				alert("please enter From Address");				
				return false;
			}


if (!echeck(emailfrom))
	{
		f.emailfrom.focus();
		alert('please enter valid EmailID');				
		return false;	
	}

			if(emailsubject.length < 1)
			{				
				f.emailsubject.focus();				
				alert("please enter Subject");				
				return false;
			}
			if(emailmsg.length < 1)
			{				
				f.emailmsg.focus();				
				alert("please enter Message");				
				return false;
			}
}












function checksubmitQuote(f)
{
	

	//alert(f.checkbox.value);
	//alert(f.phonePermission.value);
	suppliername = f.suppliername.value;
	contactname= f.contactname.value;
	phoneno= f.phoneno.value;
	emailid = f.emailid.value;
	price= f.price.value;

	
			if(suppliername.length < 1)
			{				
				f.suppliername.focus();	
			
				alert('please enter Supplier submitting quote');				
				return false;
			}


			if(contactname.length < 1)
			{				
				f.contactname.focus();				
				alert("please enter Supplier Contact name");				
				return false;
			}



			if(phoneno.length < 1)
			{				
				f.phoneno.focus();				
				alert("please enter Phone number");				
				return false;
			}
			if(emailid.length < 1)
			{				
				f.emailid.focus();				
				alert("please enter E-mail address");				
				return false;
			}

			if (!echeck(emailid))
			{
				f.emailid.focus();
				alert('please enter valid EmailID');				
				return false;	
			}

			if(price.length < 1)
			{				
				f.price.focus();				
				alert("please enter Price");				
				return false;
			}
			if(!IsNumeric(price))
			{				
				f.price.focus();				
				alert("Invalid Price");				
				return false;
			}
			
			if (f.checkbox.checked ==1)
			{}
			else
    			{
			f.checkbox.focus();
			alert("Please review fee information and check box to agree to terms");
			return false;
			}
  			
			

}




	function showpaymentpopup(cid)
		{
		obj = document.getElementById(cid);
		
				
		obj.style.position = "absolute";
		obj.style.display = "block";
		obj.style.left = 24 + '%';
		obj.style.top = 40 + '%';
		}





function checksupplieradd(suppid)
{
ajaxFunction();
 //alert(suppid);
var sUrl = "../suppliers/GetSupplier.asp?suppid="+suppid
	if (xmlHttpObj != null) 
		{
			xmlHttpObj.onreadystatechange = function(){
			  if(xmlHttpObj.readyState == 4)
                 {	
                     if(xmlHttpObj.status == 200)
                     {	



                       
                      }
                 }	
       }	
	   xmlHttpObj.open("GET",sUrl,true);
	   xmlHttpObj.send(null);
	}
}

function ajaxFunction()
    {        
        try
        {
        //firefox,opera,safari
        xmlHttpObj = new XMLHttpRequest();      
        }
        catch(e)
        {        
            try
            {
            xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try{ xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");}
                catch(e){alert("your browser doesnt support Ajax!");return false;};
            }
        }
        if(xmlHttpObj == null)
        alert('go home');
        //return xmlHttpObj;  
    } 

