// JavaScript Document

//Function to create Ajax Object [Common Function]
function createajax()
{
    var objectname = false;	
	try
	{
		// Internet Explorer Browsers
		objectname = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e)
	{
		try
		{
			objectname = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e) 
		{
			try
			{
		// Opera 8.0+, Firefox, Safari
				objectname = new XMLHttpRequest();
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser is not responding for Javascripts.");
				return false;
			}
		}
	}
	return objectname;
}

//Function to Toggle an element Show/Hide [Common Function]
function showhide(elementid)
{
	var a = document.getElementById(elementid).style;	
	
	if(a.display == "none")
	{
		a.display = "block";
	}
	else
	{
		a.display = "none";
	}
	
}

//Function to check the valid format of email ID [Common Function]
function checkemail(a)
{
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(a) && r2.test(a));
}

function validadvertise()
{
	var form = document.advertiseform;
	var error = document.getElementById('error-message');
	var field = form.company;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the Company Name."; field.focus(); field.select(); return false; }
	var field = form.contact;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the Contact Number."; field.focus(); field.select(); return false; }
	
	var field = form.address;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the address."; field.focus(); return false; }

	var field = form.email;  
	if (field.value)
	{  var a=checkemail(field.value); if(a==false) { error.innerHTML = "Please enter a valid Email ID."; field.focus(); field.select(); return false; } }
	
	var field = form.country;  
	if (!field.value)
	{ error.innerHTML = "Please select the country."; field.focus(); return false; }

	if(form.country.value == 'India'){
	var field = form.state;  
	if (!field.value)
	{ error.innerHTML = "Please select a the State."; field.focus(); return false; }}

	if(form.country.value != 'India') {
	var field = form.otherstate;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the state."; field.focus(); return false;}}

	var field = form.phone;  
	if (!field.value)
	{ error.innerHTML = "Please Enter your contact Number."; field.focus(); return false;}

	var field = form.comment;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the comments."; field.focus(); return false;}
	
	else
	return true;

}

function tabopen4(activetab,tabgroupname)
{
	var totaltabs = 4;
	var activetabheadclass = "tabheadsmallactive";
	var tabheadclass = "tabheadsmall";
	
	for(var i=1; i<=totaltabs; i++)
	{
		var tabhead = tabgroupname + 'h' + i;
		var tabcontent = tabgroupname + 'c' + i;
		if(i == activetab)
		{
			document.getElementById(tabhead).className = activetabheadclass;
			document.getElementById(tabcontent).style.display = 'block';
		}
		else
		{
			document.getElementById(tabhead).className = tabheadclass;
			document.getElementById(tabcontent).style.display = 'none';
		}
	}
}

function tabopen2(activetab,tabgroupname)
{
	var totaltabs = 2;
	var activetabheadclass = "subtabheadsmallactive";
	var tabheadclass = "subtabheadsmall";
	
	for(var i=1; i<=totaltabs; i++)
	{
		var tabhead = tabgroupname + 'h' + i;
		var tabcontent = tabgroupname + 'c' + i;
		if(i == activetab)
		{
			document.getElementById(tabhead).className = activetabheadclass;
			//alert(tabhead);
			document.getElementById(tabcontent).style.display = 'block';
		}
		else
		{
			document.getElementById(tabhead).className = tabheadclass;
			document.getElementById(tabcontent).style.display = 'none';
		}
	}
}

function tabopen3(activetab,tabgroupname)
{
	var totaltabs = 3;
	var activetabheadclass = "otabheadsmallactive";
	var tabheadclass = "otabheadsmall";
	
	for(var i=1; i<=totaltabs; i++)
	{
		var tabhead = tabgroupname + 'h' + i;
		var tabcontent = tabgroupname + 'c' + i;
		if(i == activetab)
		{
			document.getElementById(tabhead).className = activetabheadclass;
			document.getElementById(tabcontent).style.display = 'block';
		}
		else
		{
			document.getElementById(tabhead).className = tabheadclass;
			document.getElementById(tabcontent).style.display = 'none';
		}
	}
}

function validfeedback()
{
	var form = document.feedbackform;
	var error = document.getElementById('error-message');
	var field = form.name;  
	if (!field.value)
	{ error.innerHTML = "Please Enter Name."; field.focus(); field.select(); return false;}

	var field = form.email;  
	if (field.value)
	{  var a=checkemail(field.value); if(a==false) {error.innerHTML = "Please enter a valid Email ID."; field.focus(); field.select(); return false;} }
	
	var field = form.comment;  
	if (!field.value)
	{ error.innerHTML = "Please Enter the comments."; field.focus(); return false;}
	
	else
	return true;

}

var win=null;
function LaunchApp(mypage,myname,scroll)
{
	settings='width='+ ((screen.width)-15) +',height='+ ((screen.height-55)) +',top='+0+',left='+0+',scrollbars='+scroll+	
	',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(mypage,myname,settings);
}



/*function checkcookie() {
//establish div object to manipulate
contentdiv=document.getElementById("fixme");
//check if cookie includes "mycookie"
if (document.cookie.indexOf("mycookie")!=-1) {
//if it does (not false), display the div object
contentdiv.style.display="block";
}
else {
//if it does not, set the cookie for next page load
document.cookie="mycookie=1";
}
} */

function itrclose(elementid)
{
	var a = document.getElementById(elementid).style;
	if(a.display == "block")
	{
		a.display = "none";
	}
	else
	{
		a.display = 'none';
	}
}

/*var my_Days=365; // Expiry in days
var my_Cookie='Online ITR Image Displayed'; // Cookie name

function setCookie() 
{
	document.cookie=my_Cookie+"="+escape(0)+";expires="+new Date(new Date().getTime()+my_Days*86400000).toGMTString()+";path=/;";
}*/
/*
var expDays = 1; // number of days the cookie should last
var page = "flashnews.htm";
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

function GetCookie(name) 
{
	var arg = name + "="; 
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0; 
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);  
		i = document.cookie.indexOf(" ", i) + 1;   
		if (i == 0) break; 
	}  
	return null;
}

function SetCookie(name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length; 
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) +  ((domain == null) ? "" : ("; domain=" + domain)) +  ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name) 
{
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt()
{
	var count = GetCookie('count')
	if(count == null) 
	{
		SetCookie('count','1')
		return 1
	}
	else 
	{
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
   	}
}

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() 
{
	var count = GetCookie('count');
	if (count == null) 
	{
		count=1;
		SetCookie('count', count, exp);
		window.open('flashnews.htm','Flashnews645201','width=460,height=510,menubar=no,scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,top=100,left=100'); 
	}
	else 
	{
		count++;
		SetCookie('count', count, exp);
	}
}
*/
