  var validtime = 0
	var NORMAL_STATE=4;
	//Trim the string
    function TrimString(sInString) {
	sInString = sInString.replace( /^\s+/g, "" );
	return sInString.replace( /\s+$/g, "" );
    }
    
	

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
	
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

    //function to Check Empty
    function IsEmpty(fld,mesg)
    {

		
		reg = / /g;
        str = fld.value;
        
		res = str.replace(reg,""); 
       
		if(res == "")
        {
            
			alert(mesg);
            fld.value="";
            fld.focus();
            return false;
        }		
        return true;
    }
    
    function IsEmptyNoFocus(fld,mesg)
        {
    		reg = / /g;
            str = fld.value;
            
    		res = str.replace(reg,""); 
           
    		if(res == "")
            {
                
    			alert(mesg);
                fld.value="";
                return false;
            }		
            return true;
    }

  
     function IsZero(fld,mesg)
      {
  		
          str = fld.value;
 	if(str == "0")
          {
              
  			alert(mesg);
              fld.value="";
  			fld.focus();
              return false;
          }		
          return true;
      }

  
  
    //function to Check email
    // opt value 0 if mandatory and 1 if not
    function CheckEmail(fld,msg,opt)  { 
	
    	if(opt=="0" || fld.value!="")
    	{
            var emailStr=fld.value;
        	var checkTLD=1;
        	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
        
        	var emailPat=/^(.+)@(.+)$/;        
        	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";        
        	var validChars="\[^\\s" + specialChars + "\]";        
        	var quotedUser="(\"[^\"]*\")";        
        	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;        
        	var atom=validChars + '+';        
        	var word="(" + atom + "|" + quotedUser + ")";        
        	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");        
        	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");     
        	var matchArray=emailStr.match(emailPat);    
        	if (matchArray==null)
        	{
        		
                fld.focus();
        		fld.select();
        		alert(msg);
        		return false;
        	}
            
        	var user=matchArray[1];
        	var domain=matchArray[2];
    
        	for (i=0; i<user.length; i++) 
            {
            	if (user.charCodeAt(i)>127) 
                {
                	fld.focus();
                	fld.select();
                	alert(msg);
                	return false;
        	    }
        	}
    	
            for (i=0; i<domain.length; i++) 
            {
            	if (domain.charCodeAt(i)>127) 
                {
                	fld.focus();
                	fld.select();
                	alert(msg);
                	return false;
            	}
        	}
    
        	// See if "user" is valid 
        
        	if (user.match(userPat)==null) 
            {
        
        	// user is not valid
        	fld.focus();
        	fld.select();
        	alert(msg);
        	return false;
        	}
        
        	var IPArray=domain.match(ipDomainPat);
        	if (IPArray!=null) 
        	{
            	for (var i=1;i<=4;i++) 
                {
                	if (IPArray[i]>255) 
                    {
                    	fld.focus();
                    	fld.select();
                    	alert(msg);
                    	return false;
                	}
            	}
        	    return true;
        	}
    
    
        	var atomPat=new RegExp("^" + atom + "$");
        	var domArr=domain.split(".");
        	var len=domArr.length;
        	for (i=0;i<len;i++)
            {
            	if (domArr[i].search(atomPat)==-1) 
                {
                	fld.focus();
                	fld.select();
                	alert(msg);
                	return false;
            	}
        	}
    
        	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
            {
            	fld.focus();
            	fld.select();
            	alert(msg);
            	return false;
        	}
    
        	if (len<2) 
            {
            	fld.focus();
            	fld.select();
            	alert(msg);
            	return false;
        	}
    	    return true;
        }
        return true; 		
		
    }
	
	////////////////////////////////////////////////////////

    //function to Check Phone
    function CheckPhone(fld1)
    {
    	
        if(isNaN(fld1.value)==true)
        {
    		alert('Telephone number can contain numeric values only.');
    		fld1.focus();
    		fld1.select();
    		return false;
        }
        if(fld1.value.length!=10)
        {
    		alert('Telephone number should be of 10 digits.');
    		fld1.focus();
    		fld1.select();
    		return false;
        }
        return true;
    }

    function CheckUSPhone(fld1)
    {
    	
        if(isNaN(fld1.value)==true)
        {
    		alert('Telephone number can contain numeric values only.');
    		fld1.focus();
    		fld1.select();
    		return false;
        }
        if(fld1.value.length!=10)
        {
    		alert('Telephone number should be of 10 digits.');
    		fld1.focus();
    		fld1.select();
    		return false;
        }
        return true;
    }


    function userLoginValidate(userName,userPass)
    {
    
    	
		if(!IsEmpty(userName,"Please enter your ‘username‘ in the space provided"))
    	{
    	
			return false;
    	};
    
/*
    	if(!CheckEmail(userName,"Please enter your ‘username‘ in the space provided",0))
    	{
    		return false;
    	};
*/
    
    	if(!IsEmpty(userPass,"Please enter your ‘password‘ in the space provided"))
    	{
    		return false;
    	};
    }

    function isUrl(s,mesg)
    {
        var regexp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/
        return regexp.test(s);
    }

    
    function CheckUrl(fld,mesg)
    {
        var urlStr =   fld.value;
        
        var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;

        if (urlRegxp.test(urlStr))
        {
        }
        else
        {
            alert("Please Enter Valid Url");
            return false;
        } 
    	return true;
    }
	
	/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}


    function CheckDate(yf,mf,df,msg)
    {
    	// mandatory check
    	if(!IsEmpty(df,msg))return false;
    	if(!IsEmpty(mf,msg))return false;
    	if(!IsEmpty(yf,msg))return false;
    	// numeric check
    	if(!IsNumber(df,msg))return false;
    	if(!IsNumber(mf,msg))return false;
    	if(!IsNumber(yf,msg))return false;
    
    	if(mf.value==1 || mf.value==3 || mf.value==5 || mf.value==7 || mf.value==8 || mf.value==10 || mf.value==12) 
    	{
    		if(df.value>31)
    		{
    			alert(msg);
    			df.focus();
    			return false
    		}
    	}
    	else if(mf.value==2)
    	{
    		if (((yf.value % 4)==0) && ((yf.value % 100)!=0) || ((yf.value % 400)==0))
    		{
    			if(df.value>29)
    			{
    				alert(msg);
    				mf.focus();
    				return false
    			}
    		}
    		else if(df.value>28)
    		{
    			alert(msg);
    			mf.focus();
    			return false
    		}
    	}
    	else if(df.value>30)
    	{
    		alert(msg);
    		mf.focus();
    		return false
    	}
    	return true;
    }

    function IsNumber(fld,msg)
    {
    	if(isNaN(fld.value)==true)
    	{
    		alert(msg);
    		fld.focus();
    		fld.select();
    		return false;
    	}
        return true;
    }  

    function ComparePassword(pass,confPass)

    {

    	
    	if(pass.value != confPass.value)
	{
		alert("The password entered in the 'Confirm Password' field does \nnot match with new password.");
		confPass.focus();
		confPass.select();
		return false;
	}
	return true;
     }


   function isAlphanumeric(fld, ignoreWhiteSpace, msg) {
   	if (fld.value.search) {
   	   if ((ignoreWhiteSpace && fld.value.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && fld.value.search(/\W/) != -1)) 
	   {
		  fld.focus();
		  alert(msg);
		  fld.select();
		  return false;
	   }
   	}
   	return true;
   }

   function IsCharacter(field, msg) {
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var ok = "yes";
	var temp;
	var val = field.value;
	for (var i=0; i<val.length; i++) {
		temp = "" + val.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}
	return true;
   }


   function IsCatZero(fld1, fld2) {
      	     str = fld1.value;
      	     if(str == "0")
      	     {
      		   if(!IsEmpty(fld2,"Please Enter New Category name"))
      		    {		       			
      			return false;
      		    }	
      	     }		
      	     return true;
   }
   
   function CheckPassword(fld1)
   {
   	if(fld1.value.length < 5 || fld1.value.length > 20)
           {
       		alert('Password should be of minimum 5 and maximum of 20 characters long.');
       		fld1.focus();
       		fld1.select();
       		return false;
           }
           return true;
       }
  
  function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
  	}
  }

  function IsPassword(fld,ignoreWhiteSpace,msg){
	if (fld.value.search) {
		if ((ignoreWhiteSpace && fld.value.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && fld.value.search(/\W/) != -1)) 
		{
		fld.focus();
		alert(msg);
		fld.select();
		return false;
		}
		else if(fld.value.length<4)
		{
			fld.focus();
			alert("You cannot give less than 4 characters");
			fld.select();
			return 	false;
		}

	}
	return true;	 
  }
  
  function confirm_delete()
  {
  	option=window.confirm("Are you sure to delete this item?");
  	if(option)
  	{
  	}
  	else
  	{
  		window.event.returnValue=false;
  	}
 }
 function IsValidTime(timeStr,stop)
 {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 12) {
alert("Hour must be between 0 and 12.");
return false;
}
if (ampm == null) {
	
alert("You must specify AM or PM.");
return false;
  }
/*
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}*/
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;

}



  var OpenWindows = new Object();
  function OpenWin(sPath, w, h) {
	l = (screen.width - w)/2-5;
	t = (screen.height - h)/2-20;
	if (l < 1) l=0;
	if (t < 1) t=0;
	sWindowName = "mainwin_" + w + "_" + h;
  	if(OpenWindows[sWindowName]) {
  	  if(!OpenWindows[sWindowName].closed) OpenWindows[sWindowName].close();
  	}
	OpenWindows[sWindowName] = window.open(sPath, sWindowName, "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",scrollbars=no,menubar=no,toolbars=no,status=no");
	return OpenWindows[sWindowName];
  }


/*
function moveAllGroups(choiceForm)
{
var boxLength2=	choiceForm.gravailable.length;

var i,j;
for(j=0;j<boxLength2;j++)
{	var isNew=true;
	var newoption="";
	var boxLength = choiceForm.grChoiceBox.length;
	if (boxLength != 0)
		{
		for (i = 0; i < boxLength; i++)
		{
			thisitem = choiceForm.grChoiceBox.options[i].text;
			if (thisitem == choiceForm.gravailable.options[j].text)
			{
				isNew = false;
			}
		}
	}
	if (isNew==true)
	{
		newoption = new Option(choiceForm.gravailable.options[j].text, choiceForm.gravailable.options[j].value, false, false);
		choiceForm.grChoiceBox.options[boxLength] = newoption;
	}

}
choiceForm.gravailable.selectedIndex=-1;
saveFacility(choiceForm);
}
*/

function moveGroup(choiceForm)
{
var err=0;
	for(var j=0;j< choiceForm.gravailable.length;j++)
	{
	   if (choiceForm.gravailable.options[j].selected==true)
		{
			err=err+1;
		}
	}
	if(err==0)
	{
		alert("Please select group first");
		return false;
	}

	var boxLength2=	choiceForm.gravailable.length;

	var i,j;
	for(j=0;j<boxLength2;j++)
	{	var isNew=true;
		var newoption="";
		var boxLength = choiceForm.grChoiceBox.length;
		if(choiceForm.gravailable.options[j].selected==true)
		{
			if (boxLength != 0)
			{
				for (i = 0; i < boxLength; i++)
				{
					thisitem = choiceForm.grChoiceBox.options[i].text;
					if (thisitem == choiceForm.gravailable.options[j].text)
					{
						isNew = false;
					}
				}
			}
			if (isNew==true)
			{
				newoption = new Option(choiceForm.gravailable.options[j].text, choiceForm.gravailable.options[j].value, false, false);
				choiceForm.grChoiceBox.options[boxLength] = newoption;
			}
		}
	}
	choiceForm.gravailable.selectedIndex=-1;
	saveFacility(choiceForm);
}

function removeGroup(choiceForm) 
{
	var boxLength = choiceForm.grChoiceBox.length;
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++) 
	{
		if (choiceForm.grChoiceBox.options[i].selected) 
		{
			arrSelected[count] = choiceForm.grChoiceBox.options[i].value;
		}
		count++;
	}
	var x;
	for (i = 0; i < boxLength; i++) 
	{
		for (x = 0; x < arrSelected.length; x++) 
		{
			if (choiceForm.grChoiceBox.options[i].value == arrSelected[x]) 
			{
				choiceForm.grChoiceBox.options[i] = null;
   			}
		}

		boxLength = choiceForm.grChoiceBox.length;
	}
 	saveFacility(choiceForm);
}

/*
function removeAllGroups(choiceForm)
{
	var boxLength = choiceForm.grChoiceBox.length;
	var i=0;
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++)
		{
			if (choiceForm.grChoiceBox.options[i])
				{
					arrSelected[count] = choiceForm.grChoiceBox.options[i].value;
				}
			count++;
		}

	var x;
	for (i = 0; i < boxLength; i++)
		{
			for (x = 0; x < arrSelected.length; x++)
				{
					if (choiceForm.grChoiceBox.options[i].value == arrSelected[x])
						{
							choiceForm.grChoiceBox.options[i] = null;
						}
				}

			boxLength = choiceForm.grChoiceBox.length;
	 }
	saveFacility(choiceForm);
}
*/



function saveFacility(choiceForm)
{
	var strValues = "";
	var boxLength = choiceForm.grChoiceBox.length;
	var count = 0;
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			if (count == 0) {
				strValues = choiceForm.grChoiceBox.options[i].value;
				strTexts = choiceForm.grChoiceBox.options[i].text;
			}
			else {
				strValues = strValues + "," + choiceForm.grChoiceBox.options[i].value;
				strTexts = strTexts + "," + choiceForm.grChoiceBox.options[i].text;
			}
			count++;
   		}
	}
	choiceForm.grarr.value=strValues;

}

function verifyIP (IPvalue) {
errorString = "";
theName = "IPaddress";

var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = IPvalue.match(ipPattern); 

if (IPvalue == "0.0.0.0")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
else if (IPvalue == "255.255.255.255")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
if (ipArray == null)
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
else {
for (i = 0; i < 4; i++) {
thisSegment = ipArray[i];
if (thisSegment > 255) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
i = 4;
}
if ((i == 0) && (thisSegment > 255)) {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
i = 4;
      }
   }
}
extensionLength = 3;
if (errorString == "")
return true;
else
	{
return false;
	}

}
function del()
{
	var stay=window.confirm("Are You sure! You want to delete this record. Press OK to continue or Cancel to go back.");
	if (stay)
		return true;
	else
		return false;
}
function OpenBrWindow(theURL,winName,features) {
	var leftPlus	=	(screen.width-700)/2
	var topPlus		=	(screen.height-400)/2

  window.open(theURL,winName,features+',Left='+leftPlus+',Top='+topPlus);
}
function FileUploadValid(field,msg) 
{
	var msg="";
if(field.value != '')
	{
if((field.value.lastIndexOf(".jpg")==-1) && (field.value.lastIndexOf(".JPG")==-1) && (field.value.lastIndexOf(".jpeg")==-1) && (field.value.lastIndexOf(".JPEG")==-1) && (field.value.lastIndexOf(".png")==-1) && (field.value.lastIndexOf(".PNG")==-1) && (field.value.lastIndexOf(".gif")==-1) && (field.value.lastIndexOf(".GIF")==-1))
	{
   alert('Please upload jpg/jgeg, gif or png file only.	');
   field.select();
   return false;
	}
	}
	return true;
}
function CreateRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = CreateRequestObject(); 

function ValidateCustNo()
{
	if(document.PurchaseOrder.custno.value != '')
	{
		http.open('get','validatecust.php?&cust_no='+document.PurchaseOrder.custno.value,true);
		http.onreadystatechange = handleHttpgetItem; 
		http.send(null);
	}
	
}


function countryDropDown(regId,c_id)
{
	  http.open("get","getCountryList.php?region_id="+regId+"&sel="+c_id,true)
	  http.onreadystatechange = handleHttpgetItem; 
	  http.send(null);	

}
function countryDropDown1(c_id)
{
	  http.open("get","getCountryList1.php?sel="+c_id,true)
	  http.onreadystatechange = handleHttpgetItem_1; 
	  http.send(null);	

}


function cityDropDown(countId, city_id)
{
	  http.open("get","getCityList.php?count_id="+countId+"&sel="+city_id, true)
	  http.onreadystatechange = handleHttpgetItem2; 
	  http.send(null);	

}
function cityDropDown1(countId, city_id)
{
	  http.open("get","getCityList1.php?count_id="+countId+"&sel="+city_id,true)
	  http.onreadystatechange = handleHttpgetItem2_1; 
	  http.send(null);	

}

function showEditImage(im_id,option,name,id)
{
	http.open("get","getImage.php?option="+option+"&image="+im_id+"&name="+name+"&id="+id,true)
	  http.onreadystatechange = handleHttpgetItem1; 
	  http.send(null);	

}

function handleHttpgetItem1()
{
 if (http.readyState == NORMAL_STATE) {
  getImageReady();
//  hasSeed = true;
 }
}

function getImageReady()
{
var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
if(strResponseArray[3] == '1')
	{
	document.getElementById("image_to_show").innerHTML = strResponseArray[0];
	document.getElementById('EDIT').style.display = "";
	document.getElementById("region_name_edit").value = strResponseArray[1];
	document.getElementById('ADD').style.display = "none";
	document.getElementById('region_id_edit').value = strResponseArray[2];
	}
else if(strResponseArray[3] == '2')
	{
	document.getElementById("image_to_show").innerHTML = strResponseArray[0];
	document.getElementById('EDIT').style.display = "";
	document.getElementById('ADD_COUNT').style.display = "none";
	document.getElementById("country_name_edit").value = strResponseArray[1];
	document.getElementById('count_id').value = strResponseArray[2];
	
	}
else if(strResponseArray[3] == '3')
	{
	document.getElementById('EDIT').style.display = "";
	document.getElementById('ADD_CITY').style.display = "none";
	document.getElementById("city_name_edit").value = strResponseArray[1];
	document.getElementById("city_id").value =  strResponseArray[2];
	document.getElementById("image_to_show").innerHTML =strResponseArray[0];
	regionDropDown(strResponseArray[2])

	}
}



function handleHttpgetItem()
{
 // if there hasn't been any errors
 if (http.readyState == NORMAL_STATE) {
  getCountryList();
//  hasSeed = true;
 }
}

function handleHttpgetItem_1()
{
 // if there hasn't been any errors
 if (http.readyState == NORMAL_STATE) {
  getCountryList1();
//  hasSeed = true;
 }
}

function handleHttpgetItem2()
{
	if (http.readyState == NORMAL_STATE) {
	getCityList();
}
}

function handleHttpgetItem2_1()
{
	if (http.readyState == NORMAL_STATE) {
	getCityList1();
}
}

function handleHttpgetItem3()
{
	if (http.readyState == NORMAL_STATE) {
	addcurrency_();
}
}
function handleHttpgetItem4()
{
	if (http.readyState == NORMAL_STATE) {
	adddifficulty_();
}
}
function handleHttpgetItem5()
{
	if (http.readyState == NORMAL_STATE) {
	addregion_();
}
}
function handleHttpgetItem6()
{
	if (http.readyState == NORMAL_STATE) {
	addcountry_();
}
}
function handleHttpgetItem7()
{
	if (http.readyState == NORMAL_STATE) {
	addcity_();
}
}
function handleHttpgetItem8()
{
	if (http.readyState == NORMAL_STATE) {
	addtriptype_();
}
}

function addcurrency_()
{
var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("currency_id")
	selectElement.options.length = 0;
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}


}

function adddifficulty_()
{
var response = http.responseText;

var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("difficult_id")
	selectElement.options.length = 0;
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}



}

function addregion_()
{
	var response = http.responseText;
var strResponseArray = new Array();
/*strResponseArray = response.split('|');
alert(strResponseArray[0]);
if(strResponseArray[2] != '')
	alert(strResponseArray[1]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("region_id")
	selectElement.options.length = 0;
	/*opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}
*/
var selectOpt = false;

	strResponseArray = response.split('|');
	alert(strResponseArray[0]);
	arrayOptions1	 = strResponseArray[1].split("_")
	arrayOptions2	 = strResponseArray[2].split("_")
	lengthArray1	=	arrayOptions1.length
	
	lengthArray2   = arrayOptions2.length
	selectElement	=	document.getElementById("region_id")
	selectElement.options.length = 0
	
	if(strResponseArray != '')
	{
	for(i=0;i<lengthArray2;i++)
	{
	selectOpt = false;
	optionTextValue = arrayOptions2[i].split("=")
	option1	=	document.createElement('option')
	for(k=0;k<arrayOptions1.length;k++)
		{
	   if(optionTextValue[0] == arrayOptions1[k])
		selectOpt = true;
		}
	option1.selected	=	selectOpt;
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];

	//option1.setAttribute('Value',"Ravu");
	selectElement.appendChild(option1,null);
	}
	}
}
function addcountry_()
{
	var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("country_id")
	selectElement.options.length = 0;
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}


}

function addcity_()
{
	var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("city_id")
	selectElement.options.length = 0;
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}


}

function addtriptype_()
{
	var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0]);
arrayOptions	 = strResponseArray[1].split("_")
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("trip_type")
	selectElement.options.length = 0;
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	selectElement.appendChild(option1,null);
	}

}


function getCountryList()
{
var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
document.getElementById("country_drop").innerHTML = strResponseArray[0];

}
function getCountryList1()
{
var response = http.responseText;
var strResponseArray = new Array();

strResponseArray = response.split('|');

arrayOptions	 = strResponseArray[0].split("_")
selectedOption	 = strResponseArray[1]
lengthArray		=	arrayOptions.length
selectElement	=	document.getElementById("country_id")
	selectElement.options.length = 0
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
if(strResponseArray != '')
	{
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	if(optionTextValue[0] == selectedOption)
		option1.selected = true;
	option1.value		=	optionTextValue[0];
	//option1.setAttribute('Value',"Ravu");
	selectElement.appendChild(option1,null);
	}
	}


}

function getCityList()
{
var response = http.responseText;

var strResponseArray = new Array();
strResponseArray = response.split('|');
document.getElementById("city_drop").innerHTML = strResponseArray[0];

}

function getCityList1()
{
var response = http.responseText;
var strResponseArray = new Array();
strResponseArray = response.split('|');
arrayOptions	 = strResponseArray[0].split("_")
	lengthArray		=	arrayOptions.length

selectElement	=	document.getElementById("city_id")
selectElement.options.length = 0
	opt1	=	document.createElement('option')
	opt1.innerHTML	=	"Select";
	opt1.value		=	"0";
	selectElement.appendChild(opt1,null);
	if(strResponseArray != '')
	{
for(i=0;i<lengthArray;i++)
	{
	optionTextValue = arrayOptions[i].split("=")
	option1	=	document.createElement('option')
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];
	//option1.setAttribute('Value',"Ravu");
	selectElement.appendChild(option1,null);
	}
	}


}

function regionDropDown(r_id)
{
	  http.open("get","getRegionList.php?trip_id="+r_id,true)
	  http.onreadystatechange = handleHttpgetItem9; 
	  http.send(null);	

}

function handleHttpgetItem9()
{
	if (http.readyState == NORMAL_STATE) {
	getRegionList();
}
}

function getRegionList()
{
	var response = http.responseText;
	var strResponseArray = new Array();
	var selectOpt = false;

	strResponseArray = response.split('|');
	arrayOptions1	 = strResponseArray[0].split("_")
	arrayOptions2	 = strResponseArray[1].split("_")
	lengthArray1	=	arrayOptions1.length
	
	lengthArray2   = arrayOptions2.length
	selectElement	=	document.getElementById("region_id")
	selectElement.options.length = 0
	
	if(strResponseArray != '')
	{
	for(i=0;i<lengthArray2;i++)
	{
	selectOpt = false;
	optionTextValue = arrayOptions2[i].split("=")
	option1	=	document.createElement('option')
	for(k=0;k<arrayOptions1.length;k++)
		{
	   if(optionTextValue[0] == arrayOptions1[k])
		selectOpt = true;
		}
	option1.selected	=	selectOpt;
	option1.innerHTML	=	optionTextValue[1];
	option1.value		=	optionTextValue[0];

	//option1.setAttribute('Value',"Ravu");
	selectElement.appendChild(option1,null);
	}
	}
}

function buildTopicList5() {

var strResponseArray = new Array();
strResponseArray = response.split('|');
alert(strResponseArray[0])
 
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}


function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = TrimString(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}


/*    For View Regions */
function showAdd()
{
 document.getElementById('ADD').style.display = "";
 document.getElementById('EDIT').style.display = "none";
}

function hideAdd()
{
	document.getElementById('ADD').style.display = "none";
}

function showEdit(reg_id,reg_name,image_id)
{
	if(image_id != 0)
	{
		showEditImage(image_id, 1,reg_name,reg_id)
	}
	else
	{
	document.getElementById('EDIT').style.display = "";
	document.getElementById("region_name_edit").value = reg_name
	document.getElementById("region_id_edit").value = reg_id
	document.getElementById('ADD').style.display = "none";
	document.getElementById("image_to_show").innerHTML = "<input type='file' name='imageedit' class='uploadIMG'>"
	}

}

function showCountryAdd()
{
	document.getElementById('ADD_COUNT').style.display = "";
	document.getElementById('EDIT').style.display = "none";


}
function showCountryEdit(count_id,count_name,image_id)
{
	if(image_id != '')
	{
		showEditImage(image_id, 2,count_name,count_id)
	}
	else
	{
	document.getElementById('EDIT').style.display = "";
	document.getElementById('ADD_COUNT').style.display = "none";

	document.getElementById("country_name_edit").value = count_name
	document.getElementById("count_id").value = count_id
	document.getElementById("image_to_show").innerHTML = "<input type='file' name='imageedit' class='uploadIMG'>"

	}
}
function showCityAdd()
{
	document.getElementById('ADD_CITY').style.display = "";
	document.getElementById('EDIT').style.display = "none";

}
function showCityEdit(city_id,city_name,image_id)
{
	if(image_id != '')
	{
		showEditImage(image_id, 3,city_name,city_id)
	}
	else
	{
	document.getElementById('EDIT').style.display = "";
	document.getElementById('ADD_CITY').style.display = "none";
	document.getElementById("city_name_edit").value = city_name
	document.getElementById("city_id").value = city_id
	document.getElementById("image_to_show").innerHTML = "<input type='file' name='imageedit' class='image'>"

	}
}

function hideEdit()
{
	document.getElementById('EDIT').style.display = "none";
}
function DeleteConfirmRegion()
{
	var message	=	confirm("WARNING !! All data i.e countries, cities and trips booked for this region will be removed permanently ! Are you sure u want to delete this region !");
	if(message)
	return true;
	else
	return false;
}
function DeleteConfirmTrip()
{
	var message	=	confirm("WARNING !! All data i.e booking of this trip will be removed permanently ! Are you sure u want to delete this region !");
	if(message)
	return true;
	else
	return false;
}
function DeleteConfirmCountry()
{	
	var message	=	confirm("WARNING !! All data i.e cities and trips booked for this country will be removed permanently ! Are you sure u want to delete this country !");
	if(message)
	return true;
	else
	return false;
}

function DeleteConfirmCity()
{	
	var message	=	confirm("WARNING !! All data i.e trips booked for this city will be removed permanently ! Are you sure u want to delete this city !");
	if(message)
	return true;
	else
	return false;
}



function ValidateForm(fname,option)
{
	if(fname == 'form1')
	{
		if(document.getElementById("form1").region_name.value == "")
		{
			alert("Please enter region name !");
			document.getElementById("form1").region_name.focus();
			return false;
		}
		if(!FileUploadValid(document.getElementById("form1").RegImage,"Please upload jpg/jgeg, gif or png file only."))
		{
			return false;
		}

	
	}
	else if(fname == 'form2')
	{
	
		if(document.getElementById("form2").country_name.value == "")
		{
			alert("Please enter country name !");
			document.getElementById("form2").country_name.focus();
			return false;
		}
		if(!FileUploadValid(document.getElementById("form2").country_image,"Please upload jpg/jgeg, gif or png file only."))
		{
			return false;
		}


	}

	else if(fname == "form3")
	{	
		countReg = 0;
		
		
		if(document.getElementById("form3").country_id.value == 0)
		{
			alert("Please select country !");
			document.getElementById("form3").country_id.focus();
			return false;
		}

		if(document.getElementById("form3").city_name.value == 0)
		{
			alert("Please enter your city name !");
			document.getElementById("form3").city_name.focus();
			return false;
		}
		if(!FileUploadValid(document.getElementById("form3").city_image,"Please upload jpg/jgeg, gif or png file only."))
		{
			return false;
		}
		for(i=0;i<document.getElementById("region_id").length;i++)
		{
			if(document.getElementById("region_id").selectedIndex >= 0 )
				countReg++;

		}
		if(countReg == 0)
		{
			alert("Please select atleast one region for city !");
			document.getElementById("region_id").focus();
			return false;
		}
		

	}
	else if(fname == "form4")
	{
		if(option == '1')
		{
		if(document.getElementById("form4").region_name_edit.value == 0)
		{
			alert("Please enter region name !");
			document.getElementById("form4").region_name_edit.focus();
			return false;
		}
		}
		else if(option =='2')
		{
		if(document.getElementById("form4").country_name_edit.value == 0)
		{
			alert("Please enter country name !");
			document.getElementById("form4").country_name_edit.focus();
			return false;
		}
		}
		else if(option == '3')
		{
			if(document.getElementById("form4").city_name_edit.value == 0)
		{
			alert("Please enter city name !");
			document.getElementById("form4").city_name_edit.focus();
			return false;
		}
		}
		if(!FileUploadValid(document.getElementById("form4").imageedit,"Please upload jpg/jgeg, gif or png file only."))
		{
			return false;
		}

		
	}
}
function confDel(msg)
{
	if (confirm(msg) === false) {
		return false;
	}
}
/*   End for regions */