// if checkspace variable is 1 it means spaces need to be checked other wise it is not required

var t; // it will be instance of window

function whitespace(obj, checkspace)
{
   var s = obj.value;
   var flag = 0;
 	for(var i = 0; i < s.length; i++){
		if((s.charAt(i)=="~") || (s.charAt(i)=="`") || (s.charAt(i)=="%") || (s.charAt(i)=="#") || (s.charAt(i)=="$") || (s.charAt(i)=="^") || (s.charAt(i)=="*") || (s.charAt(i)=="(") || (s.charAt(i)==")") || (s.charAt(i)=="+") || (s.charAt(i)=="=") || (s.charAt(i)=="|") || (s.charAt(i)=="}") || (s.charAt(i)=="{") || (s.charAt(i)=="]") || (s.charAt(i)=="[") || (s.charAt(i)==":") || (s.charAt(i)==";") || (s.charAt(i)=="'") || (s.charAt(i)=="<") || (s.charAt(i)==">") || (s.charAt(i)==",") || (s.charAt(i)==".") || (s.charAt(i)=="/") || (s.charAt(i)=="\t") || (s.charAt(i)=="\\") || (s.charAt(i)=='"') || (s.charAt(0)=='?') || (s.charAt(0)=='!') || (s.charAt(0)=='@') || (s.charAt(0)=='&'))
		{
			flag = 1;
		}
		// if checkspace i 1 then check space and for "-" character
		if (checkspace == 1)
		{
			if ((s.charAt(i)==" "))
			{
				flag = 1;
			}
		}
		
		if (flag == 1)
		{
			alert("Error : Special characters in a button name are not allowed.");
			obj.focus();
			obj.select();			
			return false;
		}
	}
	return true;
}


function checkdomain(obj)
{
	obj.value = trimchar(obj.value, " ");
	var st = obj.value;
	st = trimchar(st, " ");
		if (st.indexOf(" ") > 0)
		{
			if(confirm("Invalid space in domain name.\n Would you like to replace it with the character \"-\" ?")==true)
			{
				var st1 = st;
				var st2;
				while(st.indexOf(" ") > 0)
				{
					obj.value = st.replace(' ','-');
					st = obj.value; 	
				}
				st2 = st;
				if (confirm("Your domain name has been changed from " + st1 + " to " + st2 + "\n Would you like to continue?")==false)
				{
					obj.focus();
					return false;
				}
			}	
			else
			{	
				obj.value = st;
				obj.focus();
				return false;
			}
		}
		return true;
}

function trimchar(pastr, pachar)
{
	var lenstr = pastr.length;
	for(var i = 0 ; pastr.charAt(i) == " "; i++);
	for(var j = pastr.length - 1; pastr.charAt(j)== " "; j--);
	j++;
	pastr = pastr.substring(i,j);
	return pastr;
}

function checkDuplicate(obj1, obj2, obj3, obj4, obj5, obj6, obj7)
{
	var msg = "You have entered duplicate values.\n Please assign a different name for each button.";
	obj1.value = trimchar(obj1.value, " ");
	obj2.value = trimchar(obj2.value, " ");
	obj3.value = trimchar(obj3.value, " ");
	obj4.value = trimchar(obj4.value, " ");
	obj5.value = trimchar(obj5.value, " ");
	obj6.value = trimchar(obj6.value, " ");
	obj7.value = trimchar(obj7.value, " ");
	
	if(obj1.value.length != 0)
		if(obj1.value.toUpperCase() == obj2.value.toUpperCase() || obj1.value.toUpperCase() == obj3.value.toUpperCase() || obj1.value.toUpperCase() == obj4.value.toUpperCase() || obj1.value.toUpperCase() == obj5.value.toUpperCase() || obj1.value.toUpperCase() == obj6.value.toUpperCase() || obj1.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj1.focus();
			return false;
		}
	if(obj2.value.length != 0)
		if(obj2.value.toUpperCase() == obj1.value.toUpperCase() || obj2.value.toUpperCase() == obj3.value.toUpperCase() || obj2.value.toUpperCase() == obj4.value.toUpperCase() || obj2.value.toUpperCase() == obj5.value.toUpperCase() || obj2.value.toUpperCase() == obj6.value.toUpperCase() || obj2.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj2.focus();
			return false;
		}
	if(obj3.value.length != 0)
		if(obj3.value.toUpperCase() == obj1.value.toUpperCase() || obj3.value.toUpperCase() == obj2.value.toUpperCase() || obj3.value.toUpperCase() == obj4.value.toUpperCase() || obj3.value.toUpperCase() == obj5.value.toUpperCase() || obj3.value.toUpperCase() == obj6.value.toUpperCase() || obj3.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj3.focus();
			return false;
		}
	if(obj4.value.length != 0)
		if(obj4.value.toUpperCase() == obj1.value.toUpperCase() || obj4.value.toUpperCase() == obj2.value.toUpperCase() || obj4.value.toUpperCase() == obj3.value.toUpperCase() || obj4.value.toUpperCase() == obj5.value.toUpperCase() || obj4.value.toUpperCase() == obj6.value.toUpperCase() || obj4.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj4.focus();
			return false;
		}
	if(obj5.value.length != 0)
		if(obj5.value.toUpperCase() == obj1.value.toUpperCase() || obj5.value.toUpperCase() == obj2.value.toUpperCase() || obj5.value.toUpperCase() == obj3.value.toUpperCase() || obj5.value.toUpperCase() == obj4.value.toUpperCase() || obj5.value.toUpperCase() == obj6.value.toUpperCase() || obj5.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj5.focus();
			return false;
		}
	if(obj6.value.length != 0)
		if(obj6.value.toUpperCase() == obj1.value.toUpperCase() || obj6.value.toUpperCase() == obj2.value.toUpperCase() || obj6.value.toUpperCase() == obj3.value.toUpperCase() || obj6.value.toUpperCase() == obj4.value.toUpperCase() || obj6.value.toUpperCase() == obj5.value.toUpperCase() || obj6.value.toUpperCase() == obj7.value.toUpperCase())
		{
			alert(msg);
			obj6.focus();
			return false;
		}
	if(obj7.value.length != 0)
		if(obj7.value.toUpperCase() == obj1.value.toUpperCase() || obj7.value.toUpperCase() == obj2.value.toUpperCase() || obj7.value.toUpperCase() == obj3.value.toUpperCase() || obj7.value.toUpperCase() == obj4.value.toUpperCase() || obj7.value.toUpperCase() == obj5.value.toUpperCase() || obj7.value.toUpperCase() == obj6.value.toUpperCase())
		{
			alert(msg);
			obj7.focus();
			return false;
		}
	return true;
}


function openwindow(strURL, strTitle )
{
	t=window.open(strURL , strTitle , "width=775,height=600,resizable=yes,pixelx=0,pixely=0,screenx=0,screeny=0,scrollbars=1,border=0,z-lock=no");
}

function endwin()
{
	t.close();
}
function detwin(){
	alert(window.name)	
}

function protectrightclick()
{	
	var cnt=0;
	if(!document.all)
		window.captureEvents(Event.MOUSEDOWN|Event.KEYDOWN);
	
	function clkhan(evnt){
		if(document.all){
			if(event.button==2){
				alert("Please follow the links to continue.");
				return false;
			}			
		}
		else{
			
				if(evnt.which==3)
				{
					return false;
				}	
			
		}	
	}
	function keyhan(evnt){
			alert("Please follow the links to continue.");
			return false;
	}
	
		
	document.onmousedown=clkhan;
	document.onkeydown=keyhan;
		
	window.onkeydown=keyhan;
	window.onmousedown=clkhan;
}	

	
function vemail(obj)
{
	var stp = obj.value;
	if(stp.length > 0)
	{ 
	  if(stp.indexOf("@") == -1 || stp.indexOf(".") == -1)
	 	{
			alert("The format of your e-mail ID is incorrect.\n Please enter the correct format for your e-mail ID.");
		    obj.focus();
			return false; 	
	     }
	}
 	 return true;
}

function goBack()
{
	history.go(-1);
}


function calc(obj, paSelectedIndex)
{
	var val = obj.sites.options[paSelectedIndex].value;
	obj.total.value = (199 * val);
}

function checkFont(obj)
{
	var msg = "";
	obj.cname.value = trimchar(obj.cname.value, " ");
	obj.cslogan.value = trimchar(obj.cslogan.value, " ");
	if(obj.cname.value.length > 40 && obj.cfontsize.options[obj.cfontsize.selectedIndex].value == 18) 
	{
		msg = "Your company name is too long.\n";
	}
	if(obj.cslogan.value.length > 40 && (obj.sfontsize.options[obj.sfontsize.selectedIndex].value == 11 || obj.sfontsize.options[obj.sfontsize.selectedIndex].value == 10)) 
	{
		msg = msg + "Your slogan is too long.\n";
	}
	if (msg.length != 0)
	{
		msg =msg + "We advice you to reduce the fontsize.\nWould you like to rectify?";
		return !confirm(msg);
	}
	return true;
}


function askForConfirm(pastr)
{
	if (confirm("Your entire work till now will be eliminated.\n Would you still like to continue?")==true)
	{
		var str = "\"" + pastr + "\"";	
		//alert(str);
		location.href = pastr;
	
		return true;
	}
	
}