// JavaScript Document
	/*
	# eLuminous Technologies - Copyright (C)  http://eluminoustechnologies.com 
	# This code is written by eLuminous Technologies, Its a sole property of 
	# eLuminous Technologies and cant be used / modified without license.  
	# Any changes/ alterations, illegal uses, unlawful distribution, copying is strictly
	# prohibhited 
	# Name: Comman_function.js
	# Usage: included the file to use comman javascript funcation that required in all the pages. ( WRITE USAGE DETAILS ) 
	   -- comman funcation of javascript
	# Created : Rupal Pinge & Sham Shriwastav (30-05-2007)
	# Update  : 30-05-2007 Sham Shriwastav 
	# Status  : open
	# Purpose : make javascript code seprate from other coding
	*/

//  num_check(obj) 
//  this funcation is user to check the value enter in the textfield weather it is numeric or not

function num_check(obj)
		{
		 with(obj)
			   {
				   if(value!="")
					{
						if(isNaN(value)==true)
							{ 
								alert("Please fill in numeric value");
								value="";
								focus();
								return false;
							}
						else
							{
								 if(value<0)
								 {
									alert("Please fill value greater than zero.");
									value="";
									focus();
									return false;
								 }
							}
					}		
				}
		}

function num_check2(obj)
{

	with(obj)
	   {
		   if(value!="")
			{
				if(isNaN(value)==true)
					{ 
						alert("Please fill in numeric value.");
						value="";
						focus();
						return false;
					}
				else
					{
						 if(value>100 || value<0)
						 {
							alert("Please fill value greater than zero and less than or equal to hundred. ");
							value="";
							focus();
							return false;
						 }
					}
			}		
		}
}


// function popUpWindow()
// to open the url in the  popub box
	var popUpWin=0;
	function popUpWindow(URLStr, left, top, width, height)
		{
			  if(popUpWin)
				  {
					if(!popUpWin.closed) popUpWin.close();
				  }
			   if ( left=='')
				{
					left = (screen.width - width) / 2;
				}
			  
			  if ( top=='')
				  {
						top = (screen.height - height) / 2 ;
				  } 
			 popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
			 popUpWin.focus();
		}



// Removes Leading whitespaces
  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));
		}

// Check subject for 3 words
	function checkSubject(field)
	{
		str=field.value;
		if(str.length > 20 )
		{
			alert("Please fill in subject less than 20 characters.");
			field.style.border="1px solid #FF0000";
			field.focus();
			return false;
		}
		/*else
		{
			var arr1=str.split(" ");
			if(arr1[3])
			{
				alert("Please fill in subject upto 3 words.");
				field.style.border="1px solid #FF0000";
				field.focus();
			}	
		}*/	
		return true;
	}
	
function validate_email(str)
{ 

	var at="@" 
	var dot="." 
	var lat=str.indexOf(at) 
	var lstr=str.length 
	var ldot=str.indexOf(dot) 
	if (str.indexOf(at)==-1)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 
	
	if (str.indexOf(at,(lat+1))!=-1)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 
	
	if (str.indexOf(dot,(lat+2))==-1)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 

	if (str.indexOf(" ")!=-1)
	{ 
		//alert("Invalid E-mail ID") 
		return false 
	} 

	return true 
} 

//-- isnumeric
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
//-- isInteger
function IsItInteger(sText)
{
   var ValidChars = "0123456789";
   var IsItInteger=true;
   var Char;
 
   for (i = 0; i < sText.length && IsItInteger == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsItInteger = false;
         }
      }
   return IsItInteger;
   
   }   
   
   
   
   
   
   

//--function right
function Right(STRING,CHARACTER_COUNT)
{
 return STRING.substring((STRING.length - CHARACTER_COUNT),STRING.length);
}

   
function copy_clip(meintext)
{
	
 if (window.clipboardData) 
   {
   		//alert ("in clip");
	   // the IE-manier
	   window.clipboardData.setData("Text", meintext);
	   
	   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
	   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   		
	   // dit is belangrijk maar staat nergens duidelijk vermeld:
	   // you have to sign the code to enable this, or see notes below 
	   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	   
	   // maak een interface naar het clipboard
	   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
	                 .createInstance(Components.interfaces.nsIClipboard);
	   if (!clip) return;
	   
	   // maak een transferable
	   var trans = Components.classes['@mozilla.org/widget/transferable;1']
	                  .createInstance(Components.interfaces.nsITransferable);
	   if (!trans) return;
	   
	   // specificeer wat voor soort data we op willen halen; text in dit geval
	   trans.addDataFlavor('text/unicode');
	   
	   // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
	   // nodig om het in op te slaan
	   var str = new Object();
	   var len = new Object();
	   
	   var str = Components.classes["@mozilla.org/supports-string;1"]
	                .createInstance(Components.interfaces.nsISupportsString);
	   
	   var copytext=meintext;
	   
	   str.data=copytext;
   
	   trans.setTransferData("text/unicode",str,copytext.length*2);
	   
	   var clipid=Components.interfaces.nsIClipboard;
	   
	   if (!clip) return false;
	   
	   clip.setData(trans,null,clipid.kGlobalClipboard);
	   
   }
  // alert("Following info was copied to your clipboard:\n\n" + meintext);
   return false;
}  

// function used for searching type of browsers and according to dispaly hand on links
function change_cursor(obj)
 {	 
 	obj.style.cursor='pointer';
 }

function insertAtCaret(obj, text) 
{
	var NotInIEmode = true;

	if(document.selection) 
	{
		//for IE and Opera
		obj.focus();
		var orig = obj.value.replace(/\r\n/g, "\n");
		var range = document.selection.createRange();

		if(range.parentElement)
		 {
			NotInIEmode = true;

			if(range.parentElement() != obj) 
			{
				return false;
			}	
		}
		range.text = text;
		
		var actual = tmp = obj.value.replace(/\r\n/g, "\n");
	}
	else
	{
		//for Mozilla and netscape-- Gecko way 
		var start = obj.selectionStart;
		var end = obj.selectionEnd;

		obj.value = obj.value.substr(0, start)+ text+ obj.value.substr(end, obj.value.length);
		//alert ( obj.value);
	}	
	
	return true;
} 




function CompareDates(sdate_obj,edate_obj)
{
 
    var str1  = sdate_obj.value; //document.getElementById("sdate").value;
 
    var str2  = edate_obj.value //document.getElementById("edate").value;
 
    var dt1   = parseInt(str1.substring(8,10),10);
    
    var mon1  = parseInt(str1.substring(6,8),10);
 
    var yr1   = parseInt(str1.substring(0,5),10);
   
    var dt2   = parseInt(str2.substring(8,10),10);
 
    var mon2  = parseInt(str2.substring(6,8),10);
 
    var yr2   = parseInt(str2.substring(0,5),10);
 
    var start_date = new Date(yr1, mon1, dt1);
 
    var end_date = new Date(yr2, mon2, dt2);
 
    if(start_date >= end_date)
    {
		alert (sdate_obj.title);
		sdate_obj.style.border="1px solid #FF0000";
		return false; 
    } 
 
	 return true;   
   
 } 
 
 
 /*function checkUrl(theUrl)
{
	if(theUrl.match(/^(http)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i))
		{
		   //alert("valid address.");
			return true;
		} 
	 else 
		{
			return false;
		}
}*/


// Function to check start date > curr date
function CompareContestDates(str1,str2)
{
    var dt1   = parseInt(str1.substring(8,10),10);
    
    var mon1  = parseInt(str1.substring(6,8),10);
 
    var yr1   = parseInt(str1.substring(0,5),10);
   
    var dt2   = parseInt(str2.substring(8,10),10);
 
    var mon2  = parseInt(str2.substring(6,8),10);
 
    var yr2   = parseInt(str2.substring(0,5),10);
 
    var start_date = new Date(yr1, mon1, dt1);
 
    var end_date = new Date(yr2, mon2, dt2);
    if(start_date < end_date)
    {
		alert("Please fill in valid date.");
		return false; 
    } 
	 return true;   
 } 
 
 
// Dispall date & time
function get_date_time()
{
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000) year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10) daym="0"+daym
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
	document.write("<font style='font-size: 14px;' color='000000' size=2 face='Tahoma, sans-serif'>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></font>&nbsp;&nbsp;")
}


// Copy to Clip bord

	function copy_clip(meintext)
	{
	   if (window.clipboardData) 
	   {
		window.clipboardData.setData("Text", meintext);
	   }
	   else if (window.netscape) 
	   { 
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			var clip = Components.classes['@mozilla.org/widget/clipboard;1']
					  .createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;
		
			var trans = Components.classes['@mozilla.org/widget/transferable;1']
					   .createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;
		
			trans.addDataFlavor('text/unicode');
		
			var str = new Object();
			var len = new Object();
			
			var str = Components.classes["@mozilla.org/supports-string;1"]
						 .createInstance(Components.interfaces.nsISupportsString);
			
			var copytext=meintext;
		
			str.data=copytext;
		   
			trans.setTransferData("text/unicode",str,copytext.length*2);
			
			var clipid=Components.interfaces.nsIClipboard;
			
			if (!clip) return false;
			
			clip.setData(trans,null,clipid.kGlobalClipboard);
	   	}
		else
	 	{
			//for opera
		   //alert ("inside");
		   //Copied = meintext.createTextRange();
		   //Copied.execCommand("Copy");
		}
	   //alert("Following info was copied to your clipboard:\n\n" + meintext);
	   return false;
	}  
	
	
function ClipBoard(obj) 
	{
			//alert(obj);
			obj.focus();
			obj.select();
			var text_to_copy = obj.value;
			copy_clip(text_to_copy);
	}

//Function to check phone no
function checkPhone(field)
{
	var ph=field.value;
	var ch=/^([\(]?\s?\d+\s?[\)]?\s?[-]?\s?)+$/;
	if(!ch.test(ph))
	{
		alert ("Please fill in valid phone number.");
		field.value="";
		field.focus();
		field.style.border="1px solid #FF0000";
		return false
	}
	else
	 	return true;	
}

//Function to check postal code
function checkZip(field)
{
	var zip=field.value;
	var ch=/^([a-zA-Z0-9]+)$/;
	if(zip.length < 3 || zip.length > 10 || !ch.test(zip))
	{
		alert ("Please fill in valid zip code.");
		field.value="";
		field.focus();
		field.style.border="1px solid #FF0000";
		return false
	}
	else
	 	return true;	
}

// Dispaly the word counter for the textb0x
function word_counter(obj_text,obj_show,maxval)
{
        var strMsg = document.getElementById(obj_text).value;
		var strMsgLen = strMsg.length
        if(maxval=='')
			{ maxval=strMsgLen;	}
		
		var strMsgMax = strMsg.substring(0, maxval);
       		
        if(strMsgLen<=maxval)
            document.getElementById(obj_show).innerHTML = (maxval - strMsgLen).toString();
        else
        {
            document.getElementById(obj_text).value = strMsgMax;
            event.returnValue = false;
        }
}

/// check the space in the field

function chk_space(field)
{
	str=field.value;
    val_len=field.value.length;
	for(i=0;i<val_len;i++)
	{
		 if(str.charCodeAt(i)==32)
			 {
				alert("Invalid character in username");
				field.value=trim(str);
				return false;
			 }	
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function CheckCookiesEnabled()
{
	setCookie('test','none',1);
	if (getCookie('test')=="")
	{
		 return "redirect";
			current_url=document.URL;
			my_domain=document.domain;
			alert(my_domain);
			on_index=current_url.search("index.html");
			if(on_index<0)
			 on_index=current_url.search("index.php");
			
			if(on_index<0)
			{	
			alert("Cookies are currently disabled in your browser.\n It must be enable.");
			document.location=my_domain;				 	
			}
			else
			{
			alert("Cookies are currently disabled in your browser.\n It must be enable.");
			}
		
	}
// return "no_need";
}


function expand_collapse(event_obj,dest_id)
{
	
	 if (document.getElementById(dest_id).style.display=="") //collapse the collapse  destionation div
	 {
		 document.getElementById(dest_id).style.display="none";
	 }
	else
	 {
		 document.getElementById(dest_id).style.display="";
	 }
	 //return false;
}


function dollerToPoint(amount, point_val)
{
 points=(amount/point_val);
 return points;
}


function expand_collapse2(event_obj,dest_id,img_name)
{
	
	 if (document.getElementById(dest_id).style.display=="") //collapse the collapse  destionation div
	 {
		 document.getElementById(dest_id).style.display="none";
		 document.images[img_name].src="images/btn_expand.gif";
	 }
	else
	 {
		 document.getElementById(dest_id).style.display="";
		 document.images[img_name].src="images/btn_collapse.gif";
	 }
	 //return false;
}