// JavaScript Document

function changeTab(no) {
    for (i = 1; i <= 3; i++) {
        if (i == no) {
            $("#content" + i).show();
            $('#head' + i).addClass("selected");
        } else {
            $("#content" + i).hide();
            $('#head' + i).removeClass("selected");
        }
    }
}

function validatefrm() {
    var count = 0;
    var msg = "Following error(s) occured:\n";
    var err = 0;
    if (document.getElementById("txt_name").value == "" || document.getElementById("txt_name").value == "Name") {
        msg += "\n- Please enter your name.";
        err++;
    }
    if (sc(document.getElementById("txt_name").value)) {
        msg += "\n- The name must not contain special characters.";
        err++;
    }
   
    if (document.getElementById("txt_email").value == "" || document.getElementById("txt_email").value == "Email" || !echeck(document.getElementById("txt_email").value)) {
        msg += "\n- Please enter a valid email address.";
        err++;
    }
    if (document.getElementById("txt_phone").value == "" || document.getElementById("txt_phone").value == "Phone") {
        msg += "\n- Please enter the valid phone number.";
        err++;
    }
    
    if (document.getElementById("txt_comment").value == "" || document.getElementById("txt_comment").value == "Comments") {
        msg += "\n- Please enter the comments.";
        err++;
    }
	if (document.getElementById("txt_scode").value == "" || document.getElementById("txt_scode").value == "Enter the Code") {
        msg += "\n- Please enter the security code.";
        err++;
    }
	/*if (document.getElementById("txt_company").value == "") {
        msg += "\n- Please enter the name of your company.";
        err++;
    }
	if (document.getElementById("txt_address").value == "") {
        msg += "\n- Please enter the address.";
        err++;
    }*/
    if (err > 0) {
        alert(msg + "\n");
        return false;
    } else {
        submitform();
		//return true;
    }
}

function isNumeric(value) {
    if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

function echeck(str) {
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }
    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }
    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }
    if (str.indexOf(" ") != -1) {
        return false
    }
    return true
}
function hideText(id,value)
{
	if(id=="txt_name" && value=="Name")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_email" && value=="Email")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_comment" && value=="Comments")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_phone" && value=="Phone")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_address" && value=="Address")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_company" && value=="Company")
	{
		document.getElementById(id).value = "";		
	}
	if(id=="txt_scode" && value=="Enter the Code")
	{
		document.getElementById(id).value = "";		
	}
}
function showText(id,value)
{
	if(id=="txt_name" && value=="")
	{
		document.getElementById(id).value = "Name";		
	}
	if(id=="txt_email" && value=="")
	{
		document.getElementById(id).value = "Email";		
	}
	if(id=="txt_comment" && value=="")
	{
		document.getElementById(id).value = "Comments";		
	}
	if(id=="txt_phone" && value=="")
	{
		document.getElementById(id).value = "Phone";		
	}
	if(id=="txt_address" && value=="")
	{
		document.getElementById(id).value = "Address";		
	}
	if(id=="txt_company" && value=="")
	{
		document.getElementById(id).value = "Company";		
	}
	if(id=="txt_scode" && value=="")
	{
		document.getElementById(id).value = "Enter the Code";		
	}
}

function sc(str) {
    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
    for (var i = 0; i < str.length; i++) {
        if (iChars.indexOf(str.charAt(i)) != -1) {
            return true;
        }
    }
}
