//New Functions
function mm_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=mm_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function mm_swapImgRestore() { //v3.0
  var i,x,a=document.mm_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function mm_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.mm_p) d.mm_p=new Array();
    var i,j=d.mm_p.length,a=mm_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.mm_p[j]=new Image; d.mm_p[j++].src=a[i];}}
}

function mm_swapImage() { //v3.0
  var i,j=0,x,a=mm_swapImage.arguments; document.mm_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=mm_findObj(a[i]))!=null){document.mm_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// JavaScript Document
function checkpass(wp,wrp,mm)
{
	var bool=true;
	if(wp.value.length!=wrp.value.length)
	{
		bool=false;
		
	}
	else 
	{
			if(wp.value==wrp.value)
			{
				bool=true;
			}
			else
			{
				bool=false;
			}	
	}
	if(!bool)
	{
		alert(mm);
		wrp.focus();
	}
	return bool;
}
function isvalidmoney(qq,aa)
{
var valid=true;
var allstring="0123456789.";
var tvalue=qq.value
var singlechracter;
for(i=0;i<tvalue.length;i++)
{
	singlecharacter=tvalue.charAt(i);
	for(j=0;j<allstring.length;j++)
	{
		if(singlecharacter==allstring.charAt(j))
		{
			break;
		}	
	}
	if(j==allstring.length)
	{
		valid=false;
		
		break;
	}
} 
if(!valid)
	{
	alert(aa)
	qq.focus();
	}
return valid;
}
function isvalidnumber(qq,aa)
{
var valid=true;
var allstring="0123456789";
var tvalue=qq.value
var singlechracter;
for(i=0;i<tvalue.length;i++)
{
	singlecharacter=tvalue.charAt(i);
	for(j=0;j<allstring.length;j++)
	{
		if(singlecharacter==allstring.charAt(j))
		{
			break;
		}	
	}
	if(j==allstring.length)
	{
		valid=false;
		
		break;
	}
} 
if(!valid)
	{
	alert(aa)
	qq.focus();
	}
return valid;
}
function customnumber(qq,aa)
{
var valid=true;
var allstring="0123456789-";
var tvalue=qq.value
var singlechracter;
for(i=0;i<tvalue.length;i++)
{
	singlecharacter=tvalue.charAt(i);
	for(j=0;j<allstring.length;j++)
	{
		if(singlecharacter==allstring.charAt(j))
		{
			break;
		}	
	}
	if(j==allstring.length)
	{
		valid=false;
		
		break;
	}
} 
if(!valid)
	{
	alert(aa)
	qq.focus();
	}
return valid;
}
function validadd(ee,mm)
{
var bool=true;
	if(ee.value!="")
	{
		emailadd=ee.value;
		iattherate=emailadd.indexOf("@");
		if(iattherate>0)
		{
			aa=emailadd.indexOf(".",iattherate);
			if((aa>iattherate+1)&&(emailadd.length>aa+1))
			{
				bool=true;
			}
			else
			{
				
				alert(mm);
				ee.focus();
				bool=false;
			}	
		}
		else
		{
			alert(mm);
			ee.focus();	
			bool=false;
		}
	}
	return bool;
}

function blank(textf,msg)
{
var bool=true;
	if(textf.value=="")
	{
		alert(msg)
		textf.focus()
		bool=false;
	}
	return bool;
}
function checkpass(wp,wrp,mm)
{
	var bool=true;
	if(wp.value.length!=wrp.value.length)
	{
		bool=false;
		
	}
	else 
	{
			if(wp.value==wrp.value)
			{
				bool=true;
			}
			else
			{
				bool=false;
			}	
	}
	if(!bool)
	{
		alert(mm);
		wrp.focus();
	}
	return bool;
}


function get_object(id)
{
	var obj = document.getElementById(id);
	return obj;
}
//selects or deselects all checkboxes in document if rooot checkbox is selected or deselected
function select_deselect_all(form_obj,root_check_box_name)
{
var mainobj = document.getElementById(root_check_box_name);
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			if(mainobj.checked)
			{
				form_obj.elements[i].checked = true;
			}
			else
			{
				form_obj.elements[i].checked = false;
			} 
		}
	}
}
//selects  root checkboxes if all checkboxes gets selected or deselect root checkboxes if any of the checkboxes in document deselected
function check_selection(form_obj,root_check_box_name)
{
var mainobj = document.getElementById(root_check_box_name);
var temp_counter;
temp_counter = 0
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			temp_counter = temp_counter + 1;
		}
	}
//I did this because even if there is other form item it should work
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			if(form_obj.elements[i].checked)
			{
				temp_counter = temp_counter - 1;
			}
		}
	}
	if(temp_counter == 0)
	{
		mainobj.checked = true;
	}
	else
	{
		mainobj.checked = false;
	}
}
function checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MM_returnValue = true;
  if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/\s/gi,"") + ")$","i");
    if (field.value == '')
	 {
      if (requireUpload) {alert('Enter File Name!');document.MM_returnValue = false;field.focus();return;}
    }
	 else
	  {
     	 if(extensions != '' && !re.test(field.value))
			  {
    	    alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
        	document.MM_returnValue = false;field.focus();return;
     		}
			    document.PU_uploadForm = field.form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } }

 

}

function showImageDimensions(fieldImg) { //v2.09
  var isNS6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !isNS6 ? fieldImg : this);
  if (img.width > 0 && img.height > 0) {
  if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
    alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
  if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
    alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
  if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
    alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
  if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
  if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
  document.MM_returnValue = true;
} }

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.09
  if (!document.layers) {
    var isNS6 = (!document.all && document.getElementById ? true : false);
    document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
    if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
		   with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
  	   gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
	 } else showImageDimensions(field.gp_img);}
}
function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.09
  document.MM_returnValue = true;

  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    checkOneFileUpload(field,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);

}
}
function open_window(url,width,height)
{
	var winfeatures = "status=no,scrollbars=yes,left=150,top=100,menubar=no,resizable=yes,titlebar=no,toolbar=no,addressbar=no,width=" +width + ",height=" + height
	window.open(url,"newwindow",winfeatures);
}
function oopen_window(url,width,height)
{
	var winfeatures = "status=no,scrollbars=yes,left=150,top=100,menubar=no,resizable=no,titlebar=no,toolbar=no,addressbar=no,width=" +width + ",height=" + height
	window.open(url,"newwindowone",winfeatures);
}
function make_selection(id)
{
	var selection_obj = document.getElementById(id)
	if(selection_obj.selectedIndex == 0)
	{
		for(i=1;i<selection_obj.options.length;i++)
		{
			selection_obj.options[i].selected = false;
		}
		selection_obj.options[0].selected = true;
	}
	else if(selection_obj.selectedIndex != 0)
	{
		selection_obj.options[0].selected = false;
	}
	return true;
}
function isradiochecked(form_obj,msg)
{
var bool =false;
	for(var i =0;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "radio")
		{
			
			if(form_obj.elements[i].checked)
			{
				bool = true;
				break;
			}
		}
	}
	if(!bool)alert(msg);
return bool;
}
function make_selection(id)
{
	var selection_obj = document.getElementById(id)
	if(selection_obj.selectedIndex == 0)
	{
		for(i=1;i<selection_obj.options.length;i++)
		{
			selection_obj.options[i].selected = false;
		}
		selection_obj.options[0].selected = true;
	}
	else if(selection_obj.selectedIndex != 0)
	{
		selection_obj.options[0].selected = false;
	}
	return true;
}
function select_deselect_all(form_obj,root_check_box_name)
{
var mainobj = document.getElementById(root_check_box_name);
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			if(mainobj.checked)
			{
				form_obj.elements[i].checked = true;
			}
			else
			{
				form_obj.elements[i].checked = false;
			} 
		}
	}
}
function check_selection(form_obj,root_check_box_name)
{
var mainobj = document.getElementById(root_check_box_name);
var temp_counter;
temp_counter = 0
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			temp_counter = temp_counter + 1;
		}
	}
	for(var i =1;i<form_obj.elements.length;i++)
	{
		if(form_obj.elements[i].type == "checkbox")
		{
			if(form_obj.elements[i].checked)
			{
				temp_counter = temp_counter - 1;
			}
		}
	}
	if(temp_counter == 0)
	{
		mainobj.checked = true;
	}
	else
	{
		mainobj.checked = false;
	}
}