function Alerts(PopupMsg, RedirectIndicator, URL)
{
	var strMsg = PopupMsg
	if (strMsg != "") {
		alert(PopupMsg)
	}
	
	if (RedirectIndicator=='True') {
		location.replace(URL)
	}
}

function isEmail(str) {
  
  var supported = 0;
  if (str==""){
  return true;
  }
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// 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 IsValid(documentelement,actiontype){
	var theExpression;
	var mystring;
	
	mystring = documentelement;
	if (actiontype =="1")
	{
		theExpression=/^[0-9a-zA-Z]+$/;
	}
	
	if (actiontype =="2")
	{
		theExpression=/^[0-9]+$/;
	}
	
	if (actiontype =="3")
	{
		theExpression=/^[a-zA-Z]+$/;
	}
	
	if (actiontype =="4")
	{
		theExpression=/^[a-z A-Z-]+$/;
	}

	if (actiontype =="5")
	{
		theExpression=/^[\r\n,0-9a-z A-Z()@#-]+$/;
	}

	if(mystring.match(theExpression))
	{
		return true;
	}else{
		return false;
	}	
}

function IsValidTime(timeStr) {
// Checks if time is in HH:MM format.

	var timePat = /^(\d{1,2}):(\d{2})+$/;
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		alert("Time is not in a valid format.\n Example 12:00");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	
	
	if (hour < 1  || hour > 12) {
		alert("Hour must be between 1 and 12");
		return false;
	}
	
	if (minute<0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	
	return true;
}

function textLimit(field, maxlen) {
	if (field.value.length > maxlen + 1)
	alert('Your input has been truncated! Maximum lenght allowed is 100 characters');
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
	field.focus();
}

function isEmpty(inputfield, type) {
//check if inputfield is blank
	if (type == 0){	 
    		if (inputfield == "" || inputfield == null || !isNaN(inputfield) || inputfield.charAt(0) == ' '){
	    		return true;
    		}
	}
	if (type==1){	
    			if (inputfield == "" || inputfield == null || inputfield.charAt(0) == ' '){
				return true;
    			}
	}
	return false;
}


var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////


function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(ModeType){
	crossobj=ns6? document.getElementById("showimage") : document.all.showimage

	if 	(ModeType==1)
	{			
			if (ie4||ns6)
			crossobj.style.visibility="hidden"
			else if (ns4)
			document.showimage.visibility="hide"
	}else {

			if (ie4||ns6)
			crossobj.style.visibility="visible"
			else if (ns4)
			document.showimage.visibility="visible"
	}
}

function toggleSound(){
	//This function toggles between showing image
	var ImageName;
	nextimage = new Image;
	
	ImageName = parent.document.getElementById("soundspeaker").src
	if(ImageName.indexOf('Pics/musicon.gif') > 0){
		nextimage.src= 'Pics/musicoff.gif'
		if (document.activeElement){ //IE Browser
	  	document.getElementById("soundspeaker").src = nextimage.src;
		document.getElementById("soundbox").value = 'Music off'
		document.getElementById("MediaPlayer").Mute = true;
		}else{	//Not a IE Browser
	  	document.getElementById("soundspeaker").src = nextimage.src;
		document.getElementById("soundbox").value = 'Music off'
		document.MediaPlayer.Mute = true;
		}		
	}else{
		nextimage.src= 'Pics/musicon.gif'
	  	document.getElementById("soundspeaker").src = nextimage.src ;
		document.getElementById("soundbox").value = 'Music on'
		document.getElementById("MediaPlayer").Mute = false;
	}
}

