// JScript source code
// function for default date on page load event
function populatedropdown(dayfield, monthfield, yearfield) {
	
	
	var daytext=['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
    var monthtext = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    var yeartext = ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'];
    var today = new Date()
	
    var dayfield = document.getElementById(dayfield)
    var monthfield = document.getElementById(monthfield)
    var yearfield = document.getElementById(yearfield)
	
	var dayTo=document.getElementById('daydropdownsecond');
	var monthTo=document.getElementById('monthdropdownsecond');
	var yearTo=document.getElementById('yeardropdownsecond');
	
    if(dayfield !=null && monthfield !=null && yearfield !=null)
    {
    for (var i = 0; i < 31; i++)
	{
		dayfield.options[i] = new Option(daytext[i], daytext[i])
		if(dayTo !=null)
		{
			dayTo.options[i] = new Option(daytext[i], daytext[i])
		}
		
	}
	
	dayfield.options[14] = new Option(daytext[14], daytext[14], true, true) // default date 15 
		if(dayTo !=null)
		{
				dayTo.options[14] = new Option(daytext[14], daytext[14],true,true)
		}
		
 
    for (var m = 0; m < 12; m++)
	{
        monthfield.options[m] = new Option(monthtext[m], monthtext[m])
		if(monthTo !=null)
		{
			monthTo.options[m] = new Option(monthtext[m], monthtext[m])
		}
		
		
	}
         //select today's month
	monthfield.options[6] = new Option(monthtext[6], monthtext[6], true, true)// default month 6
	if(monthTo !=null)
		{
			monthTo.options[6] = new Option(monthtext[6], monthtext[6],true,true)
		}
	
    var cnt = -1;
    for (var y = 0; y < 11; y++) {
        yearfield.options[y] = new Option(yeartext[y], yeartext[y]);
		if(yearTo !=null)
		{
			yearTo.options[y] = new Option(yeartext[y], yeartext[y]);
		}
        if (yeartext[y] != today.getFullYear()) { cnt += 1;}
            
        }
        
		 yearfield.options[6] = new Option(yeartext[6], yeartext[6], true, true) //select default year 2006
		 if(yearTo !=null)
		{
			yearTo.options[6] = new Option(yeartext[6], yeartext[6],true,true)
		}
  }
  else
  {
  }
 
}

 //Function for Feedback validation -->emailcheck() , ValidateEmail() and ValidateUserName()
 function emailcheck(str) {
     var at = "@";
     var dot = ".";
     var lat = str.indexOf(at);
     var lstr = str.length;
     var ldot = str.indexOf(dot);
     if (str.indexOf(at) == -1) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.indexOf(at, (lat + 1)) != -1) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.indexOf(dot, (lat + 2)) == -1) {
         alert("Invalid E-mail ID");
         return false;
     }
     if (str.indexOf(" ") != -1) {
         alert("Invalid E-mail ID");
         return false;
     }
     return true;
 }

 function ValidateEmail() {
    var nameID = document.getElementById('txtName');
	var emailID = document.getElementById('txtEmail');
	var commentsID = document.getElementById('txtComments');
	var formID = document.getElementById('frmEmail');
	var bool = true;
 if ((nameID.value == null) || (nameID.value == "")) {
         alert("Please Enter your valid name");
         nameID.focus();
         bool = false;
     }

	if ((emailID.value == null) || (emailID.value == "")) {
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!emailID.value.match(emailRegEx)){
		alert("Please Enter valid Email ID");
        emailID.focus();
        bool = false;
		}
		else{
		alert("Please Enter Email ID");
		emailID.focus();
        bool = false;
		}
	}
  

 if ((commentsID.value == null) || (commentsID.value == "")) {
         alert("Please Enter your comments");
         commentsID.focus();
        bool = false;     }

	if(bool == true){
		formID.submit();
		}
	
 }

 function ValidateUserName() {
     var userName = document.getElementById('txtName');
     if ((userName.value == null) || (userName.value == "")) {
         alert("Please Enter Your Name");
         userName.focus();
     }
     
 }

//Testing  
 function updateMap(dayfield, monthfield, yearfield) {
     var dayfield = document.getElementById(dayfield);
     var monthfield = document.getElementById(monthfield);
     var yearfield = document.getElementById(yearfield);
     monthfield.selectedIndex.toString();
     var strdate = dayfield.value.toString() + "/" + monthfield.value.toString() + "/" + yearfield.value.toString();
    
     
 }

function SendEmail() {
     var to = "ambarishmugalikar@gmail.com";
     var from = document.getElementById('txtEmail').value;
     var userName = document.getElementById('txtName').value;
     var sub = "NSSTC Project Feedback";
     var feedback = document.getElementById('txtComments').value;
     var bod = feedback + "  __  " + userName;
     
     if (from == null || from == "" && userName == null || userName == "" && feedback == null || feedback == "") {
         alert('Invalid Fields');
         return false;
     }
     else {
         location.href = 'mailto:' + to + '&subject=' + sub + '&body=' + bod;
         document.getElementById('txtEmail').value = '';
         document.getElementById('txtName').value = '';
         document.getElementById('txtComments').value = '';
		 
         return true;
     }
     
 }
 function passQuery() {
            $.get("#", { daydropdown: "foobar", monthdropdown: "foobar", yeardropdown: "foobar" });
        }

        function checkQueryString() {
            var query = location.search.substring(1);
            if (query == null || query == '') {}
            else {
                var str = query.substring(query.indexOf('daydropdown'));
                
                var dayfield = str.substring(0, str.indexOf('&'));
                var dayFieldID = dayfield.substring(0, dayfield.indexOf('='));
                var dayFieldValue = dayfield.substring(dayfield.indexOf('=') + 1);
				

                str = str.substring(str.indexOf('&') + 1);
                var monthfield = str.substring(0, str.indexOf('&'));
                var monFieldID = monthfield.substring(0, monthfield.indexOf('='));
                var monFieldValue = monthfield.substring(monthfield.indexOf('=') + 1);

                str = str.substring(str.indexOf('&') + 1);
                var yerFieldID = str.substring(0, str.indexOf('='));
                var yerFieldValue = str.substring(str.indexOf('=') + 1);
                
                if(dayFieldID !='' && monFieldID !='' && yerFieldID !='')
                {
                

                document.getElementById(dayFieldID).value = dayFieldValue;
                document.getElementById(monFieldID).value = monFieldValue;
                document.getElementById(yerFieldID).value = yerFieldValue; 
                }            
              }
        }
 
 function populatedropdownsecond(dayfield, monthfield, yearfield) {
	var daytext=['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
    var monthtext = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    var yeartext = ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010'];
    var today = new Date()
    var dayfield = document.getElementById(dayfield)
    var monthfield = document.getElementById(monthfield)
    var yearfield = document.getElementById(yearfield)
    
    for (var i = 0; i < 31; i++)
        //dayfield.options[i] = new Option(i, i + 1)
		dayfield.options[i] = new Option(daytext[i], daytext[i])
        //dayfield.options[today.getDate()] = new Option(today.getDate(), today.getDate(), true, true) //select today's day
   
	
 dayfield.options[14] = new Option(daytext[14], daytext[14], true, true) // default date 15 
    for (var m = 0; m < 12; m++)
        monthfield.options[m] = new Option(monthtext[m], monthtext[m])
       
monthfield.options[6] = new Option(monthtext[6], monthtext[6], true, true)// default month 6
    var cnt = -1;
    for (var y = 0; y < 11; y++) {
        yearfield.options[y] = new Option(yeartext[y], yeartext[y])
        if (yeartext[y] != today.getFullYear()) { cnt += 1;}
            
        }
        
 yearfield.options[6] = new Option(yeartext[6], yeartext[6], true, true) //select default year 2006
}
function setinputvariable(){
	var dayIndex = document.frmName.daydropdown.selectedIndex;
	var day=document.frmName.daydropdown.options[selIndex].value;
	var monthIndex = document.frmName.monthdropdown.selectedIndex;
	var month=document.frmName.monthdropdown.options[selIndex].value;
	var yearIndex = document.frmName.yeardropdown.selectedIndex;
	var year=document.frmName.yeardropdown.options[selIndex].value;
	
}
 function DynamicCss()
    {
       
        var nVer = navigator.appVersion;
        var nAgt = navigator.userAgent;
        var browserName = navigator.appName;       
        var verOffset;
        var dynamicCssID=document.getElementById('dynCSS');
               
         // In MSIE, the true version is after "MSIE" in userAgent
         if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
         browserName = "Microsoft Internet Explorer";        
         dynamicCssID.href="Nsstc_Style_IE.css";
        
        }

        // In Chrome, the true version is after "Chrome"
         else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
        browserName = "Chrome";
         dynamicCssID.href="Nsstc_Style_Chrome.css";
        }

        // In Firefox, the true version is after "Firefox"
         else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
         browserName = "Firefox"; 
         dynamicCssID.href="Nsstc_Style_Firefox.css";
        
        }
        else
        { 
        
           dynamicCssID.href="Nsstc_Style.css";        
        }
    }