function FrontPage_Form1_Validator(theForm)
{

    	if (theForm.user.value == "")
  		{
   			 alert("Enter username !");
   			 theForm.user.focus();
    		 return (false);
  		}
  
      	if (theForm.pass.value == "")
  		{
    		alert("Enter Password !");
   			theForm.pass.focus();
   			 return (false);
  		}
		//window.FrontPage_Form1.submit();
		 return (true);
}
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function getRadioValue(RadioName)
{
var colRadio = document.getElementsByName(RadioName);
	for (var i = 0; i < colRadio.length; i++)
	{
		if (colRadio[i].checked)
		{
			return colRadio[i].value;
		}
	}
	return null;

}

function dochange2()
	{
	var type=getRadioValue("type");
	//mytype=document.myform.mytype.value;

	myPage=document.getElementById("spage").value;
	window.location.href=myPage+"?type="+type
	}
	
	
function openwin(col)
{

mywin= open("edit.php?col="+col, "DisplayWindow", 
    "width=400,height=200,status=no,toolbar=no,menubar=no,scrollbars=yes");
}

function check()
	{
		if(trim(document.myform.country.value)=="0")
			{
				alert("Select Country First!!");
				return false;
			}
		if(trim(document.myform.aname.value)=="")
			{
				alert("Insert Name!!");
				return false;
			}
	}
	
function checkadd()
	{
		if(trim(document.myform.country.value)=="0")
			{
				alert("Select Country First!!");
				return false;
			}
		if(trim(document.myform.cat.value)=="0")
			{
				alert("Select Category!!");
				return false;
			}
			
		if(trim(document.myform.title.value)=="")
			{
				alert("Insert News Title!!");
				return false;
			}
document.myform.method="post";			
document.myform.action="news_.php";

return true;
	}
	

	
function checkdel()
	{
		if(confirm("you are about to remove this Country From Favorite Countries"))
			{
				document.myform.action="country_.php?action=delete";
				return true;
			}
			else
			{
				return false;
			}
	}
function chkdel(action,id,country,cat,year,month,day,Search)
	{
		
		if(confirm("you are about to delete this piece of news"))
			{
				
				window.location.href="news_.php?action="+action+"&id="+id+"&country="+country+"&cat="+cat+"&year="+year+"&month="+month+"&day="+day+"&Search="+Search;
			}

	}
	
	
function fill(selectid)
	{
		if(document.getElementById("type"))
			{
	var type=getRadioValue("type");
	myPage=document.getElementById("spage").value;
	window.location.href=myPage+"?type="+type+"&myid="+document.getElementById(selectid).value;
			}
	}
	
function addInput4(tId,ptitle,pdet,Img) {

var gFiles=0;
   var x= document.myform.elements.length
   var myno=x-1;
   myname=pdet+"[]";
//   if(document.getElementsByName( myname))
//   	{
counter=document.getElementsByName(myname).length;
//	}
  
		
    var tr = document.createElement('tr');
    tr.setAttribute('id', tId + counter);
    var td = document.createElement('td');
	td.className='box';



    td.innerHTML = '<table width="100%"><tr><td colspan="2">&nbsp;</td></tr></tr><TR><td align="right">Title </td><td align="left"><input type="text" name="'+ptitle+'[]" ></td></TR><TR><td align="right" valign="top">Details</td><td align="left"><textarea name="'+pdet+'[]" cols="40" rows="3"></textarea></td></TR><TR><td align="right">Image  </td><td align="left"><input type="file"  name="'+Img+'[]"></td></TR><tr><td colspan="2"><a href="javascript:removeInput(\''+tId+ counter + '\' )"  >Remove</a></td></tr></table>';
    tr.appendChild(td);
    document.getElementById(tId).appendChild(tr);
    gFiles++;
}

function removeInput(aId,tId) {
    var obj = document.getElementById(aId);
	
    obj.parentNode.removeChild(obj);
}


function chksearch()
	{
		
		if(trim(document.myform.country.value)=="0")
			{
				alert("Select Country First!!");
				return false;
			}
		if(trim(document.myform.cat.value)=="0")
			{
				alert("Select Category!!");
				return false;
			}
			
		if(trim(document.myform.year.value)=="0")
			{
				alert("Select Year!!");
				return false;
			}
		if(trim(document.myform.month.value)=="0")
			{
				alert("Select Month!!");
				return false;
			}
	}
function chkEdit()
	{
		if(trim(document.myform.country.value)=="0")
			{
				alert("Select Country First!!");
				return false;
			}
		if(trim(document.myform.cat.value)=="0")
			{
				alert("Select Category!!");
				return false;
			}
			
		if(trim(document.myform.title.value)=="")
			{
				alert("Insert News Title!!");
				return false;
			}	
	}
	
	
function checkOrder()
{
	//alert();
	

		if(document.form2.elements['myspan[]'])
			{
				
				if(document.form2.elements['myspan[]'].length>0)
					{
						
						for (i=0;i<document.form2.elements['myspan[]'].length;i++)
						{
		
								document.form2.myhidden.value += document.form2.elements['myspan[]'][i].id +",";
								//alert(document.form2.myhidden.value);
							//	return false;
													
						}
						return true
						
					}
				
			}
}

function checkreg()
	{
		if(trim(document.myform.textfield.value)=="")
			{
				alert("Insert Name!!");
				return false;
			}	
		if(trim(document.myform.textfield2.value)=="")
			{
				alert("Insert Email!!");
				return false;
			}
						var x=document.myform.textfield2.value;
						var y= x.indexOf("@",1);
						var len=x.length;
					if (x=="" || x.indexOf("@",1)==-1 || x.indexOf(".",y)==-1|| x.charAt(len-1)==".")
					{			
						alert("your email is incorrect !");
						document.myform.textfield2.focus();
						return (false) ;
					 }
			
		if(trim(document.myform.homeland.value)=="0")
			{
				alert("Select Nationality!!");
				return false;
			}
		
	}
