/*
 * Copyright 2006 Servelots Infotech Pvt. Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at:
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
// This is to search in all categories
function searchAll(form){
  //var obj=document.browse;
	form.txTitle.value = form.keyword.value;
	if(form.searchOption.type=="select-one" || form.searchOption.type=="select-multiple")
		form.searchOption.options[obj.searchOption.selectedIndex].value ="02";
	else
		form.searchOption.value="02";
	if(siteSearch(form))
		form.submit();
}
function siteSearch(form){
        form.txTitle.value=form.keyword.value;

   	var aa=form.keyword.value;
        if(aa.length==0){
                alert("Enter the search word");
		return false;
        }
	form.pageno.value="1";
	return true;
}
function clearClick(form)
{
       form.keyword.value="";
       form.pageno.value="1";
       form.submit();
}

function keysub(id,value,form)
{
        ar=value.split("/");
        if(ar.length>0) {
                form.keywordid.value=ar[id];
                form.pageno.value="1";
                form.submit();
        }
}     
function assignValue(ch)
{
	document.browse.pagecat.value=ch;
}
function signin()
{
	document.browse.action='Index';
	document.browse.submit();
 
        if(document.browse.user.value=="")
        {
        	alert("plz enter username");
        }
        else
        {
        	if(document.browse.password.value=="")
                {
                	alert("plz enter password");
                }
                else
                {
                	document.browse.action='Index';
                	document.browse.submit();
                }
	}                                     
}
function setPreviousNext(val)
{
        document.form00.prenext.value=val;
        document.form00.submit();
}   
function changereq()
{
    var arr = new Array();
        if(document.form00.req.value=='100'){
								flag = true;
                document.form00.req.value ='102';
				}
        else{
						flag = true;
					  for(i=0;i<document.form00.elements.length;i++){
							  if(document.form00.elements[i].type=='text'){
									var regexp = /(^-?\d\d*$)/;
									if(regexp.test(document.form00.elements[i].name)){
                    arr.push(document.form00.elements[i].value);   
										if(!regexp.test(document.form00.elements[i].value)){
											flag=false;
										}
									}
								}
						}
                document.form00.req.value='101';
       }    
			 /* Checking for repeated values if it is define your own order.*/ 
       var flag1 = true;
       var flag2 = true;
       var len = arr.length;
       var j=0,k=0;
       for(j=0;j<len;j++){
				 // Checking for negative entries 	
         if(arr[j] < 0)
         flag2 = false;
       	for(k=1;k<len;k++){
        	if(j!=k){
          	if(arr[j] == arr[k]) {
            	flag1=false;
            }
          } 
        }
       }       
			
			if(flag==true){
      	if(flag1==true){
          if(flag2==true)
	      	 document.form00.submit();
          else
           alert("Order should not be negative");
        }  
        else
        	 alert("Order should be unique");
      }
			else
				alert("Please enter valid order.\nOrder should be numeric");
}  
/* If user checks or unchecks a pagelet in list of all pagelets
	 and if it is already present in the selected list of pagelets, 
   it should be checked or unchecked accordingly in selected list of 
   pagelets also. The same should happen when user checks or unchecks
	 a pagelet in selected list of pagelets, it should check or uncheck
	 from list of all pagelets, if it is present 

	 This function is used for the above mentioned purpose
*/
function checkUnchecked(chk,id){
	changeddl();
   for(i=0;i<document.form00.elements.length;i++){
      if(document.form00.elements[i].name==("CHK"+id)){
        if(!chk.checked)
          document.form00.elements[i].checked = false;
        else
          document.form00.elements[i].checked = true;
    }
  }
}
/*
	We have four options in the drop down list:
	'Most recent', 'Least recent', 'Alphabetical' and 'Define your own order'
	The first three options are applicable for all the pagelets in the
  category which we are editing. So when a user unchecks or checks a pagelet,
  the option is changed to 'Define your own order'

  This function is used for the above mentioned purpose 
 */ 
function changeddl(){
	if(document.form00.deforder){
  	for(i=0;i<document.form00.elements.length;i++){
      if(document.form00.elements[i].name.indexOf("CHK")!=-1){
        if(document.form00.elements[i].checked){
          document.form00.deforder.value = "own"
        }
      }
  	}
	}
}

function validate(val,form)
{
  form.cp.value=val;	
  form.action="SignIn";
  form.req.value="101";
  var var1 = form.userid.value;
  var var2 = form.password.value;
  var j =0;
  document.cookie = "name="+"77";
  var cook = document.cookie;
        if(cook.indexOf("77") == -1)
	  {
	    alert("Cookies Disabled Enable it manually");
	    j=1;
	  }
	
        if(j!=1)
	  if(((var1==null)||(var1==""))||((var2==null)||(var2=="")))
	    {
	      alert(" Either UserID or Password field Is Empty!");
	      form.userid.focus();
	    }
	  else
	    form.submit();
}
function goTo(selectOptionName)
{
  var idx =selectOptionName.selectedIndex;

  // If '--------' is selected, it displays the first option in the drop down list
  if(selectOptionName.options[idx].value=="#top")	
    selectOptionName.options[0].selected = true;
  location.href = selectOptionName.options[idx].value;
}

//This javascript functions are used for popup which displays category description in browse screen

function closePopup(){
if(typeof dPUW != "undefined")
	dPUW.close();
}
function set(count,desc){
  var categoryDesc = desc;
  var myWin = window.open("","Category Description","left=250,top=250,width=540,height=150,scrollbar=yes,resizable=yes");
  myWin.document.write(desc);
  //  document.browse.count.value = count;
  //popup();
}
function popup(){

// Set the address, width, height, top
// and left dimensions for the popup
// window below.

PopUpURL    = "../html/tooltip.html";
PopUpLeft   =  250;
PopUpTop    =  250;
PopUpWidth  =  540;
PopUpHeight =  150;

popO='left='+PopUpLeft+',top='+PopUpTop+',width='+PopUpWidth+',height='+PopUpHeight+',scrollbars,resizable="yes"';

dPUW=window.open(PopUpURL,'nrc',popO);
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////
