/*
Filename:general.js
Owner:Vinu Mathews
Creation Date:10-10-2008

PROCEDURES IN FILE
NAME				AUTHOR				CREATION DATE               

MODIFICATION HISTORY
NAME			AUTHOR			MODIFICATION DATE		Details							APPROVER

PROCEDURE/ FUNCTION DESCRIPTIONS
procedure name:
    TABLES:Describe the tables used in this. 
	COMPONENTS:  Description of components used in the function.
    PARAMETERS: Description of parameters passed and its description
    EXTERNAL IMPACT: Description whether changes can affect other procedures
*/


/****	 to show/hide a div		****/

function showHideDiv(showsource,hidesource){
		if(document.getElementById(""+showsource+"").style.display=='none')
		{
			document.getElementById(""+showsource+"").style.display="inline";
			document.getElementById(""+hidesource+"").style.display="none";
			return;
		}
		else
		{
			document.getElementById(""+hidesource+"").style.display="none";
			return;
		}
}
function showHide_Divs(div1,div1value,div2,div2value){
	
	alert("DSDF");
	
		if(div1value==1){
			if(document.getElementById(""+div1+"").style.display=='none')
			{
				document.getElementById(""+div1+"").style.display="inline";
			}
		}
		if(div2value==1){
			if(document.getElementById(""+div2+"").style.display=='none')
			{
				document.getElementById(""+div2+"").style.display="inline";
			}		
		}
}

function emailcheck(email)

{

// a very simple email validation checking. 

// you can add more complex email checking if it helps 

    if(email.length <= 0)

	{

	  return true;

	}

    var splitted = email.match("^(.+)@(.+)$");

    if(splitted == null) return false;

    if(splitted[1] != null )

    {

      var regexp_user=/^\"?[\w-_\.]*\"?$/;

      if(splitted[1].match(regexp_user) == null) return false;

    }

    if(splitted[2] != null)

    {

      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;

      if(splitted[2].match(regexp_domain) == null) 

      {

	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

	    if(splitted[2].match(regexp_ip) == null) return false;

      }// if

      return true;

    }

return false;

}
function trimf(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrimf(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrimf(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function count_Dot(sText)
{
	
   var dotcount = 0; 

  for (i = 0; i < sText.length; i++) 
   { 
      if (sText.charAt(i) == ".") 
      {
         dotcount++;
      }
   }
   return dotcount;
}

function tagcheck(objValue,strError)

         { 
		 	str_Error = false;
		 	strfind	  =	objValue.value.search(/</);
		 
		 	if(strfind<0) {
				
				if((objValue.value.search(/>/))<0) {
					str_Error = false;
				}
				else {
					
					str_Error = true;
				}
				
			}
			else {
				str_Error = true;
			}
		  	 if(str_Error ==true) 

              { 

                 
				alert(strError);
				return false; 

              }//if            

          

         }//case tag_check 
function scriptcheck(objValue,strError)

         { 
		 	str_Error = false;
		 	strfind	  =	objValue.value.search(/<script/i);
		 	if(strfind<0) {
				
				if((objValue.value.search(/script>/i))<0) {
					str_Error = false;
				}
				else {
					
					str_Error = true;
				}
				
			}
			else {
				str_Error = true;
			}
		  	 if(str_Error ==true) 

              { 

                 
				alert(strError);
				return false; 

              }//if            
          

         }//case tag_check 

 function imageext(objValue)
          { 
				if(objValue.value.length>0) 
            	{ 				
					var exts = "jpg|gif|png|bmp|mpg|mpeg|jpeg|pjpeg|pjpg";
					
					var re = new RegExp("^.+\.("+exts+")$","i");
					if(!re.test(objValue.value))
					{	
						alert("Extension not allowed for file: \"" + objValue.value + "\"\nOnly these extensions are allowed: "+exts.replace(/\|/g,',')+" \n\n");
						return false; 
					}
				}
          

          }//case imgext 
		  
function numeric(objValue,strError)

{

  var charpos = objValue.value.search("[^0-9\.]"); 

  if(objValue.value.length > 0 &&  charpos >= 0) 

  { 

	  if(!strError || strError.length ==0) 

	{ 

	  strError = objValue.name+": characters allowed are 0-9 and ."; 

	}//if                             

	alert(strError ); 

	return false; 

  }//if 			


}
function clear_text(Obj,Val_compare,newval){//alert("sds");
	if(Val_compare!=''){
		if(Obj.value==Val_compare){
			Obj.value=newval;
			return true;
		}
	}else{
		Obj.value=newval;
		return true;
	}
}
function clearText_DiableField(ObjCmp,Objdis1,Objdis2,text){
	
	
	if(ObjCmp.value!=''){
		
		
		if(Objdis1!=''){
			Objdis1.disabled=true;
			Objdis1.selectedIndex=0;
		}
		if(Objdis2!=''){
			Objdis2.disabled=true;
			Objdis2.value=text;
		}
	}
	else if(ObjCmp.value==''){
		if(Objdis1!=''){
			Objdis1.disabled=false;
			Objdis1.selectedIndex=0;
		}
		if(Objdis2!=''){
			Objdis2.disabled=false;
			Objdis2.value=text;
		}
	}
	
}

function selectResults(Objdis1,Objdis2,pgsize,curr){
	if(Objdis1.selectedIndex==0){
		//Objdis2.disabled=false;
		Objdis1.style.background="#FFFFFF";
		Objdis2.style.background="#FFFFFF";
		Objdis2.selectedIndex=0;
	}
	if(Objdis1.selectedIndex==1){
		//Objdis2.disabled=true;
		Objdis1.style.background="#FFFFFF";
		Objdis2.style.background="#CCCCCC";
		Objdis2.selectedIndex=1;
	}else if(Objdis1.selectedIndex==2){
		//Objdis2.disabled=true;
		Objdis1.style.background="#FFFFFF";
		Objdis2.style.background="#CCCCCC";
		Objdis2.selectedIndex=3;
	}else if(Objdis1.selectedIndex==3){
		//Objdis2.disabled=true;
		Objdis1.style.background="#FFFFFF";
		Objdis2.style.background="#CCCCCC";
		Objdis2.selectedIndex=2;
	}
	for(i=0;i<=pgsize;i++){
		if(document.getElementById("txt_winner_"+curr+"").selectedIndex!=""){
			if(i!=curr){
				document.getElementById("txt_winner_"+i+"").style.background="#CCCCCC";
				document.getElementById("txt_winner_"+i+"").disabled=true;	
				document.getElementById("txt_loser_"+i+"").style.background="#CCCCCC";
				document.getElementById("txt_loser_"+i+"").disabled=true;	
			}
		}
		else{
			if(i!=curr){
				document.getElementById("txt_winner_"+i+"").disabled=false;	
				document.getElementById("txt_winner_"+i+"").style.background="#FFFFFF";
				document.getElementById("txt_loser_"+i+"").disabled=false;	
				document.getElementById("txt_loser_"+i+"").style.background="#FFFFFF";
			}
		}
	}
}


