// JavaScript Document
function WindowOpen(img,width,height) 
{
wind=window.open("","","width="+width+",height="+height+"");
wind.document.write("<html></html><body><a href=\"javascript:window.close();\"><img src=\""+img+"\" border=\"0\" /></a></body></html>");
}
function DelAccept(WarningTxt)
{
if(confirm(WarningTxt))
return true;
else
return false;
}
function SelectRec(checkflag,id)
{
FormToSelect=document.getElementById(id);
if(checkflag=="y")
{
for(i=0;i<FormToSelect.length;i++)
{
if(FormToSelect[i].type=="checkbox")
FormToSelect[i].checked=true;
}
checkflag="n";
}
else
{
for(i=0;i<FormToSelect.length;i++)
{
if(FormToSelect[i].type=="checkbox")
FormToSelect[i].checked=false;	
}
checkflag="y";
}
return checkflag;
}
function DataValidate(id)
{
var FormToCheck=document.getElementById(id);
var NoCheck='image,long_descr,lng_des,featured,pdf';
for(var i=0;i<FormToCheck.length;i++)
{
	if(NoCheck.indexOf(FormToCheck[i].name)==-1&&FormToCheck[i].value=='')
	{
	alert('Please fill in required field'+FormToCheck[i].name);
	FormToCheck[i].focus();
	return false;
	}
	else if(FormToCheck[i].name=='email'&&!/^([a-z0-9_-]+([.a-z0-9_-]+)*)@([a-z0-9_-]{1,}(.[a-z0-9_-]{1,})*.[a-z]{2,3})$/.test(FormToCheck[i].value))
	{
	alert('Please check your email address');
	FormToCheck[i].focus();
	return false;
	}
}
}

function PopulateData(id,name,results_id)
{
	FieldToComplete=document.getElementById(id);
	if(results_id!="") {
		document.getElementById(results_id).style.display="none";
	}
	opt="";
	OpCount=0;
	FieldToComplete.options.length=OpCount;
	FieldToComplete.options[0]=new Option("--Select Country--","");
	OpCount++;	
	name = name.replace('&', '&amp;');
	for(i=0;i<data.length;i++)
	{
		opt=data[i].split("|");	
		if(opt[0]==name)
		FieldToComplete.options[OpCount++]=new Option(opt[1],opt[1]);
	}
}

function MapHandle(id,id1,county_id,form_id,name)
{
if(name=='UK')
{
//document.getElementById(id).style.display="block";
//document.getElementById(id1).style.display="none";
document.getElementById("map_mode").value="uk";
document.getElementById(county_id).value="";
document.getElementById(form_id).submit();
}
else if(name=='Ireland')
{
//document.getElementById(id).style.display="none";
//document.getElementById(id1).style.display="block";	
document.getElementById("map_mode").value="ireland";
document.getElementById(county_id).value="";
document.getElementById(form_id).submit();
}
else
{
document.getElementById(id).style.display="none";
document.getElementById(id1).style.display="none";
document.getElementById(county_id).value="";
document.getElementById(form_id).submit();
}
}
function CountySelect(county_id,form_id,name)
{
document.getElementById(county_id).value=name;
document.getElementById(form_id).submit();
}
function CountryAdd(form_id,sector,sector_id)
{
document.getElementById(sector).value=sector_id;
document.getElementById(form_id).submit();
}
function CountryTransform(id,name,country_val)
{
FieldToComplete=document.getElementById(id);
OpLength=FieldToComplete.options.length;
opt="";
OpCount=0;
OpCount=document.getElementById(id).length
OpAdd=1;
for(i=0;i<OpLength;i++)
{
if(FieldToComplete.options[i].text==name)
OpAdd=0;
}
if(OpAdd==1)
FieldToComplete.options[OpLength]=new Option(name,country_val);
}
function CountryRemove(id)
{
FieldToRemove=document.getElementById(id);	
OpLength=FieldToRemove.options.length;
for(i=0;i<OpLength;i++)
{
if(FieldToRemove.options[i].selected)
FieldToRemove.remove(i);	
}
}
function SelectAll(form_id,id)
{
FieldToSelect=document.getElementById(id);	
OpLength=FieldToSelect.options.length;	
for(i=0;i<OpLength;i++)
{
FieldToSelect.options[i].selected=true;
}
document.getElementById(form_id).submit();
}
function DealerPopulate(id,name,num,sub_name,txt)
{
FieldToComplete=document.getElementById(id);
opt="";
OpCount=0;
FieldToComplete.options.length=OpCount;
FieldToComplete.options[0]=new Option(txt,"");
OpCount++;
if(sub_name=='')
{
for(i=0;i<data.length;i++)
{
opt=data[i].split("|");	
if(opt[num]==name)
{
NoAdd=0;
for(j=0;j<FieldToComplete.options.length;j++)
{
if(opt[num+1]==FieldToComplete.options[j].text)
NoAdd=1;
}
if(NoAdd==0&&opt[num+1]!='')
FieldToComplete.options[OpCount++]=new Option(opt[num+1],opt[num+1]);
}
}
}
else
{
for(i=0;i<data.length;i++)
{
opt=data[i].split("|");	
if(opt[num]==name&&opt[num-1]==sub_name)
{
NoAdd=0;
for(j=0;j<FieldToComplete.options.length;j++)
{
if(opt[num+1]==FieldToComplete.options[j].text)
NoAdd=1;
}
if(NoAdd==0&&opt[num+1]!='')
FieldToComplete.options[OpCount++]=new Option(opt[num+1],opt[num+1]);
}
}
}	
}
function EmailValidate(id)
{
email=document.getElementById(id);
if(!/^([a-z0-9_-]+([.a-z0-9_-]+)*)@([a-z0-9_-]{1,}(.[a-z0-9_-]{1,})*.[a-z]{2,3})$/.test(email.value)&&email.value!='')
{
alert('Please check your email address');
email.focus();
return false;	
}
}
function CategorySelect(fld_id,id,id_pos)
{
var fld_to_pop = document.getElementById(fld_id);
var opt="";
var OpCount=0;
var NoAdd=0;
fld_to_pop.options.length=OpCount;
fld_to_pop.options[0]=new Option("--Please Select--","");
OpCount++;
for(i=0;i<data.length;i++)
{
opt=data[i].split("|");	
if(opt[id_pos]==id && opt[id_pos+2] && opt[id_pos+3])
{
for(j=0;j<fld_to_pop.options.length;j++)
{
if(fld_to_pop.options[j].value==opt[id_pos+2])
NoAdd=1;
}
if(NoAdd==0)
fld_to_pop.options[OpCount++]=new Option(opt[id_pos+3],opt[id_pos+2]);
NoAdd=0;
}
}
}
function ProductSelect(field, SelectedVal)
{
var fld_to_populate = document.getElementById(field);
var opt="";
var OpCount=0;
fld_to_populate.options.length=OpCount;
fld_to_populate.options[0]=new Option("--Please Select--","");
OpCount++;
for(i=0;i<data.length;i++)
{
opt=data[i].split("|");	
	if(opt[0]==SelectedVal) {
	fld_to_populate.options[OpCount++]=new Option(opt[2],opt[1]);
	}
}
}
function CatShow(curr,num_cats)
{	
var total=document.getElementById(num_cats).value;
for(var i=1;i<=total;i++)
{
if(i==curr)
{
	document.getElementById('cat_link_'+i).className="active";
	if (checkobject('cat_'+i)) {		
		document.getElementById('cat_'+i).style.display="block";
	}
	document.getElementById('cat_m_'+i).style.display="block";
}
else
{
	if (checkobject('cat_'+i)) {
//  		alert("This object exists");
		document.getElementById('cat_'+i).style.display="none";	
	}
	else {
//  		alert("This object DOESNT exists: " + 'cat_'+i);
	}	
	
	document.getElementById('cat_link_'+i).className="notactive";
	document.getElementById('cat_m_'+i).style.display="none";
}
}
}
function CatShow1(curr,total)
{	
for(var i=1;i<=total;i++)
{
if(i==curr)
{
	document.getElementById('cat_link_'+i).className="active";

	if (checkobject('cat_'+i)) {
		document.getElementById('cat_'+i).style.display="block";
	}
	else {
//  		alert("This object DOESNT exists: " + 'cat_'+i);		
	}	
	
	document.getElementById('cat_m_'+i).style.display="block";
}
else
{
	document.getElementById('cat_link_'+i).className="notactive";
	
	if (checkobject('cat_'+i)) {
		document.getElementById('cat_'+i).style.display="none";		
	}
	else {
 // 		alert("This object DOESNT exists: " + 'cat_'+i);		
	}
	
	document.getElementById('cat_m_'+i).style.display="none";
}
}
}
function SubCatHande(subcat_id)
{
document.location="#subcat_"+subcat_id;	
}
function TestValidate(id) {

		var fields="name,testimonial";
		var ToCheck = document.getElementById(id);
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			for( var i=0;i<ToCheck.length;i++ )
			{
				if( fields.indexOf(ToCheck[i].name)!=-1 && ToCheck[i].value == '' )
				{
				alert("Please fill in required field");
				ToCheck[i].focus();
				return false;
				}
				if( ToCheck[i].name=="email" && ToCheck[i].value!="" && !filter.test( ToCheck[i].value ) )
				{
				alert("Your email address seems to be invalid.");
				ToCheck[i].focus();
				return false;
				}
			}
			return true;

}

function CheckTestCat(id) {
var fields="cat_name";
var ToCheck = document.getElementById(id);

for( var i=0;i<ToCheck.length;i++ )
{
	if( fields.indexOf(ToCheck[i].name)!=-1 && ToCheck[i].value == '' )
	{
	alert("Please fill in required field");
	ToCheck[i].focus();
	return false;
	}
}
return true;
}

function checkobject(obj) {
	if (document.getElementById(obj)) { return true; } else { return false; }
}
